diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b48b90b..32ff6154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ - Dev: Fixed compilation error in tests with Clang 21. (#6519) - Dev: Use CMake's `FetchContent` for RapidJSON, PajladaSignals, PajladaSerialize, and PajladaSettings. (#6560, #6567, #6569) - Dev: The LuaLS meta files moved from `docs/plugin-meta.lua` to `docs/lua-meta/globals.lua`. (#6530) +- Dev: Be more hesitant about setting saves. (#6620) - Dev: Compile time definitions for `Windows.h` are now conditional based on `WIN32` instead of `MSVC`. (#6534) - Dev: Refactored split container nodes to use shared pointers. (#6435) - Dev: Mock headers are now added as a header set if supported by CMake. (#6561) diff --git a/src/controllers/commands/builtin/chatterino/Debugging.cpp b/src/controllers/commands/builtin/chatterino/Debugging.cpp index 0d7cb8ce..aaa40e06 100644 --- a/src/controllers/commands/builtin/chatterino/Debugging.cpp +++ b/src/controllers/commands/builtin/chatterino/Debugging.cpp @@ -3,7 +3,6 @@ #include "Application.hpp" #include "common/Channel.hpp" #include "common/Env.hpp" -#include "common/Literals.hpp" #include "controllers/commands/CommandContext.hpp" #include "controllers/notifications/NotificationController.hpp" #include "messages/Image.hpp" @@ -13,6 +12,7 @@ #include "providers/twitch/eventsub/Controller.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchIrcServer.hpp" +#include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "singletons/Toasts.hpp" #include "singletons/Updates.hpp" @@ -23,9 +23,9 @@ #include #include -namespace chatterino::commands { +using namespace Qt::StringLiterals; -using namespace literals; +namespace chatterino::commands { QString setLoggingRules(const CommandContext &ctx) { @@ -202,6 +202,23 @@ QString debugTest(const CommandContext &ctx) getApp()->getUpdates().checkForUpdates(); ctx.channel->addSystemMessage(QString("checking for updates")); } + else if (command == "save-settings") + { + ctx.channel->addSystemMessage(u"requesting settings save"_s); + auto res = getSettings()->requestSave(); + switch (res) + { + case pajlada::Settings::SettingManager::SaveResult::Failed: + ctx.channel->addSystemMessage(u"setting save failed"_s); + break; + case pajlada::Settings::SettingManager::SaveResult::Success: + ctx.channel->addSystemMessage(u"setting save success"_s); + break; + case pajlada::Settings::SettingManager::SaveResult::Skipped: + ctx.channel->addSystemMessage(u"setting save skipped"_s); + break; + } + } else { ctx.channel->addSystemMessage( diff --git a/src/controllers/hotkeys/HotkeyController.cpp b/src/controllers/hotkeys/HotkeyController.cpp index c5936396..06a2238a 100644 --- a/src/controllers/hotkeys/HotkeyController.cpp +++ b/src/controllers/hotkeys/HotkeyController.cpp @@ -236,7 +236,8 @@ void HotkeyController::loadHotkeys() auto numCombinedDefaults = set.size(); pajlada::Settings::Setting>::set( - "/hotkeys/addedDefaults", std::vector(set.begin(), set.end())); + "/hotkeys/addedDefaults", std::vector(set.begin(), set.end()), + pajlada::Settings::SettingOption::CompareBeforeSet); qCDebug(chatterinoHotkeys) << "Loading hotkeys..."; for (const auto &key : keys) diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index e052906f..f68e6e39 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -157,8 +157,12 @@ Settings::Settings(const Args &args, const QString &settingsDirectory) settingsInstance->setBackupEnabled(true); settingsInstance->setBackupSlots(9); - settingsInstance->saveMethod = - pajlada::Settings::SettingManager::SaveMethod::SaveManually; + settingsInstance->saveMethod = static_cast< + pajlada::Settings::SettingManager::SaveMethod>( + static_cast( + pajlada::Settings::SettingManager::SaveMethod::SaveManually) | + static_cast( + pajlada::Settings::SettingManager::SaveMethod::OnlySaveIfChanged)); initializeSignalVector(this->signalHolder, this->highlightedMessagesSetting, this->highlightedMessages); @@ -198,14 +202,14 @@ Settings::~Settings() Settings::instance_ = this->prevInstance_; } -void Settings::requestSave() const +pajlada::Settings::SettingManager::SaveResult Settings::requestSave() const { if (this->disableSaving) { - return; + return pajlada::Settings::SettingManager::SaveResult::Skipped; } - pajlada::Settings::SettingManager::gSave(); + return pajlada::Settings::SettingManager::gSave(); } void Settings::saveSnapshot() diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index ea72f2d8..3d1dd121 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -130,7 +131,9 @@ public: /// Request the settings to be saved to file /// /// Depending on the launch options, a save might end up not happening - void requestSave() const; + /// + /// Returns the result from the save, or Skipped if disableSave has been called + pajlada::Settings::SettingManager::SaveResult requestSave() const; void saveSnapshot(); void restoreSnapshot();