mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
electron: Fix initial sync (closes #284)
Apparently the issue was caused by options_init which for Electron was attempting to read the theme asynchronously. That's why it didn't cause issues on the server build.
This commit is contained in:
parent
bc5a1de9b7
commit
99ca701a5c
@ -16,7 +16,7 @@ interface NotSyncedOpts {
|
|||||||
syncProxy?: string;
|
syncProxy?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts = {}) {
|
async function initNotSyncedOptions(initialized: boolean, theme: string, opts: NotSyncedOpts = {}) {
|
||||||
optionService.createOption('openNoteContexts', JSON.stringify([
|
optionService.createOption('openNoteContexts', JSON.stringify([
|
||||||
{
|
{
|
||||||
notePath: 'root',
|
notePath: 'root',
|
||||||
@ -32,15 +32,7 @@ async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts =
|
|||||||
optionService.createOption('initialized', initialized ? 'true' : 'false', false);
|
optionService.createOption('initialized', initialized ? 'true' : 'false', false);
|
||||||
|
|
||||||
optionService.createOption('lastSyncedPull', '0', false);
|
optionService.createOption('lastSyncedPull', '0', false);
|
||||||
optionService.createOption('lastSyncedPush', '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('theme', theme, false);
|
optionService.createOption('theme', theme, false);
|
||||||
|
|
||||||
|
@ -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();
|
triggerSync();
|
||||||
|
|
||||||
return { result: 'success' };
|
return { result: 'success' };
|
||||||
|
@ -58,6 +58,7 @@ async function createInitialDatabase() {
|
|||||||
|
|
||||||
const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf-8");
|
const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf-8");
|
||||||
const demoFile = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/demo.zip`);
|
const demoFile = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/demo.zip`);
|
||||||
|
const defaultTheme = await getDefaultTheme();
|
||||||
|
|
||||||
let rootNote!: BNote;
|
let rootNote!: BNote;
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ async function createInitialDatabase() {
|
|||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
optionsInitService.initDocumentOptions();
|
optionsInitService.initDocumentOptions();
|
||||||
optionsInitService.initNotSyncedOptions(true, {});
|
optionsInitService.initNotSyncedOptions(true, defaultTheme, {});
|
||||||
optionsInitService.initStartupOptions();
|
optionsInitService.initStartupOptions();
|
||||||
password.resetPassword();
|
password.resetPassword();
|
||||||
});
|
});
|
||||||
@ -118,19 +119,20 @@ async function createInitialDatabase() {
|
|||||||
initDbConnection();
|
initDbConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncProxy = '') {
|
async function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncProxy = '') {
|
||||||
log.info("Creating database for sync");
|
log.info("Creating database for sync");
|
||||||
|
|
||||||
if (isDbInitialized()) {
|
if (isDbInitialized()) {
|
||||||
throw new Error("DB is already initialized");
|
throw new Error("DB is already initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultTheme = await getDefaultTheme();
|
||||||
const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf8");
|
const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, "utf8");
|
||||||
|
|
||||||
sql.transactional(() => {
|
sql.transactional(() => {
|
||||||
sql.executeScript(schema);
|
sql.executeScript(schema);
|
||||||
|
|
||||||
optionsInitService.initNotSyncedOptions(false, { syncServerHost, syncProxy });
|
optionsInitService.initNotSyncedOptions(false, defaultTheme, { syncServerHost, syncProxy });
|
||||||
|
|
||||||
// document options required for sync to kick off
|
// document options required for sync to kick off
|
||||||
for (const opt of options) {
|
for (const opt of options) {
|
||||||
@ -141,6 +143,16 @@ function createDatabaseForSync(options: OptionRow[], syncServerHost = '', syncPr
|
|||||||
log.info("Schema and not synced options generated.");
|
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() {
|
function setDbAsInitialized() {
|
||||||
if (!isDbInitialized()) {
|
if (!isDbInitialized()) {
|
||||||
optionService.setOption('initialized', 'true');
|
optionService.setOption('initialized', 'true');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user