@@ -3,6 +3,8 @@ import { autoUpdater } from 'electron-updater';
33import { existsSync } from 'node:fs' ;
44import { join } from 'node:path' ;
55import { DEFAULT_BLUETOOTH_STATUS } from '../shared/bluetooth-status' ;
6+ import { SHOW_SETTINGS_SECTION_CHANNEL } from '../shared/ipc-channels' ;
7+ import type { SettingsSectionId } from '../shared/settings' ;
68import { WindowsBluetoothTransport } from './bluetooth/bluetooth-transport' ;
79import { ControlService } from './control/control-service' ;
810import { CursorOverlay } from './cursor-overlay' ;
@@ -122,7 +124,11 @@ function createMainWindow(options: MainWindowOptions = {}): BrowserWindow {
122124 return window ;
123125}
124126
125- function createSettingsWindow ( ) : BrowserWindow {
127+ function settingsHashForSection ( section : SettingsSectionId ) : string {
128+ return section === 'general' ? '/settings' : `/settings/${ section } ` ;
129+ }
130+
131+ function createSettingsWindow ( section : SettingsSectionId = 'general' ) : BrowserWindow {
126132 const iconPath = appIconPath ( ) ;
127133 const window = new BrowserWindow ( {
128134 width : 820 ,
@@ -172,10 +178,10 @@ function createSettingsWindow(): BrowserWindow {
172178
173179 if ( isDev && process . env . ELECTRON_RENDERER_URL ) {
174180 const url = new URL ( process . env . ELECTRON_RENDERER_URL ) ;
175- url . hash = '/settings' ;
181+ url . hash = settingsHashForSection ( section ) ;
176182 void window . loadURL ( url . toString ( ) ) ;
177183 } else {
178- void window . loadFile ( join ( __dirname , '../renderer/index.html' ) , { hash : '/settings' } ) ;
184+ void window . loadFile ( join ( __dirname , '../renderer/index.html' ) , { hash : settingsHashForSection ( section ) } ) ;
179185 }
180186
181187 return window ;
@@ -194,9 +200,24 @@ function showMainWindow(): void {
194200 mainWindow . focus ( ) ;
195201}
196202
197- function showSettingsWindow ( ) : void {
203+ function sendSettingsSection ( window : BrowserWindow , section : SettingsSectionId ) : void {
204+ const send = ( ) : void => {
205+ if ( ! window . isDestroyed ( ) ) {
206+ window . webContents . send ( SHOW_SETTINGS_SECTION_CHANNEL , section ) ;
207+ }
208+ } ;
209+
210+ if ( window . webContents . isLoading ( ) ) {
211+ window . webContents . once ( 'did-finish-load' , send ) ;
212+ return ;
213+ }
214+
215+ send ( ) ;
216+ }
217+
218+ function showSettingsWindow ( section : SettingsSectionId = 'general' ) : void {
198219 if ( ! settingsWindow || settingsWindow . isDestroyed ( ) ) {
199- settingsWindow = createSettingsWindow ( ) ;
220+ settingsWindow = createSettingsWindow ( section ) ;
200221 return ;
201222 }
202223
@@ -205,6 +226,7 @@ function showSettingsWindow(): void {
205226 }
206227 settingsWindow . show ( ) ;
207228 settingsWindow . focus ( ) ;
229+ sendSettingsSection ( settingsWindow , section ) ;
208230}
209231
210232function quitApp ( ) : void {
0 commit comments