2017-10-21 11:43:20 +08:00
|
|
|
'use strict';
|
2018-01-29 11:18:14 +08:00
|
|
|
|
2019-12-24 21:42:03 +08:00
|
|
|
const {app, globalShortcut} = require('electron');
|
2019-03-31 17:21:44 +08:00
|
|
|
const sqlInit = require('./src/services/sql_init');
|
2018-11-21 18:01:03 +08:00
|
|
|
const appIconService = require('./src/services/app_icon');
|
2019-12-24 21:42:03 +08:00
|
|
|
const windowService = require('./src/services/window');
|
2021-11-14 20:36:39 +08:00
|
|
|
const tray = require('./src/services/tray');
|
2017-10-21 11:43:20 +08:00
|
|
|
|
|
|
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
|
|
|
require('electron-debug')();
|
|
|
|
|
2018-11-21 18:01:03 +08:00
|
|
|
appIconService.installLocalAppIcon();
|
|
|
|
|
2018-02-19 11:19:07 +08:00
|
|
|
require('electron-dl')({ saveAs: true });
|
|
|
|
|
2017-10-21 11:43:20 +08:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit();
|
|
|
|
}
|
2019-11-14 03:28:14 +08:00
|
|
|
else if (process.platform === 'win32') {
|
|
|
|
app.exit(0); // attempt to fix the issue when app.quite() won't terminate processes on windows
|
|
|
|
}
|
2017-10-21 11:43:20 +08:00
|
|
|
});
|
|
|
|
|
2019-11-22 04:12:07 +08:00
|
|
|
app.on('ready', async () => {
|
2021-04-20 04:33:58 +08:00
|
|
|
// app.setAppUserModelId('com.github.zadam.trilium');
|
2019-11-22 04:12:07 +08:00
|
|
|
|
2020-02-20 05:09:49 +08:00
|
|
|
// if db is not initialized -> setup process
|
|
|
|
// if db is initialized, then we need to wait until the migration process is finished
|
|
|
|
if (await sqlInit.isDbInitialized()) {
|
2019-12-24 21:42:03 +08:00
|
|
|
await sqlInit.dbReady;
|
|
|
|
|
|
|
|
await windowService.createMainWindow();
|
2021-11-20 19:52:23 +08:00
|
|
|
|
|
|
|
tray.createTray();
|
2019-12-24 21:42:03 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
await windowService.createSetupWindow();
|
|
|
|
}
|
2019-11-22 04:12:07 +08:00
|
|
|
|
2019-12-28 03:28:27 +08:00
|
|
|
await windowService.registerGlobalShortcuts();
|
2018-02-13 12:53:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
app.on('will-quit', () => {
|
|
|
|
globalShortcut.unregisterAll();
|
2017-10-21 11:43:20 +08:00
|
|
|
});
|
|
|
|
|
2020-02-09 00:44:34 +08:00
|
|
|
// this is to disable electron warning spam in the dev console (local development only)
|
2020-02-08 17:40:58 +08:00
|
|
|
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
|
|
|
|
|
2018-01-31 21:03:25 +08:00
|
|
|
require('./src/www');
|