aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src/core')
-rw-r--r--src-tauri/src/core/auth.rs28
-rw-r--r--src-tauri/src/core/downloader.rs51
-rw-r--r--src-tauri/src/core/manifest.rs8
-rw-r--r--src-tauri/src/core/mod.rs2
4 files changed, 85 insertions, 4 deletions
diff --git a/src-tauri/src/core/auth.rs b/src-tauri/src/core/auth.rs
new file mode 100644
index 0000000..39c4ce0
--- /dev/null
+++ b/src-tauri/src/core/auth.rs
@@ -0,0 +1,28 @@
+use serde::{Deserialize, Serialize};
+use std::sync::Mutex;
+use uuid::Uuid;
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct OfflineAccount {
+ pub username: String,
+ pub uuid: String,
+}
+
+pub struct AccountState {
+ pub active_account: Mutex<Option<OfflineAccount>>,
+}
+
+impl AccountState {
+ pub fn new() -> Self {
+ Self {
+ active_account: Mutex::new(None),
+ }
+ }
+}
+
+pub fn generate_offline_uuid(username: &str) -> String {
+ // Generate a UUID v3 (MD5-based) using the username as the name
+ // This provides a consistent UUID for the same username
+ let namespace = Uuid::NAMESPACE_OID;
+ Uuid::new_v3(&namespace, username.as_bytes()).to_string()
+}
diff --git a/src-tauri/src/core/downloader.rs b/src-tauri/src/core/downloader.rs
new file mode 100644
index 0000000..8d717be
--- /dev/null
+++ b/src-tauri/src/core/downloader.rs
@@ -0,0 +1,51 @@
+use std::path::PathBuf;
+use tokio::sync::mpsc;
+use serde::{Serialize, Deserialize};
+
+#[derive(Debug, Clone)]
+pub struct DownloadTask {
+ pub url: String,
+ pub path: PathBuf,
+ pub sha1: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum DownloadProgress {
+ Started(String),
+ Progress { file: String, downloaded: u64, total: u64 },
+ Finished(String),
+ Error(String, String),
+}
+
+pub struct Downloader {
+ sender: mpsc::Sender<DownloadProgress>,
+}
+
+impl Downloader {
+ pub fn new(sender: mpsc::Sender<DownloadProgress>) -> Self {
+ Self { sender }
+ }
+
+ pub async fn download(&self, tasks: Vec<DownloadTask>) {
+ // TODO: Implement parallel download with limits
+ // Use futures::stream::StreamExt::buffer_unordered
+
+ for task in tasks {
+ if let Err(_) = self.sender.send(DownloadProgress::Started(task.url.clone())).await {
+ break;
+ }
+
+ // Simulate download for now or implement basic
+ // Ensure directory exists
+ if let Some(parent) = task.path.parent() {
+ let _ = tokio::fs::create_dir_all(parent).await;
+ }
+
+ // Real implementation would use reqwest here
+
+ if let Err(_) = self.sender.send(DownloadProgress::Finished(task.url)).await {
+ break;
+ }
+ }
+ }
+}
diff --git a/src-tauri/src/core/manifest.rs b/src-tauri/src/core/manifest.rs
index 1450e77..11ebc5a 100644
--- a/src-tauri/src/core/manifest.rs
+++ b/src-tauri/src/core/manifest.rs
@@ -1,19 +1,19 @@
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use std::error::Error;
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct VersionManifest {
pub latest: Latest,
pub versions: Vec<Version>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct Latest {
pub release: String,
pub snapshot: String,
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct Version {
pub id: String,
#[serde(rename = "type")]
diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs
index 640fc64..320ab82 100644
--- a/src-tauri/src/core/mod.rs
+++ b/src-tauri/src/core/mod.rs
@@ -1 +1,3 @@
pub mod manifest;
+pub mod auth;
+pub mod downloader;