electron.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. const {app, globalShortcut} = 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. // Quit when all windows are closed, except on macOS. There, it's common
  12. // for applications and their menu bar to stay active until the user quits
  13. // explicitly with Cmd + Q.
  14. app.on('window-all-closed', () => {
  15. if (process.platform !== 'darwin') {
  16. app.quit()
  17. }
  18. });
  19. app.on('ready', async () => {
  20. // app.setAppUserModelId('com.github.zadam.trilium');
  21. // if db is not initialized -> setup process
  22. // if db is initialized, then we need to wait until the migration process is finished
  23. if (await sqlInit.isDbInitialized()) {
  24. await sqlInit.dbReady;
  25. await windowService.createMainWindow(app);
  26. tray.createTray();
  27. }
  28. else {
  29. await windowService.createSetupWindow();
  30. }
  31. await windowService.registerGlobalShortcuts();
  32. });
  33. app.on('will-quit', () => {
  34. globalShortcut.unregisterAll();
  35. });
  36. // this is to disable electron warning spam in the dev console (local development only)
  37. process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
  38. require('./src/www');