Beta channel updates

This commit is contained in:
Gregory Schier
2023-11-14 08:57:46 -08:00
parent 11f5541558
commit da414debe1
6 changed files with 164 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
use std::time::SystemTime;
use log::info;
use tauri::{AppHandle, updater, Window, Wry};
use tauri::api::dialog;
@@ -11,19 +12,31 @@ pub struct YaakUpdater {
last_update_check: SystemTime,
}
pub enum UpdateMode {
Stable,
Beta,
}
impl YaakUpdater {
pub fn new() -> Self {
Self {
last_update_check: SystemTime::UNIX_EPOCH,
}
}
pub async fn check(&mut self, app_handle: &AppHandle<Wry>) -> Result<(), updater::Error> {
if self.last_update_check.elapsed().unwrap().as_secs() < MAX_UPDATE_CHECK_SECONDS {
return Ok(());
}
pub async fn force_check(
&mut self,
app_handle: &AppHandle<Wry>,
mode: UpdateMode,
) -> Result<(), updater::Error> {
self.last_update_check = SystemTime::now();
match app_handle.updater().check().await {
let update_mode = get_update_mode_str(mode);
info!("Checking for updates mode={}", update_mode);
match app_handle
.updater()
.header("X-Update-Mode", update_mode)?
.check()
.await
{
Ok(update) => {
if dialog::blocking::ask(
None::<&Window>,
@@ -38,4 +51,29 @@ impl YaakUpdater {
Err(e) => Err(e),
}
}
pub async fn check(
&mut self,
app_handle: &AppHandle<Wry>,
mode: UpdateMode,
) -> Result<(), updater::Error> {
if self.last_update_check.elapsed().unwrap().as_secs() < MAX_UPDATE_CHECK_SECONDS {
return Ok(());
}
self.force_check(app_handle, mode).await
}
}
pub fn update_mode_from_str(mode: &str) -> UpdateMode {
match mode {
"beta" => UpdateMode::Beta,
_ => UpdateMode::Stable,
}
}
fn get_update_mode_str(mode: UpdateMode) -> &'static str {
match mode {
UpdateMode::Stable => "stable",
UpdateMode::Beta => "beta",
}
}