mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 09:51:10 +01:00
Beta channel updates
This commit is contained in:
@@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user