App menu: "Check for updates" is a real check, once, now, and says what came of it calmly
Host: `updater::check_now` runs the same check the timer runs (the same updater endpoint, nothing else) for the app's shell-only `update_check`. It never queues or retries: while a check is in flight (the timer's or an earlier request's), or within 10 seconds of the last request, it only answers with the current status (`update::may_check_now`, tested). The timer's loop uses the same single-flight guard. Frame: the menu's Updates row is that check (`updateRow`, tested): "Checking…", "Up to date · <version>", "Downloading <version>…", "Restart to update" when an update is ready (the row then installs it), and "Could not check" with a plain sentence as its tooltip when the server does not answer. The updater's error text is never shown there, and a failure is only mentioned when the owner asked for the check in this menu; the timer's own failures stay quiet.
This commit is contained in:
parent
9209280959
commit
615981c7c9
6 changed files with 162 additions and 9 deletions
|
|
@ -4,8 +4,8 @@
|
|||
//! its verification are [`crate::hotfix`].
|
||||
//!
|
||||
//! The app registers the updater plugin, calls [`init`] from `setup` with its [`UpdaterConfig`],
|
||||
//! and wraps [`status`], [`apply`] and [`ready`] in its own shell-only commands; its shell gets an
|
||||
//! `update-status` event. Site tabs get no updater IPC at all, only verified hotfix data
|
||||
//! and wraps [`status`], [`apply`], [`ready`] and [`check_now`] in its own shell-only commands; its
|
||||
//! shell gets an `update-status` event. Site tabs get no updater IPC at all, only verified hotfix data
|
||||
//! ([`hotfix_script`]).
|
||||
|
||||
use crate::hotfix::{self, Hotfix, Outcome};
|
||||
|
|
@ -49,6 +49,10 @@ struct Inner {
|
|||
hotfix: Option<Hotfix>,
|
||||
/// Automatic apply is off after repeated failed starts of an update.
|
||||
problem: bool,
|
||||
/// A check is running (the timer's or one the owner asked for): a second one never starts beside it.
|
||||
checking: bool,
|
||||
/// When the owner last asked for a check ([`check_now`]).
|
||||
asked: Option<std::time::Instant>,
|
||||
}
|
||||
|
||||
struct UpdateState {
|
||||
|
|
@ -111,13 +115,48 @@ pub fn init(app: &AppHandle, config: &'static UpdaterConfig) {
|
|||
tauri::async_runtime::spawn(async move {
|
||||
tokio::time::sleep(update::FIRST_CHECK).await;
|
||||
loop {
|
||||
check_native(&app).await;
|
||||
check_once(&app).await;
|
||||
check_hotfix(&app).await;
|
||||
tokio::time::sleep(update::next_check_delay(entropy())).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// One native check, unless one is already running.
|
||||
async fn check_once(app: &AppHandle) {
|
||||
{
|
||||
let state = app.state::<UpdateState>();
|
||||
let Ok(mut inner) = state.inner.lock() else { return };
|
||||
if inner.checking {
|
||||
return;
|
||||
}
|
||||
inner.checking = true;
|
||||
}
|
||||
check_native(app).await;
|
||||
if let Ok(mut inner) = app.state::<UpdateState>().inner.lock() {
|
||||
inner.checking = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// A check the owner asked for (the app's shell-only `update_check`, the app menu's "Check for
|
||||
/// updates"): the same check the timer runs, once, now, against the same updater endpoint (no
|
||||
/// other network destination). It never queues or retries: while a check is in flight, or within
|
||||
/// [`update::MANUAL_CHECK_GAP`] of the last request, it only answers with the current status.
|
||||
/// Returns the status once the check has finished (the shell also hears each step as events).
|
||||
pub async fn check_now(app: &AppHandle) -> Result<UpdateStatus, String> {
|
||||
{
|
||||
let state = app.try_state::<UpdateState>().ok_or("UPDATE: state unavailable")?;
|
||||
let mut inner = state.inner.lock().map_err(|_| "UPDATE: state unavailable")?;
|
||||
let now = std::time::Instant::now();
|
||||
if !update::may_check_now(inner.checking, inner.asked.map(|asked| now.duration_since(asked))) {
|
||||
return Ok(status_of(state.config, &inner));
|
||||
}
|
||||
inner.asked = Some(now);
|
||||
}
|
||||
check_once(app).await;
|
||||
status(app)
|
||||
}
|
||||
|
||||
async fn check_native(app: &AppHandle) {
|
||||
{
|
||||
let state = app.state::<UpdateState>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue