main.js 1.3 KB

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