Make restarts optional for Kotatogram settings
This commit is contained in:
parent
887223bacb
commit
7c376c3a0b
6 changed files with 91 additions and 87 deletions
|
|
@ -257,24 +257,14 @@ void FontsBox::setInnerFocus() {
|
|||
}
|
||||
|
||||
void FontsBox::save() {
|
||||
const auto useSystemFont = _useSystemFont->checked();
|
||||
const auto useOriginalMetrics = _useOriginalMetrics->checked();
|
||||
const auto mainFont = _mainFontName->getLastText().trimmed();
|
||||
const auto semiboldFont = _semiboldFontName->getLastText().trimmed();
|
||||
const auto semiboldIsBold = _semiboldIsBold->checked();
|
||||
const auto monospacedFont = _monospacedFontName->getLastText().trimmed();
|
||||
|
||||
const auto changeFonts = [=] {
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/main", mainFont);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/semibold", semiboldFont);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/monospaced", monospacedFont);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/semibold_is_bold", semiboldIsBold);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/use_system_font", useSystemFont);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/use_original_metrics", useOriginalMetrics);
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/size", _fontSize);
|
||||
::Kotato::JsonSettings::Write();
|
||||
Core::Restart();
|
||||
};
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/main", _mainFontName->getLastText().trimmed());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/semibold", _semiboldFontName->getLastText().trimmed());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/monospaced", _monospacedFontName->getLastText().trimmed());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/semibold_is_bold", _semiboldIsBold->checked());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/use_system_font", _useSystemFont->checked());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/use_original_metrics", _useOriginalMetrics->checked());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/size", _fontSize);
|
||||
::Kotato::JsonSettings::Write();
|
||||
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
|
||||
|
|
@ -282,22 +272,20 @@ void FontsBox::save() {
|
|||
Box<Ui::ConfirmBox>(
|
||||
tr::lng_settings_need_restart(tr::now),
|
||||
tr::lng_settings_restart_now(tr::now),
|
||||
tr::lng_cancel(tr::now),
|
||||
changeFonts));
|
||||
tr::lng_settings_restart_later(tr::now),
|
||||
[] { Core::Restart(); },
|
||||
[=] { closeBox(); }));
|
||||
}
|
||||
|
||||
void FontsBox::resetToDefault() {
|
||||
const auto resetFonts = [=] {
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/main");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/semibold");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/monospaced");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/semibold_is_bold");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/size");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/use_system_font");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/use_original_metrics");
|
||||
::Kotato::JsonSettings::Write();
|
||||
Core::Restart();
|
||||
};
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/main");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/semibold");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/monospaced");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/semibold_is_bold");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/size");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/use_system_font");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/use_original_metrics");
|
||||
::Kotato::JsonSettings::Write();
|
||||
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
|
||||
|
|
@ -305,6 +293,7 @@ void FontsBox::resetToDefault() {
|
|||
Box<Ui::ConfirmBox>(
|
||||
tr::lng_settings_need_restart(tr::now),
|
||||
tr::lng_settings_restart_now(tr::now),
|
||||
tr::lng_cancel(tr::now),
|
||||
resetFonts));
|
||||
tr::lng_settings_restart_later(tr::now),
|
||||
[] { Core::Restart(); },
|
||||
[=] { closeBox(); }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,22 +157,18 @@ void RadioBox::prepare() {
|
|||
}
|
||||
|
||||
void RadioBox::save() {
|
||||
_saveCallback(_group->value());
|
||||
if (_warnRestart) {
|
||||
const auto saveAfterWarn = [=] {
|
||||
_saveCallback(_group->value());
|
||||
Core::Restart();
|
||||
};
|
||||
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
|
||||
*box = getDelegate()->show(
|
||||
Box<Ui::ConfirmBox>(
|
||||
tr::lng_settings_need_restart(tr::now),
|
||||
tr::lng_settings_restart_now(tr::now),
|
||||
tr::lng_cancel(tr::now),
|
||||
saveAfterWarn));
|
||||
tr::lng_settings_restart_later(tr::now),
|
||||
[] { Core::Restart(); },
|
||||
[=] { closeBox(); }));
|
||||
} else {
|
||||
_saveCallback(_group->value());
|
||||
closeBox();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,10 @@ public:
|
|||
const QString &key,
|
||||
uint64 accountId = 0,
|
||||
bool isTestAccount = false);
|
||||
[[nodiscard]] rpl::producer<bool> restartEvents();
|
||||
[[nodiscard]] rpl::producer<QString> eventsWithPending(
|
||||
const QString &key,
|
||||
uint64 accountId = 0,
|
||||
bool isTestAccount = false);
|
||||
void set(
|
||||
const QString &key,
|
||||
QVariant value,
|
||||
|
|
@ -71,7 +74,6 @@ public:
|
|||
uint64 accountId = 0,
|
||||
bool isTestAccount = false);
|
||||
void writeTimeout();
|
||||
bool needRestart();
|
||||
|
||||
private:
|
||||
[[nodiscard]] QVariant getDefault(const QString &key);
|
||||
|
|
@ -84,7 +86,7 @@ private:
|
|||
base::Timer _jsonWriteTimer;
|
||||
|
||||
rpl::event_stream<QString> _eventStream;
|
||||
rpl::event_stream<bool> _restartEventStream;
|
||||
rpl::event_stream<QString> _pendingEventStream;
|
||||
QHash<QString, QVariant> _settingsHashMap;
|
||||
QHash<QString, QVariant> _defaultSettingsHashMap;
|
||||
|
||||
|
|
@ -785,8 +787,9 @@ rpl::producer<QString> Manager::events(const QString &key, uint64 accountId, boo
|
|||
return _eventStream.events() | rpl::filter(rpl::mappers::_1 == mapKey);
|
||||
}
|
||||
|
||||
rpl::producer<bool> Manager::restartEvents() {
|
||||
return _restartEventStream.events();
|
||||
rpl::producer<QString> Manager::eventsWithPending(const QString &key, uint64 accountId, bool isTestAccount) {
|
||||
const auto mapKey = MakeMapKey(key, accountId, isTestAccount);
|
||||
return _pendingEventStream.events() | rpl::filter(rpl::mappers::_1 == mapKey);
|
||||
}
|
||||
|
||||
void Manager::set(const QString &key, QVariant value, uint64 accountId, bool isTestAccount) {
|
||||
|
|
@ -797,7 +800,6 @@ void Manager::set(const QString &key, QVariant value, uint64 accountId, bool isT
|
|||
|
||||
void Manager::setAfterRestart(const QString &key, QVariant value, uint64 accountId, bool isTestAccount) {
|
||||
const auto mapKey = MakeMapKey(key, accountId, isTestAccount);
|
||||
const auto oldNeedRestart = needRestart();
|
||||
if (!_settingsHashMap.contains(mapKey)
|
||||
|| _settingsHashMap.value(mapKey) != value) {
|
||||
_defaultSettingsHashMap.insert(mapKey, value);
|
||||
|
|
@ -805,10 +807,7 @@ void Manager::setAfterRestart(const QString &key, QVariant value, uint64 account
|
|||
&& _settingsHashMap.value(mapKey) == value) {
|
||||
_defaultSettingsHashMap.remove(mapKey);
|
||||
}
|
||||
const auto newNeedRestart = needRestart();
|
||||
if (oldNeedRestart != newNeedRestart) {
|
||||
_restartEventStream.fire_copy(newNeedRestart);
|
||||
}
|
||||
_pendingEventStream.fire_copy(mapKey);
|
||||
}
|
||||
|
||||
void Manager::reset(const QString &key, uint64 accountId, bool isTestAccount) {
|
||||
|
|
@ -1003,10 +1002,6 @@ void Manager::writeTimeout() {
|
|||
writeCurrentSettings();
|
||||
}
|
||||
|
||||
bool Manager::needRestart() {
|
||||
return _defaultSettingsHashMap.size() > 0;
|
||||
}
|
||||
|
||||
void Manager::writing() {
|
||||
_jsonWriteTimer.cancel();
|
||||
}
|
||||
|
|
@ -1048,8 +1043,8 @@ rpl::producer<QString> Events(const QString &key, uint64 accountId, bool isTestA
|
|||
return (Data) ? Data->events(key, accountId, isTestAccount) : rpl::single(QString());
|
||||
}
|
||||
|
||||
rpl::producer<bool> RestartEvents() {
|
||||
return (Data) ? Data->restartEvents() : rpl::single(false);
|
||||
rpl::producer<QString> EventsWithPending(const QString &key, uint64 accountId, bool isTestAccount) {
|
||||
return (Data) ? Data->eventsWithPending(key, accountId, isTestAccount) : rpl::single(QString());
|
||||
}
|
||||
|
||||
void Set(const QString &key, QVariant value, uint64 accountId, bool isTestAccount) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ void Finish();
|
|||
const QString &key,
|
||||
uint64 accountId = 0,
|
||||
bool isTestAccount = false);
|
||||
[[nodiscard]] rpl::producer<bool> RestartEvents();
|
||||
[[nodiscard]] rpl::producer<QString> EventsWithPending(
|
||||
const QString &key,
|
||||
uint64 accountId = 0,
|
||||
bool isTestAccount = false);
|
||||
void Set(
|
||||
const QString &key,
|
||||
QVariant value,
|
||||
|
|
|
|||
|
|
@ -305,20 +305,34 @@ void SetupKotatoChats(
|
|||
Ui::show(Box<FontsBox>());
|
||||
});
|
||||
|
||||
AddButtonWithLabel(
|
||||
container,
|
||||
rktr("ktg_settings_userpic_rounding"),
|
||||
rpl::single(UserpicRoundingLabel(::Kotato::JsonSettings::GetInt("userpic_corner_type"))),
|
||||
st::settingsButton
|
||||
)->addClickHandler([=] {
|
||||
const auto userpicCornerButton = container->add(
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
rktr("ktg_settings_userpic_rounding"),
|
||||
st::settingsButton));
|
||||
auto userpicCornerText = rpl::single(
|
||||
UserpicRoundingLabel(::Kotato::JsonSettings::GetIntWithPending("userpic_corner_type"))
|
||||
) | rpl::then(
|
||||
::Kotato::JsonSettings::EventsWithPending(
|
||||
"userpic_corner_type"
|
||||
) | rpl::map([] {
|
||||
return UserpicRoundingLabel(::Kotato::JsonSettings::GetIntWithPending("userpic_corner_type"));
|
||||
})
|
||||
);
|
||||
CreateRightLabel(
|
||||
userpicCornerButton,
|
||||
std::move(userpicCornerText),
|
||||
st::settingsButton,
|
||||
rktr("ktg_settings_userpic_rounding"));
|
||||
userpicCornerButton->addClickHandler([=] {
|
||||
Ui::show(Box<::Kotato::RadioBox>(
|
||||
ktr("ktg_settings_userpic_rounding"),
|
||||
ktr("ktg_settings_userpic_rounding_desc"),
|
||||
::Kotato::JsonSettings::GetInt("userpic_corner_type"),
|
||||
::Kotato::JsonSettings::GetIntWithPending("userpic_corner_type"),
|
||||
4,
|
||||
UserpicRoundingLabel,
|
||||
[=] (int value) {
|
||||
::Kotato::JsonSettings::Set("userpic_corner_type", value);
|
||||
::Kotato::JsonSettings::SetAfterRestart("userpic_corner_type", value);
|
||||
::Kotato::JsonSettings::Write();
|
||||
}, true));
|
||||
});
|
||||
|
|
@ -541,12 +555,26 @@ void SetupKotatoNetwork(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container);
|
||||
AddSubsectionTitle(container, rktr("ktg_settings_network"));
|
||||
|
||||
AddButtonWithLabel(
|
||||
container,
|
||||
rktr("ktg_settings_net_speed_boost"),
|
||||
rpl::single(NetBoostLabel(::Kotato::JsonSettings::GetIntWithPending("net_speed_boost"))),
|
||||
st::settingsButton
|
||||
)->addClickHandler([=] {
|
||||
const auto netBoostButton = container->add(
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
rktr("ktg_settings_net_speed_boost"),
|
||||
st::settingsButton));
|
||||
auto netBoostText = rpl::single(
|
||||
NetBoostLabel(::Kotato::JsonSettings::GetIntWithPending("net_speed_boost"))
|
||||
) | rpl::then(
|
||||
::Kotato::JsonSettings::EventsWithPending(
|
||||
"net_speed_boost"
|
||||
) | rpl::map([] {
|
||||
return NetBoostLabel(::Kotato::JsonSettings::GetIntWithPending("net_speed_boost"));
|
||||
})
|
||||
);
|
||||
CreateRightLabel(
|
||||
netBoostButton,
|
||||
std::move(netBoostText),
|
||||
st::settingsButton,
|
||||
rktr("ktg_settings_net_speed_boost"));
|
||||
netBoostButton->addClickHandler([=] {
|
||||
Ui::show(Box<::Kotato::RadioBox>(
|
||||
ktr("ktg_net_speed_boost_title"),
|
||||
ktr("ktg_net_speed_boost_desc"),
|
||||
|
|
@ -587,31 +615,24 @@ void SetupKotatoSystem(
|
|||
AddSubsectionTitle(container, rktr("ktg_settings_system"));
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
const auto qtScaleToggled = Ui::CreateChild<rpl::event_stream<bool>>(
|
||||
container.get());
|
||||
AddButton(
|
||||
container,
|
||||
rktr("ktg_settings_qt_scale"),
|
||||
st::settingsButton
|
||||
)->toggleOn(
|
||||
qtScaleToggled->events_starting_with_copy(::Kotato::JsonSettings::GetBool("qt_scale"))
|
||||
rpl::single(::Kotato::JsonSettings::GetBoolWithPending("qt_scale"))
|
||||
)->toggledValue(
|
||||
) | rpl::filter([](bool enabled) {
|
||||
return (enabled != ::Kotato::JsonSettings::GetBool("qt_scale"));
|
||||
return (enabled != ::Kotato::JsonSettings::GetBoolWithPending("qt_scale"));
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
const auto confirmed = [=] {
|
||||
::Kotato::JsonSettings::Set("qt_scale", enabled);
|
||||
::Kotato::JsonSettings::Write();
|
||||
Core::Restart();
|
||||
};
|
||||
const auto cancelled = [=] {
|
||||
qtScaleToggled->fire(::Kotato::JsonSettings::GetBool("qt_scale") == true);
|
||||
};
|
||||
::Kotato::JsonSettings::SetAfterRestart("qt_scale", enabled);
|
||||
::Kotato::JsonSettings::Write();
|
||||
|
||||
Ui::show(Box<Ui::ConfirmBox>(
|
||||
tr::lng_settings_need_restart(tr::now),
|
||||
tr::lng_settings_restart_now(tr::now),
|
||||
confirmed,
|
||||
cancelled));
|
||||
tr::lng_settings_restart_later(tr::now),
|
||||
[] { Core::Restart(); }));
|
||||
}, container->lifetime());
|
||||
#endif // Qt < 6.0.0
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ void FillMenu(
|
|||
&st::menuIconSettings);
|
||||
addAction(
|
||||
ktr("ktg_settings_restart"),
|
||||
[=] { Core::Restart(); },
|
||||
[] { Core::Restart(); },
|
||||
&st::menuIconRestore);
|
||||
if (type != Type::Kotato) {
|
||||
addAction(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue