1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-21 13:46:52 +00:00

fix: apply alt speed settings on load (#6937)

* fix: apply alt speed settings on load

* refactor: allow forcing `tr_session_alt_speeds::set_active()`
This commit is contained in:
Yat Ho 2024-07-11 07:55:34 +08:00 committed by GitHub
parent 5e08164742
commit 415c0a8aa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -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);

View file

@ -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;