removed async on load
This commit is contained in:
@@ -8,6 +8,7 @@ export async function write_config_js(config) {
|
||||
return await invoke("write_config", { config: config });
|
||||
}
|
||||
|
||||
export async function load_config_js() {
|
||||
return await invoke("load_config");
|
||||
export function load_config_js() {
|
||||
console.log("AHHAHAH")
|
||||
return invoke("load_config");
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
cslol_dir = "WHY U FUCK NO WORK"
|
||||
cslol_dir = "WHY U RK"
|
||||
wad_dir = ""
|
||||
extract_dir = ""
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use tokio::fs;
|
||||
use std::fs;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -12,23 +12,21 @@ pub struct Config {
|
||||
#[tauri::command]
|
||||
pub async fn init_config() {
|
||||
// Check if the config file exists asynchronously
|
||||
if fs::metadata("config.toml").await.is_err() {
|
||||
if fs::metadata("config.toml").is_err() {
|
||||
let config = Config {
|
||||
cslol_dir: "".to_string(),
|
||||
wad_dir: "C:\\Riot Games\\League of Legends\\Game\\DATA\\FINAL\\Champions".to_string(),
|
||||
extract_dir: "".to_string(),
|
||||
};
|
||||
write_config(config).await; // Call the async version of write_config
|
||||
write_config(config).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn load_config() -> Config {
|
||||
// Read the config file asynchronously
|
||||
let config = fs::read_to_string("config.toml").await
|
||||
pub fn load_config() -> Config {
|
||||
let config = fs::read_to_string("config.toml")
|
||||
.expect("Failed to read config.toml file");
|
||||
|
||||
// Parse the config synchronously as before (no async TOML parser by default)
|
||||
print!("COMMAND \n{}", config);
|
||||
toml::from_str(&config)
|
||||
.expect("Failed to parse config.toml file")
|
||||
}
|
||||
@@ -40,6 +38,6 @@ pub async fn write_config(config: Config) {
|
||||
.expect("Failed to serialize config");
|
||||
|
||||
// Write the config file asynchronously
|
||||
fs::write("config.toml", config_content).await
|
||||
fs::write("config.toml", config_content)
|
||||
.expect("Failed to write to config.toml file");
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::f32::consts::E;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_wasm_bindgen::to_value;
|
||||
use serde_wasm_bindgen::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
@@ -17,16 +19,18 @@ extern "C" {
|
||||
#[wasm_bindgen(js_name = write_config_js, catch)]
|
||||
pub async fn write_config_js(config: JsValue) -> Result<JsValue, JsValue>;
|
||||
|
||||
#[wasm_bindgen(js_name = load_config_js, catch)]
|
||||
pub async fn load_config_js() -> Result<JsValue, JsValue>;
|
||||
#[wasm_bindgen(js_name = load_config_js)]
|
||||
pub fn load_config_js() -> JsValue;
|
||||
}
|
||||
|
||||
pub async fn write_config(config: Config) -> Result<JsValue, JsValue> {
|
||||
write_config_js(to_value(&config).unwrap()).await
|
||||
}
|
||||
|
||||
pub async fn load_config() -> Result<Config, JsValue> {
|
||||
Ok(serde_wasm_bindgen::from_value(load_config_js().await.unwrap()).unwrap())
|
||||
pub fn load_config() -> Result<Config, Error> {
|
||||
let serdeshit: Result<Config, Error> = from_value(load_config_js());
|
||||
print!("{}", serdeshit.as_ref().expect("I Hate Js").cslol_dir);
|
||||
serdeshit
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,55 +8,51 @@ use yew::prelude::*;
|
||||
#[function_component(Settings)]
|
||||
pub fn settings() -> Html {
|
||||
|
||||
let config = Rc::new(RefCell::new(Config::default()));
|
||||
{
|
||||
let config = config.clone();
|
||||
let config_handle = use_state(Config::default);
|
||||
config_handle.set(load_config().unwrap());
|
||||
|
||||
use_effect(move || {
|
||||
spawn_local(async move {
|
||||
init_config().await.unwrap();
|
||||
*config.borrow_mut() = load_config().await.unwrap();
|
||||
console::log_1(&config.borrow().cslol_dir.clone().into());
|
||||
})
|
||||
})
|
||||
// {
|
||||
// let config_handle = config_handle.clone();
|
||||
|
||||
// spawn_local(async move {
|
||||
// init_config().await.unwrap();
|
||||
// *config.borrow_mut() = load_config().await.unwrap();
|
||||
// console::log_1(&config.borrow().cslol_dir.clone().into());
|
||||
// })
|
||||
}
|
||||
// use_effect(move || {
|
||||
// spawn_local(async move {
|
||||
// init_config().await.unwrap();
|
||||
// })
|
||||
// });
|
||||
// }
|
||||
|
||||
let config = (*config_handle).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| {
|
||||
event.prevent_default();
|
||||
let mut config = (*config_handle).clone();
|
||||
|
||||
let cslol_dir = cslol_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
||||
|
||||
let cslol_dir = cslol_dir_ref.cast::<HtmlInputElement>();
|
||||
let wad_dir = wad_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
||||
let extract_dir = extract_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
||||
|
||||
let config = Config {
|
||||
cslol_dir,
|
||||
wad_dir,
|
||||
extract_dir,
|
||||
};
|
||||
if let Some(cslol_dir) = cslol_dir {
|
||||
config.cslol_dir = cslol_dir.value();
|
||||
config_handle.set(config.clone());
|
||||
}
|
||||
|
||||
spawn_local(async move {
|
||||
write_config(config).await.unwrap();
|
||||
write_config(config.clone()).await.unwrap();
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
let mut tconfig = config.try_borrow().unwrap().clone();
|
||||
console::log_1(&tconfig.cslol_dir.clone().into());
|
||||
console::log_1(&"IM MAD".into());
|
||||
|
||||
console::log_1(&"SCREMING".into());
|
||||
|
||||
html! {
|
||||
<div class="content">
|
||||
@@ -66,7 +62,7 @@ pub fn settings() -> Html {
|
||||
<div>
|
||||
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
||||
<br/>
|
||||
<input id="cslol_dir" ref={cslol_dir_ref} value={tconfig.cslol_dir.clone()}/>
|
||||
<input id="cslol_dir" ref={cslol_dir_ref} value={config.cslol_dir}/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user