main.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { app, BrowserWindow, clipboard } 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. resizable: false,
  15. transparent: true,
  16. show: true,
  17. webPreferences: {
  18. preload: path.join(__dirname, '../preload/preload'),
  19. },
  20. })
  21. loadingView.loadFile(resolve(__dirname, 'loading.html'))
  22. const image = clipboard.readImage()
  23. const mainWin = new BrowserWindow({
  24. title: 'Electron Window',
  25. show: false,
  26. width: 1680,
  27. height: 880,
  28. icon: image,
  29. frame: false,
  30. center: true,
  31. resizable: false,
  32. fullscreen: false,
  33. fullscreenable: true,
  34. alwaysOnTop: false,
  35. useContentSize: true,
  36. transparent: true,
  37. webPreferences: {
  38. devTools: true,
  39. nodeIntegration: false,
  40. contextIsolation: true,
  41. webSecurity: false,
  42. experimentalFeatures: true,
  43. navigateOnDragDrop: false,
  44. disableHtmlFullscreenWindowResize: false,
  45. preload: path.join(__dirname, '../preload/preload'),
  46. },
  47. })
  48. mainWin.setMenu(null)
  49. mainWin.webContents.on('before-input-event', (event, input) => {
  50. if (input.key === 'F12') {
  51. mainWin.webContents.openDevTools()
  52. }
  53. })
  54. mainWin.on('ready-to-show', () => {
  55. loadingView.destroy()
  56. mainWin.show()
  57. })
  58. if (app.isPackaged) {
  59. mainWin.loadFile(resolve(__dirname, '../index.html'))
  60. } else {
  61. installDevTool(VUEJS_DEVTOOLS)
  62. process.env.WEB_DEV_INDEX_URL && mainWin.loadURL(process.env.WEB_DEV_INDEX_URL)
  63. }
  64. }
  65. app.on('window-all-closed', () => {
  66. if (process.platform !== 'darwin') app.quit()
  67. })
  68. app.whenReady().then(createWindow)