forked from TriliumNext/Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron.ts
73 lines (56 loc) · 2.17 KB
/
electron.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
import electron from "electron";
import electronDebug from "electron-debug";
import electronDl from "electron-dl";
import sqlInit from "./src/services/sql_init.js";
import appIconService from "./src/services/app_icon.js";
import windowService from "./src/services/window.js";
import tray from "./src/services/tray.js";
import sourceMapSupport from "source-map-support";
sourceMapSupport.install();
// Prevent Trilium starting twice on first install and on uninstall for the Windows installer.
if ((await import('electron-squirrel-startup')).default) {
process.exit(0);
}
// Adds debug features like hotkeys for triggering dev tools and reload
electronDebug();
appIconService.installLocalAppIcon();
electronDl({ saveAs: true });
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
electron.app.commandLine.appendSwitch(
"enable-experimental-web-platform-features"
);
// 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.
electron.app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
electron.app.quit();
}
});
electron.app.on("ready", async () => {
// electron.app.setAppUserModelId('com.github.zadam.trilium');
// if db is not initialized -> setup process
// if db is initialized, then we need to wait until the migration process is finished
if (sqlInit.isDbInitialized()) {
await sqlInit.dbReady;
await windowService.createMainWindow(electron.app);
if (process.platform === "darwin") {
electron.app.on("activate", async () => {
if (electron.BrowserWindow.getAllWindows().length === 0) {
await windowService.createMainWindow(electron.app);
}
});
}
tray.createTray();
} else {
await windowService.createSetupWindow();
}
await windowService.registerGlobalShortcuts();
});
electron.app.on("will-quit", () => {
electron.globalShortcut.unregisterAll();
});
// this is to disable electron warning spam in the dev console (local development only)
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
await import('./src/main.js');