electron.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // Adds debug features like hotkeys for triggering dev tools and reload
  7. require('electron-debug')();
  8. appIconService.installLocalAppIcon();
  9. require('electron-dl')({ saveAs: true });
  10. app.on('window-all-closed', () => {
  11. if (process.platform !== 'darwin') {
  12. app.quit();
  13. }
  14. else if (process.platform === 'win32') {
  15. app.exit(0); // attempt to fix the issue when app.quite() won't terminate processes on windows
  16. }
  17. });
  18. app.on('ready', async () => {
  19. app.setAppUserModelId('com.github.zadam.trilium');
  20. // if db is not initialized -> setup process
  21. // if db is initialized, then we need to wait until the migration process is finished
  22. if (await sqlInit.isDbInitialized()) {
  23. await sqlInit.dbReady;
  24. await windowService.createMainWindow();
  25. }
  26. else {
  27. await windowService.createSetupWindow();
  28. }
  29. await windowService.registerGlobalShortcuts();
  30. });
  31. app.on('will-quit', () => {
  32. globalShortcut.unregisterAll();
  33. });
  34. // this is to disable electron warning spam in the dev console (local development only)
  35. process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
  36. require('./src/www');