electron.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // 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 (sqlInit.isDbInitialized()) {
  24. await sqlInit.dbReady;
  25. await windowService.createMainWindow(app);
  26. if (process.platform === 'darwin') {
  27. app.on('activate', async () => {
  28. if (BrowserWindow.getAllWindows().length === 0) {
  29. await windowService.createMainWindow(app);
  30. }
  31. });
  32. }
  33. tray.createTray();
  34. }
  35. else {
  36. await windowService.createSetupWindow();
  37. }
  38. await windowService.registerGlobalShortcuts();
  39. });
  40. app.on('will-quit', () => {
  41. globalShortcut.unregisterAll();
  42. });
  43. // this is to disable electron warning spam in the dev console (local development only)
  44. process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
  45. require('./src/www');