1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { app, BrowserWindow, ipcMain } from 'electron';
- import { exec } from 'child_process';
- import path from 'path';
- import { fileURLToPath } from 'url';
- const __filename = fileURLToPath(import.meta.url);
- const __dirname = path.dirname(__filename);
- function createWindow() {
- const win = new BrowserWindow({
- width: 800,
- height: 600,
- webPreferences: {
- preload: path.join(__dirname, 'preload.js'), // 确保路径正确
- contextIsolation: true,
- enableRemoteModule: false,
- nodeIntegration: false,
- }
- });
- win.webContents.openDevTools(); // 打开开发者工具进行调试
- win.loadURL('http://localhost:5173'); // 假设你的Vite开发服务器在3000端口运行
- console.log('Window created and URL loaded');
- }
- app.whenReady().then(createWindow);
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit();
- }
- });
- app.on('activate', () => {
- if (BrowserWindow.getAllWindows().length === 0) {
- createWindow();
- }
- });
- ipcMain.on('open-notepad', (event, arg) => {
- console.log('Received open-notepad event');
- exec('notepad.exe', (error, stdout, stderr) => {
- if (error) {
- console.error(`exec error: ${error}`);
- return;
- }
- console.log(`stdout: ${stdout}`);
- console.error(`stderr: ${stderr}`);
- });
- });
|