From 415c0a8aa348891d16db8bc3e4d69de1d5890381 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Thu, 11 Jul 2024 07:55:34 +0800 Subject: [PATCH] fix: apply alt speed settings on load (#6937) * fix: apply alt speed settings on load * refactor: allow forcing `tr_session_alt_speeds::set_active()` --- libtransmission/session-alt-speeds.cc | 5 +++-- libtransmission/session-alt-speeds.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libtransmission/session-alt-speeds.cc b/libtransmission/session-alt-speeds.cc index 3782e2342..47180d4c4 100644 --- a/libtransmission/session-alt-speeds.cc +++ b/libtransmission/session-alt-speeds.cc @@ -22,6 +22,7 @@ void tr_session_alt_speeds::load(Settings&& settings) { settings_ = std::move(settings); update_scheduler(); + set_active(settings_.is_active, ChangeReason::LoadSettings, true); } void tr_session_alt_speeds::update_minutes() @@ -66,9 +67,9 @@ void tr_session_alt_speeds::check_scheduler() } } -void tr_session_alt_speeds::set_active(bool active, ChangeReason reason) +void tr_session_alt_speeds::set_active(bool active, ChangeReason reason, bool force) { - if (auto& tgt = settings_.is_active; tgt != active) + if (auto& tgt = settings_.is_active; force || tgt != active) { tgt = active; mediator_.is_active_changed(tgt, reason); diff --git a/libtransmission/session-alt-speeds.h b/libtransmission/session-alt-speeds.h index 084be65c7..968433b43 100644 --- a/libtransmission/session-alt-speeds.h +++ b/libtransmission/session-alt-speeds.h @@ -63,10 +63,11 @@ public: } }; - enum class ChangeReason + enum class ChangeReason : uint8_t { User, - Scheduler + Scheduler, + LoadSettings }; class Mediator @@ -162,7 +163,10 @@ public: } } - void set_active(bool active, ChangeReason reason); + void set_active(bool active, ChangeReason reason) + { + set_active(active, reason, false); + } private: Mediator& mediator_; @@ -171,6 +175,7 @@ private: void update_scheduler(); void update_minutes(); + void set_active(bool active, ChangeReason reason, bool force); // whether `time` hits in one of the `minutes_` that is true [[nodiscard]] bool is_active_minute(time_t time) const noexcept;