diff options
Diffstat (limited to 'packages/main/src')
-rw-r--r-- | packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts index c4b3823..f1e3c7e 100644 --- a/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts +++ b/packages/main/src/infrastructure/electron/impl/ElectronMainWindow.ts | |||
@@ -25,9 +25,11 @@ import { | |||
25 | Translation, | 25 | Translation, |
26 | } from '@sophie/shared'; | 26 | } from '@sophie/shared'; |
27 | import { BrowserWindow, ipcMain, IpcMainEvent } from 'electron'; | 27 | import { BrowserWindow, ipcMain, IpcMainEvent } from 'electron'; |
28 | import { reaction } from 'mobx'; | ||
28 | import type { IJsonPatch } from 'mobx-state-tree'; | 29 | import type { IJsonPatch } from 'mobx-state-tree'; |
29 | 30 | ||
30 | import type MainStore from '../../../stores/MainStore.js'; | 31 | import type MainStore from '../../../stores/MainStore.js'; |
32 | import Disposer from '../../../utils/Disposer.js'; | ||
31 | import getLogger from '../../../utils/getLogger.js'; | 33 | import getLogger from '../../../utils/getLogger.js'; |
32 | import RendererBridge from '../RendererBridge.js'; | 34 | import RendererBridge from '../RendererBridge.js'; |
33 | import type { MainWindow, ServiceView } from '../types.js'; | 35 | import type { MainWindow, ServiceView } from '../types.js'; |
@@ -39,6 +41,10 @@ import lockWebContentsToFile from './lockWebContentsToFile.js'; | |||
39 | 41 | ||
40 | const log = getLogger('ElectronMainWindow'); | 42 | const log = getLogger('ElectronMainWindow'); |
41 | 43 | ||
44 | function getBackroundColor(useDarkTheme: boolean): string { | ||
45 | return useDarkTheme ? '#121212' : '#FFF'; | ||
46 | } | ||
47 | |||
42 | export default class ElectronMainWindow implements MainWindow { | 48 | export default class ElectronMainWindow implements MainWindow { |
43 | private readonly browserWindow: BrowserWindow; | 49 | private readonly browserWindow: BrowserWindow; |
44 | 50 | ||
@@ -66,6 +72,8 @@ export default class ElectronMainWindow implements MainWindow { | |||
66 | } | 72 | } |
67 | }; | 73 | }; |
68 | 74 | ||
75 | private readonly disposeBackgroundColorReaction: Disposer; | ||
76 | |||
69 | constructor( | 77 | constructor( |
70 | private readonly store: MainStore, | 78 | private readonly store: MainStore, |
71 | private readonly parent: ElectronViewFactory, | 79 | private readonly parent: ElectronViewFactory, |
@@ -74,6 +82,7 @@ export default class ElectronMainWindow implements MainWindow { | |||
74 | show: false, | 82 | show: false, |
75 | autoHideMenuBar: true, | 83 | autoHideMenuBar: true, |
76 | darkTheme: store.shared.shouldUseDarkColors, | 84 | darkTheme: store.shared.shouldUseDarkColors, |
85 | backgroundColor: getBackroundColor(store.shared.shouldUseDarkColors), | ||
77 | webPreferences: { | 86 | webPreferences: { |
78 | sandbox: true, | 87 | sandbox: true, |
79 | devTools: parent.devMode, | 88 | devTools: parent.devMode, |
@@ -126,6 +135,13 @@ export default class ElectronMainWindow implements MainWindow { | |||
126 | 135 | ||
127 | webContents.userAgent = parent.userAgents.mainWindowUserAgent; | 136 | webContents.userAgent = parent.userAgents.mainWindowUserAgent; |
128 | 137 | ||
138 | this.disposeBackgroundColorReaction = reaction( | ||
139 | () => store.shared.shouldUseDarkColors, | ||
140 | (useDarkTheme) => { | ||
141 | this.browserWindow.setBackgroundColor(getBackroundColor(useDarkTheme)); | ||
142 | }, | ||
143 | ); | ||
144 | |||
129 | this.browserWindow.on('ready-to-show', () => this.browserWindow.show()); | 145 | this.browserWindow.on('ready-to-show', () => this.browserWindow.show()); |
130 | 146 | ||
131 | this.browserWindow.on('close', () => this.dispose()); | 147 | this.browserWindow.on('close', () => this.dispose()); |
@@ -171,6 +187,7 @@ export default class ElectronMainWindow implements MainWindow { | |||
171 | 187 | ||
172 | dispose() { | 188 | dispose() { |
173 | this.bridge.dispose(); | 189 | this.bridge.dispose(); |
190 | this.disposeBackgroundColorReaction(); | ||
174 | this.browserWindow.destroy(); | 191 | this.browserWindow.destroy(); |
175 | ipcMain.removeHandler(RendererToMainIpcMessage.GetSharedStoreSnapshot); | 192 | ipcMain.removeHandler(RendererToMainIpcMessage.GetSharedStoreSnapshot); |
176 | ipcMain.removeListener( | 193 | ipcMain.removeListener( |