97 lines
1.9 KiB
JavaScript
97 lines
1.9 KiB
JavaScript
const { app, BrowserWindow, ipcMain, Menu } = require('electron')
|
|
const path = require('path')
|
|
var mainWindow = null;
|
|
var pageConfig = [
|
|
{
|
|
path: './login.html',
|
|
config: {
|
|
icon: '',
|
|
title: '',
|
|
width: 280,
|
|
height: 450,
|
|
resizable: false,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
nodeIntegrationInWorker: true,
|
|
contextIsolation: false
|
|
}
|
|
}
|
|
},
|
|
{
|
|
|
|
path: './index.html',
|
|
config: {
|
|
icon: '',
|
|
title: '',
|
|
width: 800,
|
|
height: 600,
|
|
webPreferences: {
|
|
nodeIntegration: true,
|
|
nodeIntegrationInWorker: true,
|
|
contextIsolation: false
|
|
}
|
|
}
|
|
}
|
|
]
|
|
|
|
var pageIndex = 0
|
|
|
|
const createWindow = () => {
|
|
mainWindow = new BrowserWindow(pageConfig[pageIndex].config)
|
|
mainWindow.loadFile(pageConfig[pageIndex].path)
|
|
|
|
Menu.setApplicationMenu(null)
|
|
// mainWindow.webContents.openDevTools()
|
|
}
|
|
|
|
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()
|
|
})
|