Revert "open window before loading becca"

This reverts commit 2fbcd9aaf758c99bc59f81f524faa3e703aff227.
This commit is contained in:
zadam 2022-11-23 23:49:49 +01:00
parent 2fbcd9aaf7
commit e4e20c8007
8 changed files with 20 additions and 32 deletions

View File

@ -5,7 +5,6 @@ const sqlInit = require('./src/services/sql_init');
const appIconService = require('./src/services/app_icon'); const appIconService = require('./src/services/app_icon');
const windowService = require('./src/services/window'); const windowService = require('./src/services/window');
const tray = require('./src/services/tray'); const tray = require('./src/services/tray');
const beccaLoader = require("./src/becca/becca_loader");
// Adds debug features like hotkeys for triggering dev tools and reload // Adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')(); require('electron-debug')();
@ -29,17 +28,14 @@ app.on('ready', async () => {
// if db is not initialized -> setup process // if db is not initialized -> setup process
// if db is initialized, then we need to wait until the migration process is finished // if db is initialized, then we need to wait until the migration process is finished
if (sqlInit.isDbInitialized()) { if (sqlInit.isDbInitialized()) {
// first let electron open the window, it will probably keep initializing for some time in async
windowService.createMainWindow(app);
// then becca load will block the backend process for a while
await sqlInit.dbReady; await sqlInit.dbReady;
beccaLoader.loadInitially();
await windowService.createMainWindow(app);
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
app.on('activate', async () => { app.on('activate', async () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
windowService.createMainWindow(app); await windowService.createMainWindow(app);
} }
}); });
} }

View File

