diff --git a/CHANGELOG.md b/CHANGELOG.md index 64950e31..718ed116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Dev: Conan will no longer generate a `CMakeUserPresets.json` file. (#6117) - Dev: Pass `--force-openssl` when installing from CMake in Qt 6.8+. (#6129) - Dev: Fixed ` clean` not working correctly with generated sources. (#6154) +- Dev: Save settings in `aboutToQuit`. (#6159) ## 2.5.3 diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 10a38015..e49412ce 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -280,12 +280,20 @@ void runGui(QApplication &a, const Paths &paths, Settings &settings, chatterino::NetworkManager::init(); updates.checkForUpdates(); + QObject::connect(qApp, &QApplication::aboutToQuit, [] { + auto *app = dynamic_cast(tryGetApp()); + if (app) + { + app->save(); + } + + getSettings()->requestSave(); + getSettings()->disableSave(); + }); + Application app(settings, paths, args, updates); app.initialize(settings, paths); app.run(); - app.save(); - - settings.requestSave(); chatterino::NetworkManager::deinit(); diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index eca8d07d..c2a7a1a8 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -278,6 +278,11 @@ void Settings::restoreSnapshot() } } +void Settings::disableSave() +{ + this->disableSaving = true; +} + float Settings::getClampedUiScale() const { return std::clamp(this->uiScale.getValue(), 0.2F, 10.F); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 49563ba6..712bf2de 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -104,7 +104,7 @@ class Settings static Settings *instance_; Settings *prevInstance_ = nullptr; - const bool disableSaving; + bool disableSaving; public: Settings(const Args &args, const QString &settingsDirectory); @@ -120,6 +120,8 @@ public: void saveSnapshot(); void restoreSnapshot(); + void disableSave(); + FloatSetting uiScale = {"/appearance/uiScale2", 1}; BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false};