electron.js 1.9 KB

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