forked from akanyan/STARTLINER
feat: autoupdate toggle
This commit is contained in:
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::fs;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
use crate::model::config::GlobalConfigField;
|
||||
use crate::model::misc::Game;
|
||||
use crate::pkg::{Package, PkgKey};
|
||||
use crate::pkg_store::{InstallResult, PackageStore};
|
||||
@ -356,19 +357,25 @@ pub async fn list_platform_capabilities() -> Result<Vec<String>, ()> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn is_offline(state: State<'_, Mutex<AppData>>) -> Result<bool, ()> {
|
||||
log::debug!("invoke: is_offline");
|
||||
pub async fn get_global_config(state: State<'_, Mutex<AppData>>, field: GlobalConfigField) -> Result<bool, ()> {
|
||||
log::debug!("invoke: get_global_config({field:?})");
|
||||
|
||||
let appd = state.lock().await;
|
||||
Ok(appd.cfg.offline_mode)
|
||||
match field {
|
||||
GlobalConfigField::OfflineMode => Ok(appd.cfg.offline_mode),
|
||||
GlobalConfigField::EnableAutoupdates => Ok(appd.cfg.enable_autoupdates)
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn set_offline(state: State<'_, Mutex<AppData>>, value: bool) -> Result<(), String> {
|
||||
log::debug!("invoke: set_offline({value})");
|
||||
pub async fn set_global_config(state: State<'_, Mutex<AppData>>, field: GlobalConfigField, value: bool) -> Result<(), String> {
|
||||
log::debug!("invoke: set_global_config({field:?}, {value})");
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
appd.cfg.offline_mode = value;
|
||||
match field {
|
||||
GlobalConfigField::OfflineMode => appd.cfg.offline_mode = value,
|
||||
GlobalConfigField::EnableAutoupdates => appd.cfg.enable_autoupdates = value
|
||||
};
|
||||
appd.write().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
|
@ -200,8 +200,8 @@ pub async fn run(_args: Vec<String>) {
|
||||
cmd::sync_current_profile,
|
||||
cmd::save_current_profile,
|
||||
|
||||
cmd::is_offline,
|
||||
cmd::set_offline,
|
||||
cmd::get_global_config,
|
||||
cmd::set_global_config,
|
||||
|
||||
cmd::list_displays,
|
||||
cmd::list_platform_capabilities,
|
||||
@ -265,22 +265,28 @@ fn deep_link(app: AppHandle, args: Vec<String>) {
|
||||
}
|
||||
|
||||
async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
|
||||
let mutex = app.state::<Mutex<AppData>>();
|
||||
let appd = mutex.lock().await;
|
||||
if !appd.cfg.enable_autoupdates {
|
||||
log::info!("skipping autoupdate");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(update) = app.updater()?.check().await? {
|
||||
let mut downloaded = 0;
|
||||
update
|
||||
.download_and_install(
|
||||
|chunk_length, content_length| {
|
||||
downloaded += chunk_length;
|
||||
log::debug!("downloaded {downloaded} from {content_length:?}");
|
||||
},
|
||||
|| {
|
||||
log::info!("download finished");
|
||||
},
|
||||
let mut downloaded = 0;
|
||||
update.download_and_install(
|
||||
|chunk_length, content_length| {
|
||||
downloaded += chunk_length;
|
||||
log::debug!("downloaded {downloaded} from {content_length:?}");
|
||||
},
|
||||
|| {
|
||||
log::info!("download finished");
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
log::info!("update installed");
|
||||
app.restart();
|
||||
log::info!("update installed");
|
||||
app.restart();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1,10 +1,25 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::misc::Game;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct GlobalConfig {
|
||||
pub recent_profile: Option<(Game, String)>,
|
||||
|
||||
#[serde(default)]
|
||||
pub offline_mode: bool,
|
||||
pub enable_autoupdates: bool,
|
||||
}
|
||||
|
||||
impl Default for GlobalConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
recent_profile: Default::default(),
|
||||
offline_mode: false,
|
||||
enable_autoupdates: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum GlobalConfigField {
|
||||
OfflineMode,
|
||||
EnableAutoupdates
|
||||
}
|
Reference in New Issue
Block a user