The Problem
Currently, our expire_timed_sites() function does a great job of cleaning up the blocklist, but it is only triggered during a manual update_hosts() cycle (e.g., when a user clicks "Add" or "Remove").
Because our UI is built using iced::Sandbox, the app is entirely synchronous and only reacts to direct user input. If the app is left running in the background, a timed block can expire, but the hosts file will not be automatically updated until the user interacts with the app window again.
The Task
To fix this, we need to introduce a background timer (a "Tick") that checks for expirations every second. This requires graduating the UI from a Sandbox to an Application.
- Change the Trait: In
src/app.rs, change the implementation from Sandbox to Application.
- Add a Tick Message: Expand the
Message enum to handle a time tick:
pub enum Message {
UrlChanged(String),
DurationChanged(String),
AddSite,
RemoveSite(String),
ToggleBlocking,
Tick(std::time::Instant),
}
The Problem
Currently, our
expire_timed_sites()function does a great job of cleaning up the blocklist, but it is only triggered during a manualupdate_hosts()cycle (e.g., when a user clicks "Add" or "Remove").Because our UI is built using
iced::Sandbox, the app is entirely synchronous and only reacts to direct user input. If the app is left running in the background, a timed block can expire, but the hosts file will not be automatically updated until the user interacts with the app window again.The Task
To fix this, we need to introduce a background timer (a "Tick") that checks for expirations every second. This requires graduating the UI from a
Sandboxto anApplication.src/app.rs, change the implementation fromSandboxtoApplication.Messageenum to handle a time tick: