135 lines
4.4 KiB
TypeScript
135 lines
4.4 KiB
TypeScript
/* eslint-disable @angular-eslint/component-class-suffix */
|
|
import {
|
|
Component,
|
|
OnInit,
|
|
inject,
|
|
HostListener
|
|
} from '@angular/core';
|
|
import {
|
|
Router,
|
|
RouterOutlet,
|
|
NavigationEnd
|
|
} from '@angular/router';
|
|
import { CommonModule } from '@angular/common';
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import { DatabaseService } from './core/services/database.service';
|
|
import { DesktopAppUpdateService } from './core/services/desktop-app-update.service';
|
|
import { ServerDirectoryService } from './core/services/server-directory.service';
|
|
import { TimeSyncService } from './core/services/time-sync.service';
|
|
import { VoiceSessionService } from './core/services/voice-session.service';
|
|
import { ExternalLinkService } from './core/services/external-link.service';
|
|
import { SettingsModalService } from './core/services/settings-modal.service';
|
|
import { ServersRailComponent } from './features/servers/servers-rail.component';
|
|
import { TitleBarComponent } from './features/shell/title-bar.component';
|
|
import { FloatingVoiceControlsComponent } from './features/voice/floating-voice-controls/floating-voice-controls.component';
|
|
import { SettingsModalComponent } from './features/settings/settings-modal/settings-modal.component';
|
|
import { DebugConsoleComponent } from './shared/components/debug-console/debug-console.component';
|
|
import { ScreenShareSourcePickerComponent } from './shared/components/screen-share-source-picker/screen-share-source-picker.component';
|
|
import { UsersActions } from './store/users/users.actions';
|
|
import { RoomsActions } from './store/rooms/rooms.actions';
|
|
import { selectCurrentRoom } from './store/rooms/rooms.selectors';
|
|
import {
|
|
ROOM_URL_PATTERN,
|
|
STORAGE_KEY_CURRENT_USER_ID,
|
|
STORAGE_KEY_LAST_VISITED_ROUTE
|
|
} from './core/constants';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
imports: [
|
|
CommonModule,
|
|
RouterOutlet,
|
|
ServersRailComponent,
|
|
TitleBarComponent,
|
|
FloatingVoiceControlsComponent,
|
|
SettingsModalComponent,
|
|
DebugConsoleComponent,
|
|
ScreenShareSourcePickerComponent
|
|
],
|
|
templateUrl: './app.html',
|
|
styleUrl: './app.scss'
|
|
})
|
|
export class App implements OnInit {
|
|
store = inject(Store);
|
|
currentRoom = this.store.selectSignal(selectCurrentRoom);
|
|
desktopUpdates = inject(DesktopAppUpdateService);
|
|
desktopUpdateState = this.desktopUpdates.state;
|
|
|
|
private databaseService = inject(DatabaseService);
|
|
private router = inject(Router);
|
|
private servers = inject(ServerDirectoryService);
|
|
private settingsModal = inject(SettingsModalService);
|
|
private timeSync = inject(TimeSyncService);
|
|
private voiceSession = inject(VoiceSessionService);
|
|
private externalLinks = inject(ExternalLinkService);
|
|
|
|
@HostListener('document:click', ['$event'])
|
|
onGlobalLinkClick(evt: MouseEvent): void {
|
|
this.externalLinks.handleClick(evt);
|
|
}
|
|
|
|
async ngOnInit(): Promise<void> {
|
|
void this.desktopUpdates.initialize();
|
|
|
|
await this.databaseService.initialize();
|
|
|
|
try {
|
|
const apiBase = this.servers.getApiBaseUrl();
|
|
|
|
await this.timeSync.syncWithEndpoint(apiBase);
|
|
} catch {}
|
|
|
|
this.store.dispatch(UsersActions.loadCurrentUser());
|
|
|
|
this.store.dispatch(RoomsActions.loadRooms());
|
|
|
|
const currentUserId = localStorage.getItem(STORAGE_KEY_CURRENT_USER_ID);
|
|
|
|
if (!currentUserId) {
|
|
if (this.router.url !== '/login' && this.router.url !== '/register') {
|
|
this.router.navigate(['/login']).catch(() => {});
|
|
}
|
|
} else {
|
|
const last = localStorage.getItem(STORAGE_KEY_LAST_VISITED_ROUTE);
|
|
|
|
if (last && typeof last === 'string') {
|
|
const current = this.router.url;
|
|
|
|
if (current === '/' || current === '/search') {
|
|
this.router.navigate([last], { replaceUrl: true }).catch(() => {});
|
|
}
|
|
}
|
|
}
|
|
|
|
this.router.events.subscribe((evt) => {
|
|
if (evt instanceof NavigationEnd) {
|
|
const url = evt.urlAfterRedirects || evt.url;
|
|
|
|
localStorage.setItem(STORAGE_KEY_LAST_VISITED_ROUTE, url);
|
|
|
|
const roomMatch = url.match(ROOM_URL_PATTERN);
|
|
const currentRoomId = roomMatch ? roomMatch[1] : null;
|
|
|
|
this.voiceSession.checkCurrentRoute(currentRoomId);
|
|
}
|
|
});
|
|
}
|
|
|
|
openNetworkSettings(): void {
|
|
this.settingsModal.open('network');
|
|
}
|
|
|
|
openUpdatesSettings(): void {
|
|
this.settingsModal.open('updates');
|
|
}
|
|
|
|
async refreshDesktopUpdateContext(): Promise<void> {
|
|
await this.desktopUpdates.refreshServerContext();
|
|
}
|
|
|
|
async restartToApplyUpdate(): Promise<void> {
|
|
await this.desktopUpdates.restartToApplyUpdate();
|
|
}
|
|
}
|