@@ -14,18 +14,18 @@ export type SystemTheme = 'light' | 'dark';
1414export type ResetBoundType = 'bounds' | 'position' | '' ;
1515
1616class AppState {
17- private _autoLauncher = new AutoLaunch ( { name : 'Handbook' } ) ;
17+ private readonly _autoLauncher = new AutoLaunch ( { name : 'Handbook' } ) ;
1818 private _strings : Strings = getLanguageStrings ( Storage . getSettings ( Settings . APP_LANGUAGE ) || app . getLocale ( ) ) ;
1919 private _defaultAppMenu ?: MenuItem [ ] ;
2020 private _globalShortcut = '' ;
2121 private _resetBoundsType : ResetBoundType = Storage . getSettings ( Settings . RESET_BOUNDS ) ;
2222 private _systemTheme = this . getSystemTheme ( ) ;
2323 private _tray ?: Tray ;
2424 private _preferences ?: BrowserWindow ;
25- private _fromClipboardPage : Page = new Page ( void 0 , this . strings . menu . fromClipboard ) ;
2625 private _pages : Page [ ] = [ ] ;
27- private _appMenuTemplate : MenuItemConstructorOptions [ ] = [ ] ;
26+ private readonly _fromClipboardPage : Page = new Page ( void 0 , this . strings . menu . fromClipboard ) ;
2827 private readonly currentStack : { frame ?: BaseWindow , navbar ?: WebContentsView , page ?: Page } = { } ;
28+ private readonly onViewChangeHandler = function ( this : Page ) { ViewPropagator . propagate ( this . view ) ; } ;
2929 private readonly contextMenu : {
3030 tray ?: MenuItemConstructorOptions [ ] ,
3131 view ?: MenuItemConstructorOptions [ ] ,
@@ -63,14 +63,14 @@ class AppState {
6363 this . currentStack . page = page ;
6464 if ( page ) {
6565 ViewPropagator . propagate ( page . view ) ;
66- page . setViewChangeHandler ( ( ) => ViewPropagator . propagate ( page . view ) ) ;
66+ if ( ! page . hasViewChangeHandler ( ) ) {
67+ page . setViewChangeHandler ( this . onViewChangeHandler ) ;
68+ }
6769 }
6870 }
6971 get currentPage ( ) : Page | undefined { return this . currentStack . page ; }
7072 set pages ( pages : Page [ ] ) { this . _pages = pages ; }
7173 get pages ( ) : Page [ ] { return this . _pages ; }
72- get appMenuTemplate ( ) : MenuItemConstructorOptions [ ] { return this . _appMenuTemplate ; }
73- set appMenuTemplate ( template : MenuItemConstructorOptions [ ] ) { this . _appMenuTemplate = template ; }
7474
7575 set googleApiKey ( key : string ) { process . env . GOOGLE_API_KEY = key ; }
7676 set themeSource ( theme : 'light' | 'dark' | 'system' ) { nativeTheme . themeSource = theme ; }
@@ -98,9 +98,10 @@ class AppState {
9898 if ( process . env . NODE_ENV !== 'development' ) { return [ ] ; }
9999 const allPages = ( ) => [ this . _fromClipboardPage , ...this . _pages ] ;
100100 const pageType = ( current ?: Page ) => {
101- return ! current ? '' :
102- ! current . view ? 'no view' :
103- current . view . webContents . isDestroyed ( ) ? 'view: destroyed' : 'view: alive' ;
101+ if ( ! current ) { return '' ; }
102+ if ( ! current . view ) { return 'no view' ; }
103+ return current . label + ( current . hasView ?
104+ current . view . webContents && ! current . view . webContents . isDestroyed ( ) ? ': alive' : ': destroyed' : '' ) ;
104105 } ;
105106
106107 return [
0 commit comments