Skip to content

Commit

Permalink
#361: Add release check while app is open
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jul 19, 2024
1 parent 440883d commit 4ef9df5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* You can now ignore specific manifests during scans.
For example, if you only want to back up custom games,
you can now disable the primary manifest's entries.
* GUI: On startup, Ludusavi will check if a new version is available and notify you.
This happens at most once per 7 days.
* GUI: On startup and once every 24 hours,
Ludusavi will check if a new version is available and notify you.
* GUI: When left open,
Ludusavi will automatically check for manifest updates once every 24 hours.
Previously, this check only occurred when the app started.
Expand Down
13 changes: 13 additions & 0 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,15 @@ impl Application for App {
self.save_config();
Command::none()
}
Message::CheckAppRelease => {
if !self.cache.should_check_app_update() {
return Command::none();
}

Command::perform(async move { crate::metadata::Release::fetch().await }, |join| {
Message::AppReleaseChecked(join.map_err(|x| x.to_string()))
})
}
Message::AppReleaseChecked(outcome) => {
self.save_cache();
self.cache.release.checked = chrono::offset::Utc::now();
Expand Down Expand Up @@ -2679,6 +2688,10 @@ impl Application for App {
);
}

if self.config.release.check {
subscriptions.push(iced::time::every(Duration::from_secs(60 * 60 * 24)).map(|_| Message::CheckAppRelease));
}

if self.exiting {
subscriptions.push(iced::time::every(Duration::from_millis(50)).map(|_| Message::Exit { user: false }));
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub enum Message {
UpdateTime,
PruneNotifications,
AppReleaseToggle(bool),
CheckAppRelease,
AppReleaseChecked(Result<crate::metadata::Release, String>),
UpdateManifest {
force: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/resource/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ impl Cache {

pub fn should_check_app_update(&self) -> bool {
let now = chrono::offset::Utc::now();
now.signed_duration_since(self.release.checked).num_days() >= 7
now.signed_duration_since(self.release.checked).num_hours() >= 24
}
}

0 comments on commit 4ef9df5

Please sign in to comment.