main.js
var electron = require("electron");
var app = electron.app; //引用app
var BrowserWindow = electron.BrowserWindow; //窗口引用
var mainWindow = null; //声明要打开的主窗口
app.on("ready", () => {
mainWindow = new BrowserWindow({
width: 800,
height: 800,
webPreferences: { nodeIntegration: true,contextIsolation:false,enableRemoteModule: true, },
});
require('@electron/remote/main').initialize()
require('@electron/remote/main').enable(mainWindow.webContents)
require('./main/menu.js')
mainWindow.loadFile("demo.html"); //加载html页面
mainWindow.on("closed", () => {
mainWindow = null;
});
});
menu.js
const {BrowserWindow} = require('electron')
const {Menu} = require('electron')
var template = [
{
label: '凤来怡洗浴会所',
submenu:[
{
label: '精品SPA',
click: () => {
var win = new BrowserWindow({
width: 500,
height: 500,
webPreferences: {nodeIntegration: true,contextIsolation:false,enableRemoteModule: true,}
})
win.loadFile('yellow.html')
win.on('close', () => {
win = null
})
}
},
{label:'泰式按摩'}
]
},
{
label: '大浪淘沙洗浴中心',
submenu:[
{label: '牛奶玫瑰瑜'},
{label:'爱情拍拍收'}
]
}
]
var m = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(m)