+ 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)
+ }
+
+ // ---------------------------------------------------------------------------
+
+ getDefaultRoute () {
+ return this.redirectService.getDefaultRoute().split('?')[0]
+ }
+
+ getDefaultRouteQuery () {
+ return this.router.parseUrl(this.redirectService.getDefaultRoute()).queryParams
+ }
+
+ // ---------------------------------------------------------------------------
+
+ 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)
+
+ this.broadcastMessage = null
+ this.screenService.isBroadcastMessageDisplayed = false
+ }
+
+ getNotificationIcon (message: { severity: 'success' | 'error' | 'info' }): GlobalIconName {
+ switch (message.severity) {
+ case 'error':
+ return 'cross'
+ case 'success':
+ return 'tick'
+ case 'info':
+ return 'help'
+ }
+ }
+
+ private initRouteEvents () {
+ const eventsObs = this.router.events
+
+ // Plugin hooks
+ this.peertubeRouter.getNavigationEndEvents().subscribe(e => {
+ this.hooks.runAction('action:router.navigation-end', 'common', { path: e.url })
+ })
+
+ // Automatically hide/display the menu
+ eventsObs.pipe(
+ filter((e: Event): e is GuardsCheckStart => e instanceof GuardsCheckStart),
+ filter(() => this.screenService.isInSmallView() || this.screenService.isInTouchScreen())
+ ).subscribe(() => this.menu.setMenuDisplay(false)) // User clicked on a link in the menu, change the page
+
+ // Handle lazy loaded module
+ eventsObs.pipe(
+ filter((e: Event): e is RouteConfigLoadStart => e instanceof RouteConfigLoadStart)
+ ).subscribe(() => this.loadingBar.useRef().start())
+
+ eventsObs.pipe(
+ filter((e: Event): e is RouteConfigLoadEnd => e instanceof RouteConfigLoadEnd)
+ ).subscribe(() => this.loadingBar.useRef().complete())
+ }
+
+ private async injectBroadcastMessage () {
+ this.broadcastMessage = null
+ this.screenService.isBroadcastMessageDisplayed = false
+
+ const messageConfig = this.serverConfig.broadcastMessage
+
+ if (messageConfig.enabled) {
+ // Already dismissed this message?
+ if (messageConfig.dismissable && localStorage.getItem(AppComponent.BROADCAST_MESSAGE_KEY) === messageConfig.message) {
+ return
+ }
+
+ const classes: { [id in BroadcastMessageLevel]: string } = {
+ info: 'alert-info',
+ warning: 'alert-warning',
+ error: 'alert-danger'
+ }
+
+ this.broadcastMessage = {
+ message: await this.markdownService.markdownToUnsafeHTML({ markdown: messageConfig.message }),
+ dismissable: messageConfig.dismissable,
+ class: classes[messageConfig.level]
+ }
+
+ this.screenService.isBroadcastMessageDisplayed = true
+ }
+ }
+
+ private injectJS () {
+ // Inject JS
+ if (this.serverConfig.instance.customizations.javascript) {
+ try {
+ /* eslint-disable no-eval */
+ eval(this.serverConfig.instance.customizations.javascript)
+ } catch (err) {
+ logger.error('Cannot eval custom JavaScript.', err)
+ }
+ }
+ }