main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow, globalShortcut, dialog } = require('electron')
  3. // Keep a global reference of the window object, if you don't, the window will
  4. // be closed automatically when the JavaScript object is garbage collected.
  5. let mainWindow
  6. function createWindow () {
  7. // Create the browser window.
  8. mainWindow = new BrowserWindow({
  9. width: 800,
  10. height: 600,
  11. webPreferences: {
  12. nodeIntegration: true
  13. }
  14. })
  15. globalShortcut.register('CommandOrControl+Alt+K', () => {
  16. dialog.showMessageBox({
  17. type: 'info',
  18. message: 'Success!',
  19. detail: 'You pressed the registered global shortcut keybinding.',
  20. buttons: ['OK']
  21. })
  22. })
  23. // and load the index.html of the app.
  24. mainWindow.loadFile('index.html')
  25. // Open the DevTools.
  26. // mainWindow.webContents.openDevTools()
  27. // Emitted when the window is closed.
  28. mainWindow.on('closed', function () {
  29. // Dereference the window object, usually you would store windows
  30. // in an array if your app supports multi windows, this is the time
  31. // when you should delete the corresponding element.
  32. mainWindow = null
  33. })
  34. }
  35. // This method will be called when Electron has finished
  36. // initialization and is ready to create browser windows.
  37. // Some APIs can only be used after this event occurs.
  38. app.on('ready', createWindow)
  39. // Quit when all windows are closed.
  40. app.on('window-all-closed', function () {
  41. // On OS X it is common for applications and their menu bar
  42. // to stay active until the user quits explicitly with Cmd + Q
  43. if (process.platform !== 'darwin') {
  44. app.quit()
  45. }
  46. })
  47. app.on('activate', function () {
  48. // On OS X it's common to re-create a window in the app when the
  49. // dock icon is clicked and there are no other windows open.
  50. if (mainWindow === null) {
  51. createWindow()
  52. }
  53. })
  54. app.on('will-quit', function () {
  55. globalShortcut.unregisterAll()
  56. })
  57. // In this file you can include the rest of your app's specific main process
  58. // code. You can also put them in separate files and require them here.