fix: save settings less often (#6620)

Reviewed-by: James Upjohn <jupjohn@jammeh.co.nz>
This commit is contained in:
pajlada
2025-12-11 17:42:23 +01:00
committed by GitHub
parent ccb8ad8ffc
commit 99f2b5b435
5 changed files with 36 additions and 10 deletions
+1
View File
@@ -54,6 +54,7 @@
- Dev: Fixed compilation error in tests with Clang 21. (#6519) - 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: 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: 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: 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: Refactored split container nodes to use shared pointers. (#6435)
- Dev: Mock headers are now added as a header set if supported by CMake. (#6561) - Dev: Mock headers are now added as a header set if supported by CMake. (#6561)
@@ -3,7 +3,6 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "common/Env.hpp" #include "common/Env.hpp"
#include "common/Literals.hpp"
#include "controllers/commands/CommandContext.hpp" #include "controllers/commands/CommandContext.hpp"
#include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationController.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
@@ -13,6 +12,7 @@
#include "providers/twitch/eventsub/Controller.hpp" #include "providers/twitch/eventsub/Controller.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp" #include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "singletons/Toasts.hpp" #include "singletons/Toasts.hpp"
#include "singletons/Updates.hpp" #include "singletons/Updates.hpp"
@@ -23,9 +23,9 @@
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QString> #include <QString>
namespace chatterino::commands { using namespace Qt::StringLiterals;
using namespace literals; namespace chatterino::commands {
QString setLoggingRules(const CommandContext &ctx) QString setLoggingRules(const CommandContext &ctx)
{ {
@@ -202,6 +202,23 @@ QString debugTest(const CommandContext &ctx)
getApp()->getUpdates().checkForUpdates(); getApp()->getUpdates().checkForUpdates();
ctx.channel->addSystemMessage(QString("checking for updates")); 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 else
{ {
ctx.channel->addSystemMessage( ctx.channel->addSystemMessage(
+2 -1
View File
@@ -236,7 +236,8 @@ void HotkeyController::loadHotkeys()
auto numCombinedDefaults = set.size(); auto numCombinedDefaults = set.size();
pajlada::Settings::Setting<std::vector<QString>>::set( pajlada::Settings::Setting<std::vector<QString>>::set(
"/hotkeys/addedDefaults", std::vector<QString>(set.begin(), set.end())); "/hotkeys/addedDefaults", std::vector<QString>(set.begin(), set.end()),
pajlada::Settings::SettingOption::CompareBeforeSet);
qCDebug(chatterinoHotkeys) << "Loading hotkeys..."; qCDebug(chatterinoHotkeys) << "Loading hotkeys...";
for (const auto &key : keys) for (const auto &key : keys)
+9 -5
View File
@@ -157,8 +157,12 @@ Settings::Settings(const Args &args, const QString &settingsDirectory)
settingsInstance->setBackupEnabled(true); settingsInstance->setBackupEnabled(true);
settingsInstance->setBackupSlots(9); settingsInstance->setBackupSlots(9);
settingsInstance->saveMethod = settingsInstance->saveMethod = static_cast<
pajlada::Settings::SettingManager::SaveMethod::SaveManually; pajlada::Settings::SettingManager::SaveMethod>(
static_cast<uint64_t>(
pajlada::Settings::SettingManager::SaveMethod::SaveManually) |
static_cast<uint64_t>(
pajlada::Settings::SettingManager::SaveMethod::OnlySaveIfChanged));
initializeSignalVector(this->signalHolder, this->highlightedMessagesSetting, initializeSignalVector(this->signalHolder, this->highlightedMessagesSetting,
this->highlightedMessages); this->highlightedMessages);
@@ -198,14 +202,14 @@ Settings::~Settings()
Settings::instance_ = this->prevInstance_; Settings::instance_ = this->prevInstance_;
} }
void Settings::requestSave() const pajlada::Settings::SettingManager::SaveResult Settings::requestSave() const
{ {
if (this->disableSaving) if (this->disableSaving)
{ {
return; return pajlada::Settings::SettingManager::SaveResult::Skipped;
} }
pajlada::Settings::SettingManager::gSave(); return pajlada::Settings::SettingManager::gSave();
} }
void Settings::saveSnapshot() void Settings::saveSnapshot()
+4 -1
View File
@@ -24,6 +24,7 @@
#include <pajlada/settings/setting.hpp> #include <pajlada/settings/setting.hpp>
#include <pajlada/settings/settinglistener.hpp> #include <pajlada/settings/settinglistener.hpp>
#include <pajlada/settings/settingmanager.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include <optional> #include <optional>
@@ -130,7 +131,9 @@ public:
/// Request the settings to be saved to file /// Request the settings to be saved to file
/// ///
/// Depending on the launch options, a save might end up not happening /// 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 saveSnapshot();
void restoreSnapshot(); void restoreSnapshot();