Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add crash recovery on Windows #5012

Merged
merged 28 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Checks: "-*,
-readability-function-cognitive-complexity,
-bugprone-easily-swappable-parameters,
-cert-err58-cpp,
-modernize-avoid-c-arrays
"
CheckOptions:
- key: readability-identifier-naming.ClassCase
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ jobs:
run: |
cd build
set cl=/MP
nmake /S /NOLOGO crashpad_handler
nmake /S /NOLOGO chatterino-crash-handler
mkdir Chatterino2/crashpad
cp bin/crashpad/crashpad_handler.exe Chatterino2/crashpad/crashpad_handler.exe
cp bin/crashpad/crashpad-handler.exe Chatterino2/crashpad/crashpad-handler.exe
7z a bin/chatterino-Qt-${{ matrix.qt-version }}.pdb.7z bin/chatterino.pdb

- name: Prepare build dir (windows)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
build_dir: build-clang-tidy
config_file: ".clang-tidy"
split_workflow: true
exclude: "lib/*"
exclude: "lib/*,tools/crash-handler/*"
cmake_command: >-
cmake -S. -Bbuild-clang-tidy
-DCMAKE_BUILD_TYPE=Release
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
[submodule "lib/lua/src"]
path = lib/lua/src
url = https://github.com/lua/lua
[submodule "lib/crashpad"]
path = lib/crashpad
url = https://github.com/getsentry/crashpad
[submodule "tools/crash-handler"]
path = tools/crash-handler
url = https://github.com/Chatterino/crash-handler
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Minor: Add `--safe-mode` command line option that can be used for troubleshooting when Chatterino is misbehaving or is misconfigured. It disables hiding the settings button & prevents plugins from loading. (#4985)
- Minor: Updated the flatpakref link included with nightly builds to point to up-to-date flathub-beta builds. (#5008)
- Minor: Add a new completion API for experimental plugins feature. (#5000)
- Minor: Re-enabled _Restart on crash_ option on Windows. (#5012)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
- Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ if (CHATTERINO_PLUGINS)
endif()

if (BUILD_WITH_CRASHPAD)
add_subdirectory("${CMAKE_SOURCE_DIR}/lib/crashpad" EXCLUDE_FROM_ALL)
add_subdirectory("${CMAKE_SOURCE_DIR}/tools/crash-handler")
endif()

# Used to provide a date of build in the About page (for nightly builds). Getting the actual time of
Expand Down
1 change: 0 additions & 1 deletion lib/crashpad
Submodule crashpad deleted from 89991e
5 changes: 5 additions & 0 deletions mocks/include/mocks/EmptyApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class EmptyApplication : public IApplication
return nullptr;
}

CrashHandler *getCrashHandler() override
{
return nullptr;
}

CommandController *getCommands() override
{
return nullptr;
Expand Down
7 changes: 6 additions & 1 deletion src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
#include "singletons/CrashHandler.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/helper/LoggingChannel.hpp"
Expand Down Expand Up @@ -113,6 +114,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, toasts(&this->emplace<Toasts>())
, imageUploader(&this->emplace<ImageUploader>())
, seventvAPI(&this->emplace<SeventvAPI>())
, crashHandler(&this->emplace<CrashHandler>())

, commands(&this->emplace<CommandController>())
, notifications(&this->emplace<NotificationController>())
Expand Down Expand Up @@ -174,7 +176,9 @@ void Application::initialize(Settings &settings, Paths &paths)
singleton->initialize(settings, paths);
}

// add crash message
// Show crash message.
// On Windows, the crash message was already shown.
#ifndef Q_OS_WIN
if (!getArgs().isFramelessEmbed && getArgs().crashRecovery)
{
if (auto selected =
Expand All @@ -195,6 +199,7 @@ void Application::initialize(Settings &settings, Paths &paths)
}
}
}
#endif

this->windows->updateWordTypeMask();

Expand Down
7 changes: 7 additions & 0 deletions src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FfzBadges;
class SeventvBadges;
class ImageUploader;
class SeventvAPI;
class CrashHandler;

class IApplication
{
Expand All @@ -60,6 +61,7 @@ class IApplication
virtual HotkeyController *getHotkeys() = 0;
virtual WindowManager *getWindows() = 0;
virtual Toasts *getToasts() = 0;
virtual CrashHandler *getCrashHandler() = 0;
virtual CommandController *getCommands() = 0;
virtual HighlightController *getHighlights() = 0;
virtual NotificationController *getNotifications() = 0;
Expand Down Expand Up @@ -102,6 +104,7 @@ class Application : public IApplication
Toasts *const toasts{};
ImageUploader *const imageUploader{};
SeventvAPI *const seventvAPI{};
CrashHandler *const crashHandler{};

CommandController *const commands{};
NotificationController *const notifications{};
Expand Down Expand Up @@ -148,6 +151,10 @@ class Application : public IApplication
{
return this->toasts;
}
CrashHandler *getCrashHandler() override
{
return this->crashHandler;
}
CommandController *getCommands() override
{
return this->commands;
Expand Down
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ set(SOURCE_FILES
messages/search/SubtierPredicate.cpp
messages/search/SubtierPredicate.hpp

providers/Crashpad.cpp
providers/Crashpad.hpp
providers/IvrApi.cpp
providers/IvrApi.hpp
providers/LinkResolver.cpp
Expand Down Expand Up @@ -425,6 +423,8 @@ set(SOURCE_FILES

singletons/Badges.cpp
singletons/Badges.hpp
singletons/CrashHandler.cpp
singletons/CrashHandler.hpp
singletons/Emotes.cpp
singletons/Emotes.hpp
singletons/Fonts.cpp
Expand Down Expand Up @@ -1007,7 +1007,6 @@ endif ()
if (BUILD_WITH_CRASHPAD)
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO_WITH_CRASHPAD)
target_link_libraries(${LIBRARY_PROJECT} PUBLIC crashpad::client)
set_target_directory_hierarchy(crashpad_handler crashpad)
endif()

# Configure compiler warnings
Expand Down
53 changes: 13 additions & 40 deletions src/RunGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand Down Expand Up @@ -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] {
{
Expand Down Expand Up @@ -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();
Expand Down
Loading
Loading