main.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { app, BrowserWindow } from 'electron'
  2. import { resolve } from 'path'
  3. import installDevTool, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
  4. import path from 'path'
  5. if (!app.requestSingleInstanceLock()) {
  6. app.quit()
  7. process.exit(0)
  8. }
  9. async function createWindow() {
  10. const loadingView = new BrowserWindow({
  11. width: 520,
  12. height: 150,
  13. frame: false,
  14. icon: path.join(__dirname, './icons/icon.png'),
  15. resizable: false,
  16. transparent: true,
  17. show: true,
  18. webPreferences: {
  19. preload: path.join(__dirname, '../preload/preload'),
  20. },
  21. })
  22. loadingView.loadFile(resolve(__dirname, 'loading.html'))
  23. const mainWin = new BrowserWindow({
  24. show: false,
  25. width: 1680,
  26. height: 880,
  27. frame: false,
  28. center: true,
  29. icon: path.join(__dirname, './icons/icon.png'),
  30. resizable: false,
  31. fullscreen: true,
  32. fullscreenable: true,
  33. alwaysOnTop: false,
  34. useContentSize: true,
  35. transparent: true,
  36. webPreferences: {
  37. devTools: true,
  38. nodeIntegration: false,
  39. contextIsolation: true,
  40. webSecurity: false,
  41. experimentalFeatures: true,
  42. navigateOnDragDrop: false,
  43. disableHtmlFullscreenWindowResize: false,
  44. preload: path.join(__dirname, '../preload/preload'),
  45. },
  46. })
  47. mainWin.setMenu(null)
  48. if (!app.isPackaged) {
  49. mainWin.webContents.on('before-input-event', (event, input) => {
  50. if (input.key === 'F12') {
  51. mainWin.webContents.openDevTools()
  52. }
  53. })
  54. }
  55. mainWin.on('ready-to-show', () => {
  56. loadingView.destroy()
  57. mainWin.show()
  58. })
  59. if (app.isPackaged) {
  60. mainWin.loadURL('http://cet-test.markingtool.cn')
  61. } else {
  62. installDevTool(VUEJS_DEVTOOLS)
  63. process.env.WEB_DEV_INDEX_URL && mainWin.loadURL(process.env.WEB_DEV_INDEX_URL)
  64. }
  65. }
  66. app.on('window-all-closed', () => {
  67. if (process.platform !== 'darwin') app.quit()
  68. })
  69. app.whenReady().then(createWindow)