47 lines
1.1 KiB
JavaScript
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: 800,
|
|
height: 600,
|
|
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();
|
|
});
|