main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. 'use strict';
  6. const config = require('./config');
  7. const app = require('app'); // Module to control application life.
  8. const BrowserWindow = require('browser-window'); // Module to create native browser window.
  9. const http = require('http');
  10. //app.__is_debug = true;
  11. app.__is_debug = false;
  12. // Report crashes to our server.
  13. require('crash-reporter').start();
  14. // Keep a global reference of the window object, if you don't, the window will
  15. // be closed automatically when the javascript object is GCed.
  16. let mainWindow = null;
  17. // Quit when all windows are closed.
  18. app.on('window-all-closed', function () {
  19. if (process.platform != 'darwin') {
  20. app.quit();
  21. }
  22. });
  23. // This method will be called when atom-shell has done everything
  24. // initialization and ready for creating browser windows.
  25. app.on('ready', function () {
  26. // Create the browser window.
  27. mainWindow = new BrowserWindow({width: 800, height: 600});
  28. // and load the index.html of the app.
  29. mainWindow.loadURL('file://' + __dirname + '/index.html');
  30. //app.dock.hide();
  31. if (app.__is_debug) {
  32. mainWindow.toggleDevTools();
  33. }
  34. mainWindow.on('close', function (e) {
  35. console.log('close');
  36. if (!app.__force_quit) {
  37. e.preventDefault();
  38. mainWindow.hide();
  39. }
  40. });
  41. // You can use 'before-quit' instead of (or with) the close event
  42. app.on('before-quit', function (e) {
  43. console.log('before-quit');
  44. // Handle menu-item or keyboard shortcut quit here
  45. app.__force_quit = true;
  46. });
  47. // Remove mainWindow.on('closed'), as it is redundant
  48. /*
  49. // Emitted when the window is closed.
  50. mainWindow.on('closed', function () {
  51. // Dereference the window object, usually you would store windows
  52. // in an array if your app supports multi windows, this is the time
  53. // when you should delete the corresponding element.
  54. mainWindow = null;
  55. app.quit();
  56. });*/
  57. app.on('activate', function () {
  58. mainWindow.show();
  59. });
  60. require('./js/menu').makeMenu(app, mainWindow);
  61. require('./js/tray').makeTray(app);
  62. });