electron11/background/main.js
2025-08-25 23:42:31 +08:00

46 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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()
}
})