background.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict'
  2. import { app, protocol, BrowserWindow } from 'electron'
  3. import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
  4. import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'
  5. const isDevelopment = process.env.NODE_ENV !== 'production'
  6. // Scheme must be registered before the app is ready
  7. protocol.registerSchemesAsPrivileged([
  8. { scheme: 'app', privileges: { secure: true, standard: true } }
  9. ])
  10. async function createWindow() {
  11. // Create the browser window.
  12. const win = new BrowserWindow({
  13. width: 800,
  14. height: 600,
  15. frame:false,
  16. fullscreen:true,
  17. webPreferences: {
  18. // Use pluginOptions.nodeIntegration, leave this alone
  19. // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
  20. nodeIntegration: true,
  21. contextIsolation: false,
  22. enableRemoteModule: true
  23. }
  24. })
  25. if (process.env.WEBPACK_DEV_SERVER_URL) {
  26. // Load the url of the dev server if in development mode
  27. await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
  28. if (!process.env.IS_TEST) win.webContents.openDevTools()
  29. } else {
  30. createProtocol('app')
  31. // Load the index.html when not in development
  32. win.loadURL('app://./index.html')
  33. }
  34. }
  35. // Quit when all windows are closed.
  36. app.on('window-all-closed', () => {
  37. // On macOS it is common for applications and their menu bar
  38. // to stay active until the user quits explicitly with Cmd + Q
  39. if (process.platform !== 'darwin') {
  40. app.quit()
  41. }
  42. })
  43. app.on('activate', () => {
  44. // On macOS it's common to re-create a window in the app when the
  45. // dock icon is clicked and there are no other windows open.
  46. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  47. })
  48. // This method will be called when Electron has finished
  49. // initialization and is ready to create browser windows.
  50. // Some APIs can only be used after this event occurs.
  51. app.on('ready', async () => {
  52. if (isDevelopment && !process.env.IS_TEST) {
  53. // Install Vue Devtools
  54. try {
  55. await installExtension(VUEJS_DEVTOOLS)
  56. } catch (e) {
  57. console.error('Vue Devtools failed to install:', e.toString())
  58. }
  59. }
  60. createWindow()
  61. })
  62. // Exit cleanly on request from parent process in development mode.
  63. if (isDevelopment) {
  64. if (process.platform === 'win32') {
  65. process.on('message', (data) => {
  66. if (data === 'graceful-exit') {
  67. app.quit()
  68. }
  69. })
  70. } else {
  71. process.on('SIGTERM', () => {
  72. app.quit()
  73. })
  74. }
  75. }