fix: save settings less often (#6620)
Reviewed-by: James Upjohn <jupjohn@jammeh.co.nz>
This commit is contained in:
@@ -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 <QLoggingCategory>
|
||||
#include <QString>
|
||||
|
||||
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(
|
||||
|
||||
@@ -236,7 +236,8 @@ void HotkeyController::loadHotkeys()
|
||||
auto numCombinedDefaults = set.size();
|
||||
|
||||
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...";
|
||||
for (const auto &key : keys)
|
||||
|
||||
@@ -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<uint64_t>(
|
||||
pajlada::Settings::SettingManager::SaveMethod::SaveManually) |
|
||||
static_cast<uint64_t>(
|
||||
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()
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
#include <pajlada/settings/settinglistener.hpp>
|
||||
#include <pajlada/settings/settingmanager.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
|
||||
#include <optional>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user