main.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const { app, BrowserWindow } = require('electron');
  2. const path = require('path');
  3. const url = require('url');
  4. // 创建窗口
  5. const createWindow = () => {
  6. const win = new BrowserWindow({
  7. width: 1200,
  8. height: 800,
  9. autoHideMenuBar: true, // 隐藏菜单栏
  10. webPreferences: {
  11. nodeIntegration: true, // 是否集成 Node.js
  12. enableRemoteModule: true, // 是否启用 remote 模块
  13. webSecurity: false, // 是否禁用同源策略
  14. },
  15. });
  16. win.loadURL(
  17. url.format({
  18. pathname: path.join(__dirname, './dist', 'index.html'),
  19. protocol: 'file:',
  20. slashes: true, // true: file://, false: file:
  21. hash: '/login',
  22. }),
  23. );
  24. };
  25. // 当 Electron 完成初始化并准备创建浏览器窗口时调用此方法
  26. app.whenReady().then(() => {
  27. createWindow();
  28. app.on('activate', () => {
  29. if (BrowserWindow.getAllWindows().length === 0) {
  30. createWindow();
  31. }
  32. });
  33. });
  34. // 当所有窗口都已关闭时退出
  35. app.on('window-all-closed', () => {
  36. if (process.platform !== 'darwin') {
  37. app.quit();
  38. }
  39. });
  40. app.on('activate', () => {
  41. if (BrowserWindow.getAllWindows().length === 0) {
  42. createWindow();
  43. }
  44. });