11// Scrips are moved to scripts/renderer/preload.js so node integration can be disabled
22// in the application window.
3+
4+ /* eslint-disable no-console */
5+
36/**
47 * Class responsible for initializing the main ARC elements
58 * and setup base options.
@@ -94,6 +97,7 @@ class ArcInit {
9497 ipc . on ( 'app-navigate' , this . _appNavHandler . bind ( this ) ) ;
9598 ipc . on ( 'popup-app-menu-opened' , this . _popupMenuOpened . bind ( this ) ) ;
9699 ipc . on ( 'popup-app-menu-closed' , this . _popupMenuClosed . bind ( this ) ) ;
100+ ipc . on ( 'system-theme-changed' , this . _systemThemeChangeHandler . bind ( this ) ) ;
97101 }
98102 /**
99103 * Requests initial state information from the main process for current
@@ -145,9 +149,9 @@ class ArcInit {
145149 throw e ;
146150 }
147151 if ( this . initConfig . darkMode ) {
148- cnf . theme = 'advanced-rest-client/arc-electron-dark-theme' ;
152+ cnf . theme = '@ advanced-rest-client/arc-electron-dark-theme' ;
149153 }
150- if ( cnf . theme === 'advanced-rest-client/arc-electron-anypoint-theme' ) {
154+ if ( cnf . theme === '@ advanced-rest-client/arc-electron-anypoint-theme' ) {
151155 const app = this . app ;
152156 app . compatibility = true ;
153157 }
@@ -177,6 +181,7 @@ class ArcInit {
177181 if ( this . created ) {
178182 return Promise . resolve ( ) ;
179183 }
184+ /* eslint-disable-next-line import/no-unresolved */
180185 await import ( 'web-module://src/arc-electron.js' ) ;
181186 const app = document . createElement ( 'arc-electron' ) ;
182187 app . id = 'app' ;
@@ -237,7 +242,7 @@ class ArcInit {
237242 */
238243 commandHandler ( e , action , ...args ) {
239244 // console.info('Renderer command handled: ', action);
240- const app = this . app ;
245+ const { app } = this ;
241246 switch ( action ) {
242247 case 'show-settings' : app . openSettings ( ) ; break ;
243248 case 'about' : app . openAbout ( ) ; break ;
@@ -262,6 +267,7 @@ class ArcInit {
262267 case 'open-onboarding' : app . openOnboarding ( ) ; break ;
263268 case 'open-workspace-details' : app . openWorkspaceDetails ( ) ; break ;
264269 case 'export-workspace' : this . exportWorkspace ( ) ; break ;
270+ case 'open-client-certificates' : app . openClientCertificates ( ) ; break ;
265271 default :
266272 console . warn ( 'Unknown command' , action , args ) ;
267273 }
@@ -504,6 +510,26 @@ class ArcInit {
504510 const workspace = this . app . workspace . serializeWorkspace ( ) ;
505511 return await this . fs . exportFileData ( workspace , 'application/json' , 'arc-workspace.arc' ) ;
506512 }
513+ /**
514+ * Handler for system theme change event dispatche in the IO thread.
515+ * Updates theme depending on current setting.
516+ *
517+ * @param {Event } e
518+ * @param {Boolean } isDarkMode true when Electron detected dark mode
519+ * @return {Promise }
520+ */
521+ async _systemThemeChangeHandler ( e , isDarkMode ) {
522+ const theme = isDarkMode ?
523+ '@advanced-rest-client/arc-electron-dark-theme' :
524+ '@advanced-rest-client/arc-electron-default-theme' ;
525+ const app = this . app ;
526+ app . compatibility = false ;
527+ try {
528+ await this . themeManager . loadTheme ( theme ) ;
529+ } catch ( e ) {
530+ console . error ( e ) ;
531+ }
532+ }
507533}
508534
509535const initScript = new ArcInit ( ) ;
0 commit comments