2017-10-20 23:43:20 -04:00
|
|
|
'use strict';
|
2018-01-28 22:18:14 -05:00
|
|
|
|
2019-12-24 14:42:03 +01:00
|
|
|
const {app, globalShortcut} = require('electron');
|
2019-03-31 11:21:44 +02:00
|
|
|
const sqlInit = require('./src/services/sql_init');
|
2018-11-21 11:01:03 +01:00
|
|
|
const appIconService = require('./src/services/app_icon');
|
2019-12-24 14:42:03 +01:00
|
|
|
const windowService = require('./src/services/window');
|
2017-10-20 23:43:20 -04:00
|
|
|
|
|
|
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
|
|
|
require('electron-debug')();
|
|
|
|
|
2018-11-21 11:01:03 +01:00
|
|
|
appIconService.installLocalAppIcon();
|
|
|
|
|
2018-02-18 22:19:07 -05:00
|
|
|
require('electron-dl')({ saveAs: true });
|
|
|
|
|
2017-10-20 23:43:20 -04:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit();
|
|
|
|
}
|
2019-11-13 20:28:14 +01: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-20 23:43:20 -04:00
|
|
|
});
|
|
|
|
|
2019-11-21 21:12:07 +01:00
|
|
|
app.on('ready', async () => {
|
|
|
|
app.setAppUserModelId('com.github.zadam.trilium');
|
|
|
|
|
2019-12-24 14:42:03 +01:00
|
|
|
await sqlInit.dbConnection;
|
|
|
|
|
|
|
|
// if schema doesn't exist -> setup process
|
|
|
|
// if schema exists, then we need to wait until the migration process is finished
|
|
|
|
if (await sqlInit.schemaExists()) {
|
|
|
|
await sqlInit.dbReady;
|
|
|
|
|
|
|
|
await windowService.createMainWindow();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
await windowService.createSetupWindow();
|
|
|
|
}
|
2019-11-21 21:12:07 +01:00
|
|
|
|
2019-12-27 20:28:27 +01:00
|
|
|
await windowService.registerGlobalShortcuts();
|
2018-02-12 23:53:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
app.on('will-quit', () => {
|
|
|
|
globalShortcut.unregisterAll();
|
2017-10-20 23:43:20 -04:00
|
|
|
});
|
|
|
|
|
2018-01-31 08:03:25 -05:00
|
|
|
require('./src/www');
|