mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
032f290767
This change enforces strict include grouping using IncludeCategories In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes: In ChatterSet.hpp, I changed lrucache to a <>include In Irc2.hpp, I change common/SignalVector.hpp to a "project-include" In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first. clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
128 lines
2.8 KiB
C++
128 lines
2.8 KiB
C++
#include "BaseSettings.hpp"
|
|
|
|
#include "util/Clamp.hpp"
|
|
|
|
#include <QDebug>
|
|
|
|
namespace chatterino {
|
|
|
|
std::vector<std::weak_ptr<pajlada::Settings::SettingData>> _settings;
|
|
|
|
AB_SETTINGS_CLASS *AB_SETTINGS_CLASS::instance = nullptr;
|
|
|
|
void _actuallyRegisterSetting(
|
|
std::weak_ptr<pajlada::Settings::SettingData> setting)
|
|
{
|
|
_settings.push_back(std::move(setting));
|
|
}
|
|
|
|
AB_SETTINGS_CLASS::AB_SETTINGS_CLASS(const QString &settingsDirectory)
|
|
{
|
|
AB_SETTINGS_CLASS::instance = this;
|
|
|
|
QString settingsPath = settingsDirectory + "/settings.json";
|
|
|
|
// get global instance of the settings library
|
|
auto settingsInstance = pajlada::Settings::SettingManager::getInstance();
|
|
|
|
settingsInstance->load(qPrintable(settingsPath));
|
|
|
|
settingsInstance->setBackupEnabled(true);
|
|
settingsInstance->setBackupSlots(9);
|
|
settingsInstance->saveMethod =
|
|
pajlada::Settings::SettingManager::SaveMethod::SaveOnExit;
|
|
}
|
|
|
|
void AB_SETTINGS_CLASS::saveSnapshot()
|
|
{
|
|
rapidjson::Document *d = new rapidjson::Document(rapidjson::kObjectType);
|
|
rapidjson::Document::AllocatorType &a = d->GetAllocator();
|
|
|
|
for (const auto &weakSetting : _settings)
|
|
{
|
|
auto setting = weakSetting.lock();
|
|
if (!setting)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
rapidjson::Value key(setting->getPath().c_str(), a);
|
|
auto curVal = setting->unmarshalJSON();
|
|
if (curVal == nullptr)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
rapidjson::Value val;
|
|
val.CopyFrom(*curVal, a);
|
|
d->AddMember(key.Move(), val.Move(), a);
|
|
}
|
|
|
|
// log("Snapshot state: {}", rj::stringify(*d));
|
|
|
|
this->snapshot_.reset(d);
|
|
}
|
|
|
|
void AB_SETTINGS_CLASS::restoreSnapshot()
|
|
{
|
|
if (!this->snapshot_)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const auto &snapshot = *(this->snapshot_.get());
|
|
|
|
if (!snapshot.IsObject())
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (const auto &weakSetting : _settings)
|
|
{
|
|
auto setting = weakSetting.lock();
|
|
if (!setting)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
const char *path = setting->getPath().c_str();
|
|
|
|
if (!snapshot.HasMember(path))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
setting->marshalJSON(snapshot[path]);
|
|
}
|
|
}
|
|
|
|
float AB_SETTINGS_CLASS::getClampedUiScale() const
|
|
{
|
|
return clamp<float>(this->uiScale.getValue(), 0.2f, 10);
|
|
}
|
|
|
|
void AB_SETTINGS_CLASS::setClampedUiScale(float value)
|
|
{
|
|
this->uiScale.setValue(clamp<float>(value, 0.2f, 10));
|
|
}
|
|
|
|
#ifndef AB_CUSTOM_SETTINGS
|
|
Settings *getSettings()
|
|
{
|
|
static_assert(std::is_same_v<AB_SETTINGS_CLASS, Settings>,
|
|
"`AB_SETTINGS_CLASS` must be the same as `Settings`");
|
|
|
|
assert(AB_SETTINGS_CLASS::instance != nullptr);
|
|
|
|
return AB_SETTINGS_CLASS::instance;
|
|
}
|
|
#endif
|
|
|
|
AB_SETTINGS_CLASS *getABSettings()
|
|
{
|
|
assert(AB_SETTINGS_CLASS::instance);
|
|
|
|
return AB_SETTINGS_CLASS::instance;
|
|
}
|
|
|
|
} // namespace chatterino
|