From e56cdad02c00adf3b779d9de62d460e78be204a6 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 26 Dec 2021 19:17:23 +0100 Subject: refactor: Clarify main process architecture * stores: reactive data structures to hold application state * controllers: subscribe to store changes and call store actions in response to external events from services * services: integrate with the nodejs and electron environment (should be mocked for unit testing) --- packages/main/src/index.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'packages/main/src/index.ts') diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 8297ff5..67f5546 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -23,7 +23,6 @@ import { BrowserView, BrowserWindow, ipcMain, - nativeTheme, } from 'electron'; import { readFileSync } from 'fs'; import { readFile } from 'fs/promises'; @@ -47,7 +46,10 @@ import { installDevToolsExtensions, openDevToolsWhenReady, } from './devTools'; -import { ConfigPersistenceImpl } from './services/impl/ConfigPersistenceImpl'; +import { initConfig } from './controllers/ConfigController'; +import { initNativeTheme } from './controllers/NativeThemeController'; +import { ConfigPersistenceService } from './services/ConfigPersistenceService'; +import { NativeThemeService } from './services/NativeThemeService'; import { createMainStore } from './stores/MainStore'; const isDevelopment = import.meta.env.MODE === 'development'; @@ -105,23 +107,14 @@ if (isDevelopment) { let mainWindow: BrowserWindow | null = null; -const store = createMainStore({ - configPersistence: new ConfigPersistenceImpl( - app.getPath('userData'), - 'config.json5', - ), -}); - -autorun(() => { - nativeTheme.themeSource = store.config.themeSource; -}); - -store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); -nativeTheme.on('updated', () => { - store.setShouldUseDarkColors(nativeTheme.shouldUseDarkColors); -}); +const store = createMainStore(); -store.config.initConfig(); +initConfig( + store.config, + new ConfigPersistenceService(app.getPath('userData'), 'config.json5'), +).then(() => { + initNativeTheme(store, new NativeThemeService()); +}).catch((err) => console.error(err)); const rendererBaseUrl = getResourceUrl('../renderer/'); function shouldCancelMainWindowRequest(url: string, method: string): boolean { -- cgit v1.2.3-54-g00ecf