| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | const { app, BrowserWindow, shell } = require('electron');const path = require('path');const url = require('url');let win = null;// 创建窗口const createWindow = () => {  win = new BrowserWindow({    // width: 1200,    // height: 800,    show: false, // 是否显示窗口    autoHideMenuBar: true, // 隐藏菜单栏    webPreferences: {      nodeIntegration: true, // 是否集成 Node.js      // enableRemoteModule: true, // 是否启用 remote 模块      webSecurity: false, // 是否禁用同源策略      preload: path.join(__dirname, 'preload.js'), // 预加载脚本    },  });  win.loadURL(    url.format({      pathname: path.join(__dirname, './dist', 'index.html'),      protocol: 'file:',      slashes: true, // true: file://, false: file:      hash: '/login', // /image_change 图片切换页    }),  );  win.once('ready-to-show', () => {    win.maximize();    win.show();  });  // 拦截当前窗口的导航,防止外部链接在应用内打开  win.webContents.on('will-navigate', (event, url) => {    if (url.startsWith('http://') || url.startsWith('https://')) {      event.preventDefault();      shell.openExternal(url);    }  });};// 当 Electron 完成初始化并准备创建浏览器窗口时调用此方法app.whenReady().then(() => {  createWindow();  app.on('activate', () => {    if (BrowserWindow.getAllWindows().length === 0) {      createWindow();    }  });});// 当所有窗口都已关闭时退出app.on('window-all-closed', () => {  if (process.platform !== 'darwin') {    app.quit();  }});app.on('activate', () => {  if (BrowserWindow.getAllWindows().length === 0) {    createWindow();  }});
 |