diff --git a/src/services/options_init.ts b/src/services/options_init.ts index a50d57296..b07300150 100644 --- a/src/services/options_init.ts +++ b/src/services/options_init.ts @@ -16,7 +16,7 @@ interface NotSyncedOpts { syncProxy?: string; } -async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) { +async function initNotSyncedOptions(initialized: boolean, theme: string, opts: NotSyncedOpts = {}) { optionService.createOption('openNoteContexts', JSON.stringify([ { notePath: 'root', @@ -32,15 +32,7 @@ async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = optionService.createOption('initialized', initialized ? 'true' : 'false', false); optionService.createOption('lastSyncedPull', '0', false); - optionService.createOption('lastSyncedPush', '0', false); - - let theme = 'dark'; // default based on the poll in https://github.com/zadam/trilium/issues/2516 - - if (utils.isElectron()) { - const {nativeTheme} = await import("electron"); - - theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'; - } + optionService.createOption('lastSyncedPush', '0', false); optionService.createOption('theme', theme, false); diff --git a/src/services/setup.ts b/src/services/setup.ts index 0f3d26f58..b632e8d08 100644 --- a/src/services/setup.ts +++ b/src/services/setup.ts @@ -87,8 +87,8 @@ async function setupSyncFromSyncServer(syncServerHost: string, syncProxy: string } } - sqlInit.createDatabaseForSync(resp.options, syncServerHost, syncProxy); - + await sqlInit.createDatabaseForSync(resp.options, syncServerHost, syncProxy); + triggerSync(); return { result: 'success' }; diff --git a/src/services/sql_init.ts b/src/services/sql_init.ts index a93750476..715514746 100644 --- a/src/services/sql_init.ts +++ b/src/services/sql_init.ts @@ -58,6 +58,7 @@ async function createInitialDatabase() { const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf-8"); const demoFile = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/demo.zip`); + const defaultTheme = await getDefaultTheme(); let rootNote!: BNote; @@ -87,7 +88,7 @@ async function createInitialDatabase() { }).save(); optionsInitService.initDocumentOptions(); - optionsInitService.initNotSyncedOptions(true, {}); + optionsInitService.initNotSyncedOptions(true, defaultTheme, {}); optionsInitService.initStartupOptions(); password.resetPassword(); }); @@ -118,19 +119,20 @@ async function createInitialDatabase() { initDbConnection(); } -function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncProxy = '') { +async function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncProxy = '') { log.info("Creating database for sync"); if (isDbInitialized()) { throw new Error("DB is already initialized"); } + const defaultTheme = await getDefaultTheme(); const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf8"); sql.transactional(() => { sql.executeScript(schema); - optionsInitService.initNotSyncedOptions(false, { syncServerHost, syncProxy }); + optionsInitService.initNotSyncedOptions(false, defaultTheme, { syncServerHost, syncProxy }); // document options required for sync to kick off for (const opt of options) { @@ -141,6 +143,16 @@ function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncPr log.info("Schema and not synced options generated."); } +async function getDefaultTheme() { + if (utils.isElectron()) { + const {nativeTheme} = await import("electron"); + return nativeTheme.shouldUseDarkColors ? 'dark' : 'light'; + } else { + // default based on the poll in https://github.com/zadam/trilium/issues/2516 + return "dark"; + } +} + function setDbAsInitialized() { if (!isDbInitialized()) { optionService.setOption('initialized', 'true');