trilium/electron.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-10-21 11:43:20 +08:00
'use strict';
2018-01-29 11:18:14 +08:00
const {app, globalShortcut} = require('electron');
const sqlInit = require('./src/services/sql_init');
const appIconService = require('./src/services/app_icon');
const windowService = require('./src/services/window');
2017-10-21 11:43:20 +08:00
// Adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')();
appIconService.installLocalAppIcon();
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
});
app.on('ready', async () => {
app.setAppUserModelId('com.github.zadam.trilium');
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();
}
await windowService.registerGlobalShortcuts();
});
app.on('will-quit', () => {
globalShortcut.unregisterAll();
2017-10-21 11:43:20 +08:00
});
2018-01-31 21:03:25 +08:00
require('./src/www');