98 lines
2.2 KiB
JavaScript
98 lines
2.2 KiB
JavaScript
const { app, BrowserWindow , ipcMain, Menu } = require('electron')
|
|
const path = require('path')
|
|
|
|
var mainWindow = null
|
|
|
|
var pageConfig = [
|
|
{
|
|
title: "登录",
|
|
path: "./login.html",
|
|
config: {
|
|
width: 300,
|
|
height: 420,
|
|
resizable: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
nodeIntegrationInWorker: true,
|
|
contextIsolation: false
|
|
}
|
|
}
|
|
|
|
},
|
|
{
|
|
title: "首页",
|
|
path: "./index.html",
|
|
config: {
|
|
width: 800,
|
|
height: 600,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
nodeIntegrationInWorker: true,
|
|
contextIsolation: false
|
|
}
|
|
}
|
|
}
|
|
]
|
|
var pageIndex = 0
|
|
|
|
//创建窗口
|
|
const createWindow = () => {
|
|
mainWindow = new BrowserWindow(pageConfig[pageIndex].config)
|
|
|
|
// 加载 index.html
|
|
mainWindow.loadFile(pageConfig[pageIndex].path)
|
|
|
|
// 打开开发工具
|
|
// mainWindow.webContents.openDevTools()
|
|
}
|
|
|
|
//接收前端穿过来的参数1 把1赋值给下标然后关闭登录窗口 创建聊天窗口
|
|
ipcMain.on("openIndex", (event, arg) => {
|
|
console.log("主进程收到的消息:", arg);
|
|
pageIndex = arg;
|
|
mainWindow.close();
|
|
createWindow()
|
|
})
|
|
ipcMain.on("startShake", (event, arg) => {
|
|
var position = mainWindow.getPosition();
|
|
var newPosition = [
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30,position[0] + 60,
|
|
position[0] - 30
|
|
]
|
|
|
|
for (let i = 0; i < newPosition.length; i++) {
|
|
setTimeout(() => {
|
|
mainWindow.setPosition(
|
|
newPosition[i],
|
|
position[1]
|
|
)
|
|
}, 30 * i)
|
|
}
|
|
|
|
|
|
newPosition.forEach((v, i) => {
|
|
mainWindow.setPosition(
|
|
v,
|
|
position[1]
|
|
)
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow()
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit()
|
|
}) |