diff --git a/public/glue.js b/public/glue.js index e15b9a9..e3bd0b5 100644 --- a/public/glue.js +++ b/public/glue.js @@ -8,7 +8,6 @@ export async function write_config_js(config) { return await invoke("write_config", { config: config }); } -export function load_config_js() { - console.log("AHHAHAH") - return invoke("load_config"); +export async function load_config_js() { + return await invoke("load_config"); } \ No newline at end of file diff --git a/src-tauri/config.toml b/src-tauri/config.toml index 41c2581..0b1e7dc 100644 --- a/src-tauri/config.toml +++ b/src-tauri/config.toml @@ -1,3 +1,3 @@ -cslol_dir = "WHY U RK" -wad_dir = "" +cslol_dir = "" +wad_dir = "C:\\Riot Games\\League of Legends\\Game\\DATA\\FINAL\\Champions" extract_dir = "" diff --git a/src-tauri/src/config_settings.rs b/src-tauri/src/config_settings.rs index d7f3c11..1eb06de 100644 --- a/src-tauri/src/config_settings.rs +++ b/src-tauri/src/config_settings.rs @@ -11,7 +11,6 @@ pub struct Config { #[tauri::command] pub async fn init_config() { - // Check if the config file exists asynchronously if fs::metadata("config.toml").is_err() { let config = Config { cslol_dir: "".to_string(), @@ -23,21 +22,18 @@ pub async fn init_config() { } #[tauri::command] -pub fn load_config() -> Config { +pub async fn load_config() -> Config { let config = fs::read_to_string("config.toml") .expect("Failed to read config.toml file"); - print!("COMMAND \n{}", config); toml::from_str(&config) .expect("Failed to parse config.toml file") } #[tauri::command] pub async fn write_config(config: Config) { - // Serialize the config synchronously (no async TOML serializer by default) let config_content = toml::to_string(&config) .expect("Failed to serialize config"); - // Write the config file asynchronously fs::write("config.toml", config_content) .expect("Failed to write to config.toml file"); } \ No newline at end of file diff --git a/src/app.rs b/src/app.rs index a808485..8c3bc36 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,9 +1,8 @@ use wasm_bindgen::prelude::*; -use wasm_bindgen_futures::spawn_local; use yew::prelude::*; use yew_router::prelude::*; -use crate::{config_settings::init_config, views::*}; +use crate::views::*; #[wasm_bindgen] extern "C" { @@ -27,10 +26,14 @@ pub enum Route { #[function_component(App)] pub fn app() -> Html { + let fallback = html! {
{"Loading..."}
}; + html! { - - render={switch} /> + + + render={switch} /> + } } diff --git a/src/config_settings.rs b/src/config_settings.rs index 3d395b5..cacb855 100644 --- a/src/config_settings.rs +++ b/src/config_settings.rs @@ -1,5 +1,3 @@ -use std::f32::consts::E; - use serde::{Deserialize, Serialize}; use serde_wasm_bindgen::*; use wasm_bindgen::prelude::*; @@ -19,18 +17,14 @@ extern "C" { #[wasm_bindgen(js_name = write_config_js, catch)] pub async fn write_config_js(config: JsValue) -> Result; - #[wasm_bindgen(js_name = load_config_js)] - pub fn load_config_js() -> JsValue; + #[wasm_bindgen(js_name = load_config_js, catch)] + pub async fn load_config_js() -> Result; } pub async fn write_config(config: Config) -> Result { write_config_js(to_value(&config).unwrap()).await } -pub fn load_config() -> Result { - let serdeshit: Result = from_value(load_config_js()); - print!("{}", serdeshit.as_ref().expect("I Hate Js").cslol_dir); - serdeshit -} - - +pub async fn load_config() -> Result { + from_value(load_config_js().await.unwrap()) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 0b1d961..2c2a721 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,13 @@ mod views; mod config_settings; use app::App; +use config_settings::init_config; +use yew::platform::spawn_local; fn main() { - console_error_panic_hook::set_once(); yew::Renderer::::new().render(); + spawn_local(async move { + init_config().await; + }) } diff --git a/src/views/settings.rs b/src/views/settings.rs index 921858f..780ee7b 100644 --- a/src/views/settings.rs +++ b/src/views/settings.rs @@ -1,59 +1,42 @@ -use std::{cell::RefCell, rc::Rc}; - +use yew::suspense::use_future; use crate::config_settings::*; use wasm_bindgen_futures::spawn_local; -use web_sys::{console, HtmlInputElement}; +use web_sys::HtmlInputElement; use yew::prelude::*; #[function_component(Settings)] -pub fn settings() -> Html { +pub fn settings() -> HtmlResult { + let config_future = use_future(|| async {load_config().await})?; - let config_handle = use_state(Config::default); - config_handle.set(load_config().unwrap()); - - // { - // let config_handle = config_handle.clone(); - - // use_effect(move || { - // spawn_local(async move { - // init_config().await.unwrap(); - // }) - // }); - // } - - let config = (*config_handle).clone(); + let config = config_future.as_ref().unwrap().clone(); let cslol_dir_ref = use_node_ref(); let wad_dir_ref = use_node_ref(); let extract_dir_ref = use_node_ref(); let on_submit = { - let cslol_dir_ref = cslol_dir_ref.clone(); let wad_dir_ref = wad_dir_ref.clone(); let extract_dir_ref = extract_dir_ref.clone(); - Callback::from(move |event: SubmitEvent| { - let mut config = (*config_handle).clone(); - - - let cslol_dir = cslol_dir_ref.cast::(); + Callback::from(move |_event: SubmitEvent| { + let cslol_dir = cslol_dir_ref.cast::().unwrap().value(); let wad_dir = wad_dir_ref.cast::().unwrap().value(); let extract_dir = extract_dir_ref.cast::().unwrap().value(); - if let Some(cslol_dir) = cslol_dir { - config.cslol_dir = cslol_dir.value(); - config_handle.set(config.clone()); - } + let config = Config { + cslol_dir, + wad_dir, + extract_dir, + }; spawn_local(async move { - write_config(config.clone()).await.unwrap(); + write_config(config).await.unwrap(); }); }) }; - console::log_1(&"SCREMING".into()); - + Ok( html! {

{"Settings"}

@@ -62,19 +45,19 @@ pub fn settings() -> Html {

- +

- +

- +
@@ -83,4 +66,5 @@ pub fn settings() -> Html {
} +) }