|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const { app, BrowserWindow, ipcMain } = require('electron');
- const path = require('path');
- const Store = require('electron-store');
- const store = new Store();
-
- // 设置 Playwright 浏览器路径
- if (app.isPackaged) {
- process.env.PLAYWRIGHT_BROWSERS_PATH = path.join(process.resourcesPath, 'ms-playwright');
- } else {
- process.env.PLAYWRIGHT_BROWSERS_PATH = path.join(process.env.LOCALAPPDATA, 'ms-playwright');
- }
-
- let mainWindow;
-
- function createWindow() {
- mainWindow = new BrowserWindow({
- width: 800,
- height: 600,
- webPreferences: {
- nodeIntegration: true,
- contextIsolation: false
- }
- });
-
- mainWindow.loadFile('index.html');
- }
-
- // 处理 IPC 消息
- ipcMain.handle('get-credentials', async () => {
- return store.get('credentials');
- });
-
- ipcMain.handle('save-credentials', async (event, credentials) => {
- store.set('credentials', credentials);
- });
-
- app.whenReady().then(createWindow);
-
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
-
- app.on('activate', () => {
- if (BrowserWindow.getAllWindows().length === 0) {
- createWindow();
- }
- });
|