main.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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: 900,
  27. frame: false,
  28. center: true,
  29. icon: path.join(__dirname, './icons/icon.png'),
  30. resizable: false,
  31. fullscreen: app.isPackaged ? true : false,
  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. // mainWin.loadURL('http://192.168.10.177:81')
  62. } else {
  63. installDevTool(VUEJS_DEVTOOLS)
  64. process.env.WEB_DEV_INDEX_URL && mainWin.loadURL(process.env.WEB_DEV_INDEX_URL)
  65. }
  66. }
  67. app.on('window-all-closed', () => {
  68. if (process.platform !== 'darwin') app.quit()
  69. })
  70. app.whenReady().then(createWindow)