diff --git a/Cargo.lock b/Cargo.lock index 15f5f2a..40933d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "toml", "winit", "wry", ] @@ -924,7 +925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ "heck 0.4.1", - "proc-macro-crate 2.0.2", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote", @@ -1495,7 +1496,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 2.0.2", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.100", @@ -2072,11 +2073,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] @@ -2811,21 +2811,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.22.24", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] @@ -2838,7 +2838,7 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap 2.8.0", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] @@ -2846,12 +2846,23 @@ name = "toml_edit" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.8.0", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap 2.8.0", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.7.4", ] [[package]] @@ -3653,6 +3664,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36" +dependencies = [ + "memchr", +] + [[package]] name = "wit-bindgen-rt" version = "0.33.0" diff --git a/Cargo.toml b/Cargo.toml index 3601a06..939374b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,5 @@ tokio = { version = "1", features = ["full"] } dirs = "6.0.0" rand = "0.9.0" serde = { version = "1.0.219", features = ["derive"] } -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +toml = "0.8.20" \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 8d0d344..bf67ca7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,12 @@ use std::path::PathBuf; -#[derive(Default)] +use serde::{Deserialize, Serialize}; + +#[derive(Default, Serialize, Deserialize)] pub struct LauncherConfig { - is_portable: bool + is_portable: bool, + pub user_name: String, + pub user_secret: String } impl LauncherConfig { diff --git a/src/launcher.rs b/src/launcher.rs index 19fa603..08fe3ff 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -1,3 +1,5 @@ +use core::str; + use crate::config::LauncherConfig; @@ -16,6 +18,24 @@ impl Launcher { self.config.config_path().exists() } + pub fn load_config(&mut self) { + if self.is_config_exist() { + self.config = toml::from_str( + str::from_utf8(&std::fs::read(self.config.config_path()).unwrap()).unwrap()).unwrap(); + } + } + + pub fn save_config(&self) { + std::fs::write(self.config.config_path(), toml::to_string_pretty(&self.config).unwrap()); + } + + pub fn init_config(&mut self, user_name: String) { + self.load_config(); + self.config.user_name = user_name; + self.config.user_secret = crate::util::random_string(32); + self.save_config(); + } + pub fn init_dirs(&self) { let root = self.config.launcher_dir(); std::fs::create_dir_all(&root); diff --git a/src/main.rs b/src/main.rs index 28d190b..e22268c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,6 @@ impl ApplicationHandler for App { let webview = WebViewBuilder::new() .with_asynchronous_custom_protocol("xcraft".into(), move |wid, request, responder| { let uri = request.uri().to_string(); - println!("Body: {}", String::from_utf8(request.body().to_vec()).unwrap()); if let Ok(msg) = serde_json::from_slice(request.body()) { let _ = SENDER.lock().unwrap().as_ref().unwrap().send((uri, Some(msg), responder)); return; @@ -89,23 +88,27 @@ async fn main() { "portable" => { launcher.config.set_portable(true); launcher.init_dirs(); + responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap())) } "installation" => { launcher.init_dirs(); + responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap())) } "check_installation" => { if launcher.is_portable() { launcher.config.set_portable(true); launcher.init_dirs(); if !launcher.is_config_exist() { - responder.respond(Response::new("show_login".as_bytes())) + responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_login".to_string()] }).unwrap())) } else { - responder.respond(Response::new("show_add".as_bytes())) + responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_add".to_string(), "sidebar_on".to_string()] }).unwrap())) } } } "sign_up" => { - + let user_name = params.as_ref().unwrap().params.get(0).unwrap(); + launcher.init_config(user_name.to_string()); + responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_add".to_string(), "sidebar_on".to_string()] }).unwrap())); } _ => {} } diff --git a/src/www/portable.html b/src/www/portable.html index 91da5f2..b8f106a 100644 --- a/src/www/portable.html +++ b/src/www/portable.html @@ -84,7 +84,23 @@ + +
  • + + + + +
  • +
  • CraftX v1.0 - - + +