added setting to restart on SIGSEGV
This commit is contained in:
+41
-7
@@ -4,11 +4,14 @@
|
||||
#include <QFile>
|
||||
#include <QPalette>
|
||||
#include <QStyleFactory>
|
||||
#include <Qt>
|
||||
#include <csignal>
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/NetworkManager.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Updates.hpp"
|
||||
#include "util/CombinePath.hpp"
|
||||
#include "widgets/dialogs/LastRunCrashDialog.hpp"
|
||||
@@ -21,12 +24,6 @@
|
||||
# include <QBreakpadHandler.h>
|
||||
#endif
|
||||
|
||||
// void initQt();
|
||||
// void installCustomPalette();
|
||||
// void showLastCrashDialog();
|
||||
// void createRunningFile(const QString &path);
|
||||
// void removeRunningFile(const QString &path);
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
void installCustomPalette()
|
||||
@@ -109,13 +106,50 @@ namespace {
|
||||
{
|
||||
QFile::remove(path);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point signalsInitTime;
|
||||
bool restartOnSignal = false;
|
||||
|
||||
[[noreturn]] void handleSignal(int signum)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// if (std::chrono::steady_clock::now() - signalsInitTime > 30s)
|
||||
// {
|
||||
QProcess proc;
|
||||
proc.setProgram(QApplication::applicationFilePath());
|
||||
proc.setArguments({"--crash-recovery"});
|
||||
proc.startDetached();
|
||||
|
||||
// QProcess::startDetached(QApplication::applicationFilePath(),
|
||||
// {"--crash-recovery"});
|
||||
// }
|
||||
|
||||
_exit(signum);
|
||||
}
|
||||
|
||||
// We want to restart chatterino when it crashes and the setting is set to
|
||||
// true.
|
||||
void initSignalHandler()
|
||||
{
|
||||
//#if not defined(DEBUG) && not defined(_DEBUG) && not defined(NDEBUG)
|
||||
signalsInitTime = std::chrono::steady_clock::now();
|
||||
|
||||
// signal(SIGINT, handleSignal);
|
||||
signal(SIGSEGV, handleSignal);
|
||||
// signal(SIGABRT_COMPAT, handleSignal);
|
||||
//#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void runGui(QApplication &a, Paths &paths, Settings &settings)
|
||||
{
|
||||
initQt();
|
||||
|
||||
initResources();
|
||||
initSignalHandler();
|
||||
|
||||
settings.restartOnCrash.connect(
|
||||
[](const bool &value) { restartOnSignal = value; });
|
||||
|
||||
auto thread = std::thread([dir = paths.miscDirectory] {
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user