main.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { app, BrowserWindow, Menu } = require('electron');
  2. const path = require('path');
  3. function createWindow() {
  4. const isMac = process.platform === 'darwin';
  5. const win = new BrowserWindow({
  6. show: false, // 先隐藏,避免白屏
  7. frame: !isMac, // 非 macOS 无边框
  8. titleBarStyle: isMac ? 'hiddenInset' : 'default', // macOS 隐藏标题栏但保留控制按钮
  9. webPreferences: {
  10. nodeIntegration: true,
  11. contextIsolation: false,
  12. },
  13. });
  14. // 去掉应用菜单栏
  15. Menu.setApplicationMenu(null);
  16. if (!isMac) win.removeMenu(); // Windows / Linux 额外保险
  17. // 启动即最大化
  18. win.maximize();
  19. // 加载 Taro 编译后的 H5 页面
  20. win.loadFile(path.join(__dirname, './dist/h5/index.html'));
  21. // 页面准备好再显示,防止视觉闪烁
  22. win.once('ready-to-show', () => win.show());
  23. }
  24. app.whenReady().then(createWindow);
  25. app.on('window-all-closed', () => {
  26. if (process.platform !== 'darwin') app.quit();
  27. });
  28. app.on('activate', () => {
  29. if (BrowserWindow.getAllWindows().length === 0) createWindow();
  30. });