summaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src')
-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
-rw-r--r--src-tauri/src/main.rs35
5 files changed, 119 insertions, 5 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;
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index fdd0794..402f58f 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1,6 +1,8 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
+use tauri::State;
+
mod core;
mod launcher;
@@ -23,10 +25,41 @@ async fn start_game() -> Result<String, String> {
}
}
+#[tauri::command]
+async fn get_versions() -> Result<Vec<core::manifest::Version>, String> {
+ match core::manifest::fetch_version_manifest().await {
+ Ok(manifest) => Ok(manifest.versions),
+ Err(e) => Err(e.to_string()),
+ }
+}
+
+#[tauri::command]
+async fn login_offline(
+ state: State<'_, core::auth::AccountState>,
+ username: String,
+) -> Result<core::auth::OfflineAccount, String> {
+ let uuid = core::auth::generate_offline_uuid(&username);
+ let account = core::auth::OfflineAccount {
+ username,
+ uuid,
+ };
+
+ *state.active_account.lock().unwrap() = Some(account.clone());
+ Ok(account)
+}
+
+#[tauri::command]
+async fn get_active_account(
+ state: State<'_, core::auth::AccountState>,
+) -> Result<Option<core::auth::OfflineAccount>, String> {
+ Ok(state.active_account.lock().unwrap().clone())
+}
+
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
- .invoke_handler(tauri::generate_handler![start_game])
+ .manage(core::auth::AccountState::new())
+ .invoke_handler(tauri::generate_handler![start_game, get_versions, login_offline, get_active_account])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}