Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for updates periodically #79

Open
jqnatividad opened this issue Dec 14, 2021 · 2 comments
Open

Check for updates periodically #79

jqnatividad opened this issue Dec 14, 2021 · 2 comments

Comments

@jqnatividad
Copy link
Contributor

It would be nice if self_update incorporates an update check policy that works across platforms, where you can set a time interval between checks, so the next time the binary is run and the interval has passed, it will invoke the update automatically.

@jaemk
Copy link
Owner

jaemk commented Dec 15, 2021

Seems like a good idea. Maybe implemented as some struct that you pass a file path to where it can look for and save the last timestamp at which it checked, and then run a lambda against that timestamp? Some like

let f = xdg_dirs.place_config_file("last_update.stamp")?;
let g = UpdateGuard::new(f, |ts| {
    (now() - chrono::DateTime::parse_from_rfc3339(s)?) > Duration::from_secs(60 * 60 * 24 * 7)
})?;
if g.should_try()? {
    ...
    g.save_attempt();
}

@jqnatividad
Copy link
Contributor Author

jqnatividad commented Dec 16, 2021

Great! Perhaps you can have a default of using the bin name to save the last_update.stamp file in a hidden directory (e.g. ".foo" for program ""foo").

Perhaps, there can even be a way for users to optionally specify their update preferences similar to how cargo.toml checks for semver (say "selfupdate.toml" in the same hidden directory) - so folks can pin to a specific version, or only allow patch updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants