ITEyes/index.js
高峰君主 8140d0fdfa 上传文件至 /
来自宫瑞骏的提交
2024-10-20 20:22:18 +08:00

47 lines
1.1 KiB
JavaScript

const { app, BrowserWindow } = require('electron');
const { spawn } = require('child_process');
const path = require('path');
const flaskProcess = spawn('python', [path.join(__dirname, 'app.py')]);
flaskProcess.stdout.on('data', (data) => {
console.log(`Flask: ${data}`);
});
// 监听Node.js进程的关闭事件
process.on('SIGINT', () => {
console.log('Closing Node.js application and Python script...');
// 杀掉Python进程
pythonProcess.kill('SIGINT');
// 完全退出Node.js应用
process.exit();
});
let mainWindow;
app.whenReady().then(() => {
mainWindow = new BrowserWindow({
width: 430,
height: 680,
icon: path.join(__dirname, 'assets', 'icon.ico'),
webPreferences: {
nodeIntegration: false, // 禁用 Node 集成
contextIsolation: true, // 启用上下文隔离
},
});
// 加载 HTTP 服务的 URL
mainWindow.loadURL('http://127.0.0.1:5000/');
mainWindow.on('closed', () => {
mainWindow = null;
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});