main.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * @Author: Gtylcara.
  3. * @Date: 2021-03-26 23:23:14
  4. * @LastEditors: Gtylcara.
  5. * @LastEditTime: 2021-03-27 00:01:04
  6. */
  7. // Modules to control application life and create native browser window
  8. const {app, BrowserWindow} = require('electron')
  9. const path = require('path')
  10. function createWindow () {
  11. // Create the browser window.
  12. const mainWindow = new BrowserWindow({
  13. width: 800,
  14. height: 600,
  15. webPreferences: {
  16. preload: path.join(__dirname, 'preload.js')
  17. }
  18. })
  19. // and load the index.html of the app.
  20. mainWindow.loadFile('index.html')
  21. }
  22. // This method will be called when Electron has finished
  23. // initialization and is ready to create browser windows.
  24. // Some APIs can only be used after this event occurs.
  25. app.whenReady().then(() => {
  26. createWindow()
  27. app.on('activate', function () {
  28. // On macOS it's common to re-create a window in the app when the
  29. // dock icon is clicked and there are no other windows open.
  30. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  31. })
  32. })
  33. // Quit when all windows are closed, except on macOS. There, it's common
  34. // for applications and their menu bar to stay active until the user quits
  35. // explicitly with Cmd + Q.
  36. app.on('window-all-closed', function () {
  37. if (process.platform !== 'darwin') app.quit()
  38. })
  39. // In this file you can include the rest of your app's specific main process
  40. // code. You can also put them in separate files and require them here.