+export class AppComponent implements OnInit, AfterViewInit {
+ private static BROADCAST_MESSAGE_KEY = 'app-broadcast-message-dismissed'
+
+ @ViewChild('accountSetupWarningModal') accountSetupWarningModal: AccountSetupWarningModalComponent
+ @ViewChild('adminWelcomeModal') adminWelcomeModal: AdminWelcomeModalComponent
+ @ViewChild('instanceConfigWarningModal') instanceConfigWarningModal: InstanceConfigWarningModalComponent
+ @ViewChild('customModal') customModal: CustomModalComponent
+
+ customCSS: SafeHtml
+ broadcastMessage: { message: string, dismissable: boolean, class: string } | null = null
+
+ private serverConfig: HTMLServerConfig
+
+ constructor (
+ @Inject(DOCUMENT) private document: Document,
+ @Inject(LOCALE_ID) private localeId: string,
+ private router: Router,
+ private authService: AuthService,
+ private serverService: ServerService,
+ private peertubeRouter: PeerTubeRouterService,
+ private pluginService: PluginService,
+ private instanceService: InstanceService,
+ private domSanitizer: DomSanitizer,
+ private redirectService: RedirectService,
+ private screenService: ScreenService,
+ private hotkeysService: HotkeysService,
+ private themeService: ThemeService,
+ private hooks: HooksService,
+ private location: PlatformLocation,
+ private modalService: NgbModal,
+ private markdownService: MarkdownService,
+ private ngbConfig: NgbConfig,
+ private loadingBar: LoadingBarService,
+ private scrollService: ScrollService,
+ public menu: MenuService
+ ) {
+ this.ngbConfig.animation = false
+ }
+
+ get instanceName () {
+ return this.serverConfig.instance.name
+ }
+
+ goToDefaultRoute () {
+ return this.router.navigateByUrl(this.redirectService.getDefaultRoute())
+ }
+
+ ngOnInit () {
+ document.getElementById('incompatible-browser').className += ' browser-ok'
+
+ this.serverConfig = this.serverService.getHTMLConfig()
+
+ this.hooks.runAction('action:application.init', 'common')
+ this.themeService.initialize()
+
+ this.authService.loadClientCredentials()
+
+ if (this.isUserLoggedIn()) {
+ // The service will automatically redirect to the login page if the token is not valid anymore
+ this.authService.refreshUserInformation()
+ }
+
+ this.initRouteEvents()
+ this.scrollService.enableScrollRestoration()
+
+ this.injectJS()
+ this.injectCSS()
+ this.injectBroadcastMessage()
+
+ this.serverService.configReloaded
+ .subscribe(config => {
+ this.serverConfig = config
+
+ this.injectBroadcastMessage()
+ this.injectCSS()
+
+ // Don't reinject JS since it could conflict with existing one
+ })
+
+ this.initHotkeys()
+
+ this.location.onPopState(() => this.modalService.dismissAll(POP_STATE_MODAL_DISMISS))
+
+ this.openModalsIfNeeded()
+
+ this.document.documentElement.lang = getShortLocale(this.localeId)
+ this.document.documentElement.dir = getLocaleDirection(this.localeId)
+ }
+
+ ngAfterViewInit () {
+ this.pluginService.initializeCustomModal(this.customModal)
+ }
+
+ getToggleTitle () {
+ if (this.menu.isDisplayed()) return $localize`Close the left menu`
+
+ return $localize`Open the left menu`
+ }
+
+ isUserLoggedIn () {
+ return this.authService.isLoggedIn()
+ }
+
+ hideBroadcastMessage () {
+ peertubeLocalStorage.setItem(AppComponent.BROADCAST_MESSAGE_KEY, this.serverConfig.broadcastMessage.message)