2017-10-20 23:43:20 -04:00
|
|
|
'use strict';
|
2018-01-28 22:18:14 -05:00
|
|
|
|
2022-10-27 19:59:41 -05:00
|
|
|
const {app, globalShortcut, BrowserWindow} = require('electron');
|
2023-11-22 19:34:48 +01:00
|
|
|
const sqlInit = require('./src/services/sql_init.js');
|
|
|
|
const appIconService = require('./src/services/app_icon.js');
|
|
|
|
const windowService = require('./src/services/window.js');
|
|
|
|
const tray = require('./src/services/tray.js');
|
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 });
|
|
|
|
|
2023-09-21 12:29:11 +02:00
|
|
|
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
|
|
|
app.commandLine.appendSwitch("enable-experimental-web-platform-features");
|
|
|
|
|
2022-09-18 10:05:49 +02:00
|
|
|
// Quit when all windows are closed, except on macOS. There, it's common
|
|
|
|
// for applications and their menu bar to stay active until the user quits
|
|
|
|
// explicitly with Cmd + Q.
|
2017-10-20 23:43:20 -04:00
|
|
|
app.on('window-all-closed', () => {
|
2022-09-18 10:05:49 +02:00
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
2017-10-20 23:43:20 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-21 21:12:07 +01:00
|
|
|
app.on('ready', async () => {
|
2021-04-19 22:33:58 +02:00
|
|
|
// app.setAppUserModelId('com.github.zadam.trilium');
|
2019-11-21 21:12:07 +01:00
|
|
|
|
2020-02-19 22:09:49 +01:00
|
|
|
// if db is not initialized -> setup process
|
|
|
|
// if db is initialized, then we need to wait until the migration process is finished
|
2022-11-18 21:08:32 +01:00
|
|
|
if (sqlInit.isDbInitialized()) {
|
2019-12-24 14:42:03 +01:00
|
|
|
await sqlInit.dbReady;
|
|
|
|
|
2022-08-02 22:53:06 +02:00
|
|
|
await windowService.createMainWindow(app);
|
2021-11-20 12:52:23 +01:00
|
|
|
|
2022-10-27 19:59:41 -05:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.on('activate', async () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
await windowService.createMainWindow(app);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-20 12:52:23 +01:00
|
|
|
tray.createTray();
|
2019-12-24 14:42:03 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-02-08 17:44:34 +01:00
|
|
|
// this is to disable electron warning spam in the dev console (local development only)
|
2020-02-08 10:40:58 +01:00
|
|
|
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
|
|
|
|
|
2023-11-22 19:34:48 +01:00
|
|
|
require('./src/www.js');
|