没有任何信息的电子死亡,现在该怎么办? [英] Electron dying without any information, what now?

查看:101
本文介绍了没有任何信息的电子死亡,现在该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建的应用程序,当我编译它以使用电子生成器打包打包分发时,有时会死掉,显示空白屏幕和断开的devtools:

The app I'm building, when I compile it for distribution packing it with electron-builder, every now and then, dies, showing a blank screen and a disconnected devtools:

有什么想法吗?如何开始弄清楚这里发生了什么?

Any ideas what's going on or how to start figuring out what's happening here?

推荐答案

监听 uncaughtException 事件,并记录所有错误。这将使您深入了解正在发生的事情。然后在必要时执行任何清理,并在需要时重新启动该应用程序。如果打算长时间运行,则可以让您的应用从崩溃中恢复。

Listen for the uncaughtException event and log any error that you get. This will give you insight into what is happening. Then perform any cleanup if necessary and relaunch the app if desired. This allows your app to "recover" from crashes if it is intended to be long-running.

//handle crashes and kill events
process.on('uncaughtException', function(err) {
  //log the message and stack trace
  fs.writeFileSync('crash.log', err + "\n" + err.stack);

  //do any cleanup like shutting down servers, etc

  //relaunch the app (if you want)
  app.relaunch({args: []});
  app.exit(0);
});

您还可以收听 SIGTERM 事件查看您的应用程序是否已被杀死,并正常关闭服务器,重新启动等。

You can also listen to the SIGTERM event to see if your application is being killed off, and also gracefully shutdown servers, restart, etc.

process.on('SIGTERM', function() {
  fs.writeFileSync('shutdown.log', "Received SIGTERM signal");

  //do any cleanup like shutting down servers, etc

  //relaunch the app (if you want)
  app.relaunch({args: []});
  app.exit(0);
});

这篇关于没有任何信息的电子死亡,现在该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