@ -14,7 +14,7 @@
}, },
"scripts": { "scripts": {
"start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev node ./src/www", "start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev node ./src/www",
"start-electron": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev electron --trace-warnings --inspect=5858 .", "start-electron": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev electron --inspect=5858 .",
"switch-server": "rm -r ./node_modules/better-sqlite3 && npm install", "switch-server": "rm -r ./node_modules/better-sqlite3 && npm install",
"switch-electron": "rm -r ./node_modules/better-sqlite3 && npm install && ./node_modules/.bin/electron-rebuild", "switch-electron": "rm -r ./node_modules/better-sqlite3 && npm install && ./node_modules/.bin/electron-rebuild",
"build-backend-docs": "rm -r ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js", "build-backend-docs": "rm -r ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js",

View File

@ -13,20 +13,16 @@ const EtapiToken = require("./entities/etapi_token");
const cls = require("../services/cls"); const cls = require("../services/cls");
const entityConstructor = require("../becca/entity_constructor"); const entityConstructor = require("../becca/entity_constructor");
let setBeccaAsLoaded = null;
const beccaLoaded = new Promise((res, rej) => { const beccaLoaded = new Promise((res, rej) => {
setBeccaAsLoaded = res; sqlInit.dbReady.then(() => {
load();
cls.init(() => require('../services/options_init').initStartupOptions());
res();
});
}); });
function loadInitially() {
load();
cls.init(() => require('../services/options_init').initStartupOptions());
setBeccaAsLoaded();
}
function load() { function load() {
const start = Date.now(); const start = Date.now();
becca.reset(); becca.reset();
@ -249,6 +245,5 @@ eventService.subscribeBeccaLoader(eventService.LEAVE_PROTECTED_SESSION, load);
module.exports = { module.exports = {
load, load,
reload, reload,
beccaLoaded, beccaLoaded
loadInitially
}; };

View File

@ -1,7 +1,8 @@
"use strict"; "use strict";
const becca = require('./becca'); const becca = require('./becca.js');
const cls = require('../services/cls'); const cls = require('../services/cls');
const protectedSessionService = require('../services/protected_session');
const log = require('../services/log'); const log = require('../services/log');
function isNotePathArchived(notePath) { function isNotePathArchived(notePath) {

View File

@ -1,12 +1,12 @@
const scriptService = require('./script'); const scriptService = require('./script');
const cls = require('./cls'); const cls = require('./cls');
const sqlInit = require('./sql_init');
const config = require('./config'); const config = require('./config');
const log = require('./log'); const log = require('./log');
const sql = require("./sql"); const sql = require("./sql");
const becca = require("../becca/becca"); const becca = require("../becca/becca");
const specialNotesService = require("../services/special_notes"); const specialNotesService = require("../services/special_notes");
const protectedSessionService = require("../services/protected_session"); const protectedSessionService = require("../services/protected_session");
const beccaLoader = require("../becca/becca_loader");
function getRunAtHours(note) { function getRunAtHours(note) {
try { try {
@ -50,7 +50,7 @@ function runNotesWithLabel(runAttrValue) {
} }
} }
beccaLoader.beccaLoaded.then(() => { sqlInit.dbReady.then(() => {
if (!process.env.TRILIUM_SAFE_MODE) { if (!process.env.TRILIUM_SAFE_MODE) {
cls.init(() => specialNotesService.createMissingSpecialNotes()); cls.init(() => specialNotesService.createMissingSpecialNotes());

View File

@ -10,6 +10,7 @@ const becca = require('../../../becca/becca');
const beccaService = require('../../../becca/becca_service'); const beccaService = require('../../../becca/becca_service');
const utils = require('../../utils'); const utils = require('../../utils');
const log = require('../../log'); const log = require('../../log');
const scriptService = require("../../script.js");
function searchFromNote(note) { function searchFromNote(note) {
let searchResultNoteIds, highlightedTokens; let searchResultNoteIds, highlightedTokens;
@ -68,7 +69,6 @@ function searchFromRelation(note, relationName) {
return []; return [];
} }
const scriptService = require("../../script");
const result = scriptService.executeNote(scriptNote, { originEntity: note }); const result = scriptService.executeNote(scriptNote, { originEntity: note });
if (!Array.isArray(result)) { if (!Array.isArray(result)) {

View File

@ -44,11 +44,11 @@ ipcMain.on('create-extra-window', (event, arg) => {
createExtraWindow(arg.notePath, arg.hoistedNoteId); createExtraWindow(arg.notePath, arg.hoistedNoteId);
}); });
function createMainWindow(app) { async function createMainWindow(app) {
const windowStateKeeper = require('electron-window-state'); // should not be statically imported const windowStateKeeper = require('electron-window-state'); // should not be statically imported
const mainWindowState = windowStateKeeper({ const mainWindowState = windowStateKeeper({
// default window width & height, so it's usable on 1600 * 900 display (including some extra panels etc.) // default window width & height so it's usable on 1600 * 900 display (including some extra panels etc.)
defaultWidth: 1200, defaultWidth: 1200,
defaultHeight: 800 defaultHeight: 800
}); });

View File

@ -25,10 +25,10 @@ const log = require('./services/log');
const appInfo = require('./services/app_info'); const appInfo = require('./services/app_info');
const ws = require('./services/ws'); const ws = require('./services/ws');
const utils = require('./services/utils'); const utils = require('./services/utils');
const sqlInit = require('./services/sql_init');
const port = require('./services/port'); const port = require('./services/port');
const host = require('./services/host'); const host = require('./services/host');
const semver = require('semver'); const semver = require('semver');
const beccaLoader = require("./becca/becca_loader");
if (!semver.satisfies(process.version, ">=10.5.0")) { if (!semver.satisfies(process.version, ">=10.5.0")) {
console.error("Trilium only supports node.js 10.5 and later"); console.error("Trilium only supports node.js 10.5 and later");
@ -95,10 +95,6 @@ async function startTrilium() {
const cpuInfos = require('os').cpus(); const cpuInfos = require('os').cpus();
log.info(`CPU model: ${cpuInfos[0].model}, logical cores: ${cpuInfos.length} freq: ${cpuInfos[0].speed} Mhz`); // for perf. issues it's good to know the rough configuration log.info(`CPU model: ${cpuInfos[0].model}, logical cores: ${cpuInfos.length} freq: ${cpuInfos[0].speed} Mhz`); // for perf. issues it's good to know the rough configuration
if (!utils.isElectron()) {
beccaLoader.loadInitially();
}
/** /**
* Listen on provided port, on all network interfaces. * Listen on provided port, on all network interfaces.
*/ */