应用程序未停止脚本"/>
Cloing Electron应用程序未停止脚本
我有一个问题,希望有人可以帮助我。
我有一个Electron + React桌面应用程序,我需要正确处理其关闭。当我关闭应用程序(单击窗口上的X)时,程序停止,但是,我用来运行程序的终端窗口没有停止。
我使用此脚本运行程序:
npm run electron-dev
确实:
"scripts": {
"start": "react-scripts start",
"electron-dev": "concurrently \"npm run start\" \"wait-on http://localhost:3000 && electron .\""
}
我正常运行我的应用程序,当我关闭窗口时,终端进入:
wait-on http://localhost:3000 && electron . exited with code 0
但是我无法在终端上键入内容,除非我用Control + C终止程序。
这是我处理应用程序关闭的方式:
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('before-quit', () => {
mainWindow.removeAllListeners('close');
mainWindow.close();
});
有人可以帮我吗?
回答如下:这是因为您正在使用concurrently
,这是预期的行为。
[关闭窗口(并退出macOS上的程序)时,电子进程确实停止了,但是您在终端中给出的命令仍在运行,因为您仍在运行react-scripts
。
[查看您的electron-dev
脚本,您说您想运行命令npm start
和wait-on http://localhost:3000 && electron .\
。当您关闭电子应用程序时,它会告诉您该过程已结束(wait-on http://localhost:3000 && electron . exited with code 0
)。但是,您只结束了创建的2个过程中的1个。创建的npm start
进程仍在运行,因此不会将终端控制权还给您。
npm start
执行命令react-scripts start
,该命令设置开发环境并启动服务器。您有a few options for killing the process,而CTRL + C是最简单的。
打包您的应用程序时,不会出现此问题,当用户关闭窗口(或退出macOS上的程序)时,应用程序将干净地关闭
更多推荐
Cloing Electron应用程序未停止脚本
发布评论