Suspense start
This commit is contained in:
@@ -8,7 +8,6 @@ export async function write_config_js(config) {
|
|||||||
return await invoke("write_config", { config: config });
|
return await invoke("write_config", { config: config });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function load_config_js() {
|
export async function load_config_js() {
|
||||||
console.log("AHHAHAH")
|
return await invoke("load_config");
|
||||||
return invoke("load_config");
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
cslol_dir = "WHY U RK"
|
cslol_dir = ""
|
||||||
wad_dir = ""
|
wad_dir = "C:\\Riot Games\\League of Legends\\Game\\DATA\\FINAL\\Champions"
|
||||||
extract_dir = ""
|
extract_dir = ""
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ pub struct Config {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn init_config() {
|
pub async fn init_config() {
|
||||||
// Check if the config file exists asynchronously
|
|
||||||
if fs::metadata("config.toml").is_err() {
|
if fs::metadata("config.toml").is_err() {
|
||||||
let config = Config {
|
let config = Config {
|
||||||
cslol_dir: "".to_string(),
|
cslol_dir: "".to_string(),
|
||||||
@@ -23,21 +22,18 @@ pub async fn init_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn load_config() -> Config {
|
pub async fn load_config() -> Config {
|
||||||
let config = fs::read_to_string("config.toml")
|
let config = fs::read_to_string("config.toml")
|
||||||
.expect("Failed to read config.toml file");
|
.expect("Failed to read config.toml file");
|
||||||
print!("COMMAND \n{}", config);
|
|
||||||
toml::from_str(&config)
|
toml::from_str(&config)
|
||||||
.expect("Failed to parse config.toml file")
|
.expect("Failed to parse config.toml file")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn write_config(config: Config) {
|
pub async fn write_config(config: Config) {
|
||||||
// Serialize the config synchronously (no async TOML serializer by default)
|
|
||||||
let config_content = toml::to_string(&config)
|
let config_content = toml::to_string(&config)
|
||||||
.expect("Failed to serialize config");
|
.expect("Failed to serialize config");
|
||||||
|
|
||||||
// Write the config file asynchronously
|
|
||||||
fs::write("config.toml", config_content)
|
fs::write("config.toml", config_content)
|
||||||
.expect("Failed to write to config.toml file");
|
.expect("Failed to write to config.toml file");
|
||||||
}
|
}
|
||||||
11
src/app.rs
11
src/app.rs
@@ -1,9 +1,8 @@
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen_futures::spawn_local;
|
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
use yew_router::prelude::*;
|
use yew_router::prelude::*;
|
||||||
|
|
||||||
use crate::{config_settings::init_config, views::*};
|
use crate::views::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -27,10 +26,14 @@ pub enum Route {
|
|||||||
|
|
||||||
#[function_component(App)]
|
#[function_component(App)]
|
||||||
pub fn app() -> Html {
|
pub fn app() -> Html {
|
||||||
|
let fallback = html! {<div class="content" >{"Loading..."}</div>};
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<nav::Nav/>
|
<nav::Nav/>
|
||||||
<Switch<Route> render={switch} />
|
<Suspense {fallback}>
|
||||||
|
<Switch<Route> render={switch} />
|
||||||
|
</Suspense>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use std::f32::consts::E;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_wasm_bindgen::*;
|
use serde_wasm_bindgen::*;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
@@ -19,18 +17,14 @@ extern "C" {
|
|||||||
#[wasm_bindgen(js_name = write_config_js, catch)]
|
#[wasm_bindgen(js_name = write_config_js, catch)]
|
||||||
pub async fn write_config_js(config: JsValue) -> Result<JsValue, JsValue>;
|
pub async fn write_config_js(config: JsValue) -> Result<JsValue, JsValue>;
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = load_config_js)]
|
#[wasm_bindgen(js_name = load_config_js, catch)]
|
||||||
pub fn load_config_js() -> JsValue;
|
pub async fn load_config_js() -> Result<JsValue, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn write_config(config: Config) -> Result<JsValue, JsValue> {
|
pub async fn write_config(config: Config) -> Result<JsValue, JsValue> {
|
||||||
write_config_js(to_value(&config).unwrap()).await
|
write_config_js(to_value(&config).unwrap()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_config() -> Result<Config, Error> {
|
pub async fn load_config() -> Result<Config, Error> {
|
||||||
let serdeshit: Result<Config, Error> = from_value(load_config_js());
|
from_value(load_config_js().await.unwrap())
|
||||||
print!("{}", serdeshit.as_ref().expect("I Hate Js").cslol_dir);
|
}
|
||||||
serdeshit
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -4,9 +4,13 @@ mod views;
|
|||||||
mod config_settings;
|
mod config_settings;
|
||||||
|
|
||||||
use app::App;
|
use app::App;
|
||||||
|
use config_settings::init_config;
|
||||||
|
use yew::platform::spawn_local;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
yew::Renderer::<App>::new().render();
|
yew::Renderer::<App>::new().render();
|
||||||
|
spawn_local(async move {
|
||||||
|
init_config().await;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,42 @@
|
|||||||
use std::{cell::RefCell, rc::Rc};
|
use yew::suspense::use_future;
|
||||||
|
|
||||||
use crate::config_settings::*;
|
use crate::config_settings::*;
|
||||||
use wasm_bindgen_futures::spawn_local;
|
use wasm_bindgen_futures::spawn_local;
|
||||||
use web_sys::{console, HtmlInputElement};
|
use web_sys::HtmlInputElement;
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
#[function_component(Settings)]
|
#[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);
|
let config = config_future.as_ref().unwrap().clone();
|
||||||
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 cslol_dir_ref = use_node_ref();
|
let cslol_dir_ref = use_node_ref();
|
||||||
let wad_dir_ref = use_node_ref();
|
let wad_dir_ref = use_node_ref();
|
||||||
let extract_dir_ref = use_node_ref();
|
let extract_dir_ref = use_node_ref();
|
||||||
|
|
||||||
let on_submit = {
|
let on_submit = {
|
||||||
|
|
||||||
let cslol_dir_ref = cslol_dir_ref.clone();
|
let cslol_dir_ref = cslol_dir_ref.clone();
|
||||||
let wad_dir_ref = wad_dir_ref.clone();
|
let wad_dir_ref = wad_dir_ref.clone();
|
||||||
let extract_dir_ref = extract_dir_ref.clone();
|
let extract_dir_ref = extract_dir_ref.clone();
|
||||||
|
|
||||||
Callback::from(move |event: SubmitEvent| {
|
Callback::from(move |_event: SubmitEvent| {
|
||||||
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 wad_dir = wad_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
||||||
let extract_dir = extract_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
let extract_dir = extract_dir_ref.cast::<HtmlInputElement>().unwrap().value();
|
||||||
|
|
||||||
if let Some(cslol_dir) = cslol_dir {
|
let config = Config {
|
||||||
config.cslol_dir = cslol_dir.value();
|
cslol_dir,
|
||||||
config_handle.set(config.clone());
|
wad_dir,
|
||||||
}
|
extract_dir,
|
||||||
|
};
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
write_config(config.clone()).await.unwrap();
|
write_config(config).await.unwrap();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
console::log_1(&"SCREMING".into());
|
Ok(
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h2>{"Settings"}</h2>
|
<h2>{"Settings"}</h2>
|
||||||
@@ -62,19 +45,19 @@ pub fn settings() -> Html {
|
|||||||
<div>
|
<div>
|
||||||
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
<label for="cslol_dir">{"Location of CSLoL"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input id="cslol_dir" ref={cslol_dir_ref} value={config.cslol_dir}/>
|
<input id="cslol_dir" ref={cslol_dir_ref} value={config.cslol_dir.clone()}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
<label for="wad_dir">{"Custom location of Champion Wads"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input id="wad_dir" ref={wad_dir_ref} />
|
<input id="wad_dir" ref={wad_dir_ref} value={config.wad_dir.clone()}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="extract_dir">{"Custom location to Extract to"}</label>
|
<label for="extract_dir">{"Custom location to Extract to"}</label>
|
||||||
<br/>
|
<br/>
|
||||||
<input id="extract_dir" ref={extract_dir_ref} />
|
<input id="extract_dir" ref={extract_dir_ref} value={config.extract_dir.clone()}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -83,4 +66,5 @@ pub fn settings() -> Html {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user