mirror of
https://github.com/Chatterino/chatterino2.git
synced 2026-08-24 02:24:18 -05:00
chore: scaffold setting migration system (#7144)
This commit is contained in:
@@ -19,10 +19,11 @@ namespace chatterino::mock {
|
||||
class BaseApplication : public EmptyApplication
|
||||
{
|
||||
public:
|
||||
BaseApplication()
|
||||
BaseApplication(bool runMigrations = false)
|
||||
: settings(this->modes_, this->args_, this->settingsDir.path(),
|
||||
{
|
||||
.isTest = true,
|
||||
.runMigrations = runMigrations,
|
||||
})
|
||||
, updates(this->modes_, this->paths_, this->settings)
|
||||
, theme(this->paths_)
|
||||
@@ -30,11 +31,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
explicit BaseApplication(const QString &settingsData)
|
||||
BaseApplication(const QString &settingsData, bool runMigrations = false)
|
||||
: EmptyApplication(settingsData)
|
||||
, settings(this->modes_, this->args_, this->settingsDir.path(),
|
||||
{
|
||||
.isTest = true,
|
||||
.runMigrations = runMigrations,
|
||||
})
|
||||
, updates(this->modes_, this->paths_, this->settings)
|
||||
, theme(this->paths_)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Args.hpp"
|
||||
#include "common/Modes.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
#include "controllers/highlights/HighlightBadge.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
@@ -47,6 +48,13 @@ void initializeSignalVector(pajlada::Signals::SignalHolder &signalHolder,
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
const auto &LOG = chatterinoSettings;
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<std::weak_ptr<pajlada::Settings::SettingData>> _settings;
|
||||
|
||||
void _actuallyRegisterSetting(
|
||||
@@ -70,6 +78,10 @@ bool Settings::isHighlightedUser(const QString &username)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Settings::migrate(bool isTest)
|
||||
{
|
||||
}
|
||||
|
||||
bool Settings::isBlacklistedUser(const QString &username)
|
||||
{
|
||||
auto items = this->blacklistedUsers.readOnly();
|
||||
@@ -167,6 +179,7 @@ Settings::Settings(const Modes &modes, const Args &args,
|
||||
|
||||
if (settingsArgs.isTest)
|
||||
{
|
||||
qCInfo(LOG) << "Loading settings from" << settingsPath;
|
||||
settingsInstance->load(qPrintable(settingsPath));
|
||||
}
|
||||
else
|
||||
@@ -212,6 +225,12 @@ Settings::Settings(const Modes &modes, const Args &args,
|
||||
static_cast<uint64_t>(
|
||||
pajlada::Settings::SettingManager::SaveMethod::OnlySaveIfChanged));
|
||||
|
||||
// Run setting migrations
|
||||
if (settingsArgs.runMigrations)
|
||||
{
|
||||
this->migrate(settingsArgs.isTest);
|
||||
}
|
||||
|
||||
initializeSignalVector(this->signalHolder, this->highlightedMessagesSetting,
|
||||
this->highlightedMessages);
|
||||
initializeSignalVector(this->signalHolder, this->highlightedUsersSetting,
|
||||
|
||||
@@ -116,6 +116,7 @@ constexpr std::optional<std::string_view> qmagicenumDisplayName(
|
||||
|
||||
struct SettingsArgs {
|
||||
bool isTest = false;
|
||||
bool runMigrations = true;
|
||||
};
|
||||
|
||||
/// Settings which are available for reading and writing on the gui thread.
|
||||
@@ -874,6 +875,13 @@ private:
|
||||
"/logging/channels"};
|
||||
SignalVector<QString> mutedChannels;
|
||||
|
||||
IntSetting settingsVersion = {
|
||||
"/misc/settingsVersion",
|
||||
0,
|
||||
};
|
||||
|
||||
void migrate(bool isTest);
|
||||
|
||||
public:
|
||||
SignalVector<HighlightPhrase> highlightedMessages;
|
||||
SignalVector<HighlightPhrase> highlightedUsers;
|
||||
|
||||
@@ -67,13 +67,8 @@ const QString IRC_CATEGORY = u"IrcMessageHandler"_s;
|
||||
class MockApplication : public mock::BaseApplication
|
||||
{
|
||||
public:
|
||||
MockApplication()
|
||||
: highlights(this->settings, &this->accounts)
|
||||
{
|
||||
}
|
||||
|
||||
MockApplication(const QString &settingsData)
|
||||
: mock::BaseApplication(settingsData)
|
||||
: mock::BaseApplication(settingsData, /*runMigrations*/ true)
|
||||
, highlights(this->settings, &this->accounts)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user