@@ -14,18 +14,19 @@ export type SystemTheme = 'light' | 'dark';
1414export type ResetBoundType = 'bounds' | 'position' | '' ;
1515
1616class AppState {
17- private _autoLauncher = new AutoLaunch ( { name : 'Handbook' } ) ;
18- private _strings : Strings = getLanguageStrings ( Storage . getSettings ( Settings . APP_LANGUAGE ) || app . getLocale ( ) ) ;
17+ private readonly _autoLauncher = new AutoLaunch ( { name : 'Handbook' } ) ;
18+ private _language = Storage . getSettings < string > ( Settings . APP_LANGUAGE ) || app . getLocale ( ) ;
19+ private _strings : Strings = getLanguageStrings ( this . _language ) ;
1920 private _defaultAppMenu ?: MenuItem [ ] ;
2021 private _globalShortcut = '' ;
2122 private _resetBoundsType : ResetBoundType = Storage . getSettings ( Settings . RESET_BOUNDS ) ;
2223 private _systemTheme = this . getSystemTheme ( ) ;
2324 private _tray ?: Tray ;
2425 private _preferences ?: BrowserWindow ;
25- private _fromClipboardPage : Page = new Page ( void 0 , this . strings . menu . fromClipboard ) ;
2626 private _pages : Page [ ] = [ ] ;
27- private _appMenuTemplate : MenuItemConstructorOptions [ ] = [ ] ;
27+ private readonly _fromClipboardPage : Page = new Page ( void 0 , this . strings . menu . fromClipboard ) ;
2828 private readonly currentStack : { frame ?: BaseWindow , navbar ?: WebContentsView , page ?: Page } = { } ;
29+ private readonly onViewChangeHandler = function ( this : Page ) { ViewPropagator . propagate ( this . view ) ; } ;
2930 private readonly contextMenu : {
3031 tray ?: MenuItemConstructorOptions [ ] ,
3132 view ?: MenuItemConstructorOptions [ ] ,
@@ -35,6 +36,7 @@ class AppState {
3536 constructor ( ) { this . debugLifecycleStatus ( ) ; }
3637
3738 get autoLauncher ( ) : AutoLaunch { return this . _autoLauncher ; }
39+ get language ( ) : string { return this . _language ; }
3840 get strings ( ) : Strings { return this . _strings ; }
3941 set defaultAppMenu ( template : MenuItem [ ] ) { this . _defaultAppMenu = template ; }
4042 get defaultAppMenu ( ) : MenuItem [ ] { return this . _defaultAppMenu ! ; }
@@ -63,20 +65,21 @@ class AppState {
6365 this . currentStack . page = page ;
6466 if ( page ) {
6567 ViewPropagator . propagate ( page . view ) ;
66- page . setViewChangeHandler ( ( ) => ViewPropagator . propagate ( page . view ) ) ;
68+ if ( ! page . hasViewChangeHandler ( ) ) {
69+ page . setViewChangeHandler ( this . onViewChangeHandler ) ;
70+ }
6771 }
6872 }
6973 get currentPage ( ) : Page | undefined { return this . currentStack . page ; }
7074 set pages ( pages : Page [ ] ) { this . _pages = pages ; }
7175 get pages ( ) : Page [ ] { return this . _pages ; }
72- get appMenuTemplate ( ) : MenuItemConstructorOptions [ ] { return this . _appMenuTemplate ; }
73- set appMenuTemplate ( template : MenuItemConstructorOptions [ ] ) { this . _appMenuTemplate = template ; }
7476
7577 set googleApiKey ( key : string ) { process . env . GOOGLE_API_KEY = key ; }
7678 set themeSource ( theme : 'light' | 'dark' | 'system' ) { nativeTheme . themeSource = theme ; }
7779
7880 public refreshStrings ( ) {
79- this . _strings = getLanguageStrings ( Storage . getSettings ( Settings . APP_LANGUAGE ) || app . getLocale ( ) ) ;
81+ this . _language = Storage . getSettings < string > ( Settings . APP_LANGUAGE ) || app . getLocale ( ) ;
82+ this . _strings = getLanguageStrings ( this . _language ) ;
8083 this . _fromClipboardPage . label = this . strings . menu . fromClipboard ;
8184 }
8285
@@ -98,9 +101,10 @@ class AppState {
98101 if ( process . env . NODE_ENV !== 'development' ) { return [ ] ; }
99102 const allPages = ( ) => [ this . _fromClipboardPage , ...this . _pages ] ;
100103 const pageType = ( current ?: Page ) => {
101- return ! current ? '' :
102- ! current . view ? 'no view' :
103- current . view . webContents . isDestroyed ( ) ? 'view: destroyed' : 'view: alive' ;
104+ if ( ! current ) { return '' ; }
105+ if ( ! current . view ) { return 'no view' ; }
106+ return current . label + ( current . hasView ?
107+ current . view . webContents && ! current . view . webContents . isDestroyed ( ) ? ': alive' : ': destroyed' : '' ) ;
104108 } ;
105109
106110 return [
0 commit comments