feat: Add crash recovery on Windows (#5012)
This commit is contained in:
+13
-40
@@ -5,6 +5,7 @@
|
||||
#include "common/Modes.hpp"
|
||||
#include "common/NetworkManager.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "singletons/CrashHandler.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
@@ -99,21 +100,10 @@ namespace {
|
||||
|
||||
void showLastCrashDialog()
|
||||
{
|
||||
//#ifndef C_DISABLE_CRASH_DIALOG
|
||||
// LastRunCrashDialog dialog;
|
||||
|
||||
// switch (dialog.exec())
|
||||
// {
|
||||
// case QDialog::Accepted:
|
||||
// {
|
||||
// };
|
||||
// break;
|
||||
// default:
|
||||
// {
|
||||
// _exit(0);
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
auto *dialog = new LastRunCrashDialog;
|
||||
// Use exec() over open() to block the app from being loaded
|
||||
// and to be able to set the safe mode.
|
||||
dialog->exec();
|
||||
}
|
||||
|
||||
void createRunningFile(const QString &path)
|
||||
@@ -131,14 +121,13 @@ namespace {
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point signalsInitTime;
|
||||
bool restartOnSignal = false;
|
||||
|
||||
[[noreturn]] void handleSignal(int signum)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
if (restartOnSignal &&
|
||||
std::chrono::steady_clock::now() - signalsInitTime > 30s)
|
||||
if (std::chrono::steady_clock::now() - signalsInitTime > 30s &&
|
||||
getIApp()->getCrashHandler()->shouldRecover())
|
||||
{
|
||||
QProcess proc;
|
||||
|
||||
@@ -240,9 +229,12 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
|
||||
initResources();
|
||||
initSignalHandler();
|
||||
|
||||
settings.restartOnCrash.connect([](const bool &value) {
|
||||
restartOnSignal = value;
|
||||
});
|
||||
#ifdef Q_OS_WIN
|
||||
if (getArgs().crashRecovery)
|
||||
{
|
||||
showLastCrashDialog();
|
||||
}
|
||||
#endif
|
||||
|
||||
auto thread = std::thread([dir = paths.miscDirectory] {
|
||||
{
|
||||
@@ -279,30 +271,11 @@ void runGui(QApplication &a, Paths &paths, Settings &settings)
|
||||
chatterino::NetworkManager::init();
|
||||
chatterino::Updates::instance().checkForUpdates();
|
||||
|
||||
#ifdef C_USE_BREAKPAD
|
||||
QBreakpadInstance.setDumpPath(getPaths()->settingsFolderPath + "/Crashes");
|
||||
#endif
|
||||
|
||||
// Running file
|
||||
auto runningPath =
|
||||
paths.miscDirectory + "/running_" + paths.applicationFilePathHash;
|
||||
|
||||
if (QFile::exists(runningPath))
|
||||
{
|
||||
showLastCrashDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
createRunningFile(runningPath);
|
||||
}
|
||||
|
||||
Application app(settings, paths);
|
||||
app.initialize(settings, paths);
|
||||
app.run(a);
|
||||
app.save();
|
||||
|
||||
removeRunningFile(runningPath);
|
||||
|
||||
if (!getArgs().dontSaveSettings)
|
||||
{
|
||||
pajlada::Settings::SettingManager::gSave();
|
||||
|
||||
Reference in New Issue
Block a user