Cloing Electron应用程序未停止脚本

编程入门 行业动态 更新时间:2024-10-08 00:29:35

Cloing Electron<a href=https://www.elefans.com/category/jswz/34/1771452.html style=应用程序未停止脚本"/>

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 startwait-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应用程序未停止脚本

本文发布于:2024-05-07 22:00:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   脚本   Cloing   Electron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!