| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const { app, BrowserWindow, Menu } = require('electron');
- const path = require('path');
- function createWindow() {
- const mainWindow = new BrowserWindow({
- width: 1600,
- height: 900,
- icon: path.join(__dirname, 'favicon.ico'), // 设置窗口图标
- webPreferences: {
- nodeIntegration: false,
- contextIsolation: true
- },
- });
- mainWindow.loadFile('index.html');
- // 创建菜单模板,只包含一个刷新按钮
- const menuTemplate = [
- {
- label: 'View',
- submenu: [
- {
- label: 'Reload',
- accelerator: 'CmdOrCtrl+R',
- click: () => {
- mainWindow.reload();
- },
- },
- ],
- },
- ];
- // 创建菜单
- const menu = Menu.buildFromTemplate(menuTemplate);
- // 设置应用程序的菜单
- Menu.setApplicationMenu(menu);
- }
- app.on('ready', createWindow);
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
- app.on('activate', () => {
- if (BrowserWindow.getAllWindows().length === 0) {
- createWindow();
- }
- });
|