Feat: Implement Storage-based (JSON) Settings & Data-Storage (WIP) (#56)

This commit is contained in:
Youwes09
2026-04-29 00:18:09 -05:00
parent c009bd71fc
commit 170493aa71
23 changed files with 493 additions and 164 deletions
+54 -30
View File
@@ -2,18 +2,18 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Clone)]
pub struct ReleaseInfo {
pub tag_name: String,
pub name: String,
pub body: String,
pub tag_name: String,
pub name: String,
pub body: String,
pub published_at: String,
pub html_url: String,
pub html_url: String,
}
#[derive(Clone, Serialize)]
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
struct UpdateProgress {
downloaded: u64,
total: Option<u64>,
total: Option<u64>,
}
#[tauri::command]
@@ -22,11 +22,11 @@ pub async fn list_releases() -> Result<Vec<ReleaseInfo>, String> {
#[derive(Deserialize)]
struct GhRelease {
tag_name: String,
name: Option<String>,
body: Option<String>,
tag_name: String,
name: Option<String>,
body: Option<String>,
published_at: Option<String>,
html_url: String,
html_url: String,
}
let client = reqwest::Client::builder()
@@ -44,17 +44,20 @@ pub async fn list_releases() -> Result<Vec<ReleaseInfo>, String> {
return Err(format!("GitHub API returned {}", resp.status()));
}
let releases: Vec<GhRelease> = serde_json::from_str(
&resp.text().await.map_err(|e| e.to_string())?
).map_err(|e| e.to_string())?;
let releases: Vec<GhRelease> =
serde_json::from_str(&resp.text().await.map_err(|e| e.to_string())?)
.map_err(|e| e.to_string())?;
Ok(releases.into_iter().map(|r| ReleaseInfo {
tag_name: r.tag_name.clone(),
name: r.name.unwrap_or_else(|| r.tag_name.clone()),
body: r.body.unwrap_or_default(),
published_at: r.published_at.unwrap_or_default(),
html_url: r.html_url,
}).collect())
Ok(releases
.into_iter()
.map(|r| ReleaseInfo {
tag_name: r.tag_name.clone(),
name: r.name.unwrap_or_else(|| r.tag_name.clone()),
body: r.body.unwrap_or_default(),
published_at: r.published_at.unwrap_or_default(),
html_url: r.html_url,
})
.collect())
}
#[tauri::command]
@@ -70,9 +73,15 @@ pub async fn download_and_install_update(app: tauri::AppHandle, tag: String) ->
use tauri_plugin_http::reqwest;
#[derive(Deserialize)]
struct Asset { name: String, browser_download_url: String, size: u64 }
struct Asset {
name: String,
browser_download_url: String,
size: u64,
}
#[derive(Deserialize)]
struct Release { assets: Vec<Asset> }
struct Release {
assets: Vec<Asset>,
}
let client = reqwest::Client::builder()
.user_agent("Moku")
@@ -80,26 +89,41 @@ pub async fn download_and_install_update(app: tauri::AppHandle, tag: String) ->
.map_err(|e| e.to_string())?;
let resp = client
.get(format!("https://api.github.com/repos/moku-project/Moku/releases/tags/{}", tag))
.get(format!(
"https://api.github.com/repos/moku-project/Moku/releases/tags/{}",
tag
))
.send()
.await
.map_err(|e| e.to_string())?;
if !resp.status().is_success() {
return Err(format!("GitHub API returned {} for tag {}", resp.status(), tag));
return Err(format!(
"GitHub API returned {} for tag {}",
resp.status(),
tag
));
}
let release: Release = serde_json::from_str(
&resp.text().await.map_err(|e| e.to_string())?
).map_err(|e| e.to_string())?;
let release: Release = serde_json::from_str(&resp.text().await.map_err(|e| e.to_string())?)
.map_err(|e| e.to_string())?;
let asset = release.assets
let asset = release
.assets
.into_iter()
.find(|a| a.name.ends_with("_x64-setup.exe"))
.ok_or_else(|| format!("No x64-setup.exe asset found in release {}", tag))?;
let total = if asset.size > 0 { Some(asset.size) } else { None };
let mut resp = client.get(&asset.browser_download_url).send().await.map_err(|e| e.to_string())?;
let total = if asset.size > 0 {
Some(asset.size)
} else {
None
};
let mut resp = client
.get(&asset.browser_download_url)
.send()
.await
.map_err(|e| e.to_string())?;
let tmp_path = std::env::temp_dir().join(&asset.name);
let mut file = std::fs::File::create(&tmp_path).map_err(|e| e.to_string())?;
@@ -123,4 +147,4 @@ pub async fn download_and_install_update(app: tauri::AppHandle, tag: String) ->
Ok(())
}
}
}