46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const { app, BrowserWindow, ipcMain } = require('electron')
|
||
const { argon2Test } = require('./service/argon2.js')
|
||
|
||
function createWindow () {
|
||
// 创建浏览器窗口
|
||
const win = new BrowserWindow({
|
||
width: 800,
|
||
height: 600,
|
||
webPreferences: {
|
||
nodeIntegration: true,
|
||
contextIsolation: false,
|
||
}
|
||
})
|
||
|
||
// 加载index.html文件
|
||
win.loadFile('index.html')
|
||
|
||
// 打开开发者工具
|
||
// win.webContents.openDevTools()
|
||
}
|
||
|
||
// 注册IPC接口处理程序
|
||
ipcMain.handle('argon2-test', async (event, inputString) => {
|
||
// 调用argon2Test方法处理输入字符串
|
||
return await argon2Test(inputString);
|
||
});
|
||
|
||
// 当Electron完成初始化并准备创建浏览器窗口时调用此方法
|
||
app.whenReady().then(() => {
|
||
createWindow()
|
||
|
||
// macOS中点击Dock图标并且没有其他窗口打开时,重新创建一个窗口
|
||
app.on('activate', () => {
|
||
if (BrowserWindow.getAllWindows().length === 0) {
|
||
createWindow()
|
||
}
|
||
})
|
||
})
|
||
|
||
// 当所有窗口关闭时退出应用
|
||
app.on('window-all-closed', () => {
|
||
// 在macOS上,除非用户用Cmd + Q确定退出,否则绝大部分应用及其菜单栏会保持激活
|
||
if (process.platform !== 'darwin') {
|
||
app.quit()
|
||
}
|
||
}) |