Fixed updater
This commit is contained in:
@@ -1,52 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{AppHandle, Manager};
|
||||
use tauri::AppHandle;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AppConfig {
|
||||
pub update_url: String,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
update_url: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn config_path(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
let dir = app
|
||||
.path()
|
||||
.app_config_dir()
|
||||
.map_err(|e| format!("Failed to get config dir: {}", e))?;
|
||||
std::fs::create_dir_all(&dir)
|
||||
.map_err(|e| format!("Failed to create config dir: {}", e))?;
|
||||
Ok(dir.join("config.json"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_config(app: AppHandle) -> Result<AppConfig, String> {
|
||||
let path = config_path(&app)?;
|
||||
if !path.exists() {
|
||||
return Ok(AppConfig::default());
|
||||
}
|
||||
let data = std::fs::read_to_string(&path)
|
||||
.map_err(|e| format!("Failed to read config: {}", e))?;
|
||||
serde_json::from_str(&data)
|
||||
.map_err(|e| format!("Failed to parse config: {}", e))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn save_config(app: AppHandle, config: AppConfig) -> Result<(), String> {
|
||||
let path = config_path(&app)?;
|
||||
let data = serde_json::to_string_pretty(&config)
|
||||
.map_err(|e| format!("Failed to serialize config: {}", e))?;
|
||||
std::fs::write(&path, data)
|
||||
.map_err(|e| format!("Failed to write config: {}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
const UPDATE_URL: &str = "https://git.racooncity.org/api/v1/repos/mysticmomba/argus/releases/latest";
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct UpdateInfo {
|
||||
@@ -57,13 +12,7 @@ pub struct UpdateInfo {
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn check_for_update(app: AppHandle) -> Result<Option<UpdateInfo>, String> {
|
||||
let config = get_config(app.clone()).await?;
|
||||
|
||||
if config.update_url.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let response = reqwest::get(&config.update_url)
|
||||
let response = reqwest::get(UPDATE_URL)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to check for updates: {}", e))?;
|
||||
|
||||
@@ -76,7 +25,6 @@ pub async fn check_for_update(app: AppHandle) -> Result<Option<UpdateInfo>, Stri
|
||||
.await
|
||||
.map_err(|e| format!("Invalid update response: {}", e))?;
|
||||
|
||||
// Parse Gitea/GitHub release format
|
||||
let tag = body["tag_name"]
|
||||
.as_str()
|
||||
.ok_or_else(|| "No tag_name in response".to_string())?;
|
||||
@@ -91,7 +39,6 @@ pub async fn check_for_update(app: AppHandle) -> Result<Option<UpdateInfo>, Stri
|
||||
.map(|s| s.to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
// Strip leading 'v' from tag if present (v0.2.0 -> 0.2.0)
|
||||
let remote_version = tag.strip_prefix('v').unwrap_or(tag);
|
||||
let current = app.package_info().version.to_string();
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ pub fn run() {
|
||||
commands::monitor::monitor_get_entries,
|
||||
commands::monitor::monitor_start,
|
||||
commands::monitor::monitor_stop,
|
||||
commands::updater::get_config,
|
||||
commands::updater::save_config,
|
||||
commands::updater::check_for_update,
|
||||
commands::actions::check_privileges,
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user