main.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const electron = require('electron');
  2. const tray = require('./tray');
  3. const app = electron.app;
  4. const BrowserWindow = electron.BrowserWindow;
  5. const mainPage = 'file://' + __dirname + '/public/index.html';
  6. var isQuitting = false;
  7. var mainWindow = null;
  8. app.on('window-all-closed', function() {
  9. if (process.platform != 'darwin') {
  10. app.quit();
  11. }
  12. });
  13. app.on('ready', function() {
  14. mainWindow = new BrowserWindow({
  15. autoHideMenuBar: false,
  16. webPreferences: {
  17. nodeIntegration: false
  18. },
  19. width: 1200,
  20. height: 750,
  21. icon: __dirname + '/resources/app/public/images/preserver_icon.png'
  22. });
  23. mainWindow.loadURL(mainPage);
  24. tray.create(mainWindow);
  25. // mainWindow.openDevTools();
  26. mainWindow.on('closed', function() {
  27. // Dereference the window object, usually you would store windows
  28. // in an array if your app supports multi windows, this is the time
  29. // when you should delete the corresponding element.
  30. mainWindow = null;
  31. });
  32. mainWindow.on('close', e => {
  33. if (!isQuitting) {
  34. e.preventDefault();
  35. if (process.platform === 'darwin') {
  36. app.hide();
  37. } else {
  38. mainWindow.hide();
  39. }
  40. }
  41. });
  42. app.on('before-quit', function() {
  43. isQuitting = true;
  44. });
  45. });