electron.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. import { app, globalShortcut, BrowserWindow } from 'electron';
  3. import sqlInit from './src/services/sql_init.js';
  4. import appIconService from './src/services/app_icon.js';
  5. import windowService from './src/services/window.js';
  6. import tray from './src/services/tray.js';
  7. import electron_debug from "electron-debug";
  8. import electron_dl from "electron-dl";
  9. import './src/www.js';
  10. // Adds debug features like hotkeys for triggering dev tools and reload
  11. electron_debug();
  12. appIconService.installLocalAppIcon();
  13. electron_dl({ saveAs: true });
  14. // needed for excalidraw export https://github.com/zadam/trilium/issues/4271
  15. app.commandLine.appendSwitch("enable-experimental-web-platform-features");
  16. // Quit when all windows are closed, except on macOS. There, it's common
  17. // for applications and their menu bar to stay active until the user quits
  18. // explicitly with Cmd + Q.
  19. app.on('window-all-closed', () => {
  20. if (process.platform !== 'darwin') {
  21. app.quit()
  22. }
  23. });
  24. app.on('ready', async () => {
  25. // app.setAppUserModelId('com.github.zadam.trilium');
  26. // if db is not initialized -> setup process
  27. // if db is initialized, then we need to wait until the migration process is finished
  28. if (sqlInit.isDbInitialized()) {
  29. await sqlInit.dbReady;
  30. await windowService.createMainWindow(app);
  31. if (process.platform === 'darwin') {
  32. app.on('activate', async () => {
  33. if (BrowserWindow.getAllWindows().length === 0) {
  34. await windowService.createMainWindow(app);
  35. }
  36. });
  37. }
  38. tray.createTray();
  39. }
  40. else {
  41. await windowService.createSetupWindow();
  42. }
  43. await windowService.registerGlobalShortcuts();
  44. });
  45. app.on('will-quit', () => {
  46. globalShortcut.unregisterAll();
  47. });
  48. // this is to disable electron warning spam in the dev console (local development only)
  49. process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';