From 0e2500c77fae872a3f313b0bfb581e91962336c3 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Wed, 12 Oct 2022 16:19:43 -0700 Subject: [PATCH] Revert to use web session --- Cargo.toml | 2 +- src/common/menu.rs | 17 ++++++++++++----- src/lib.rs | 2 +- src/static/js/training_modpack.js | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb7b424..e9a4f44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,4 +52,4 @@ plugin-dependencies = [ [features] outside_training_mode = [] -web_session = [] \ No newline at end of file +web_session_single_thread = [] \ No newline at end of file diff --git a/src/common/menu.rs b/src/common/menu.rs index f03b4df..69ae5e8 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -69,7 +69,9 @@ pub unsafe fn write_menu() { const MENU_CONF_PATH: &str = "sd:/TrainingModpack/training_modpack_menu.json"; pub unsafe fn set_menu_from_json(message: &str) { - if let Ok(message_json) = serde_json::from_str::(message) { + let web_response = serde_json::from_str::(message); + let tui_response = serde_json::from_str::(message); + if let Ok(message_json) = web_response { // Includes both MENU and DEFAULTS_MENU // From Web Applet MENU = message_json.menu; @@ -79,7 +81,7 @@ pub unsafe fn set_menu_from_json(message: &str) { serde_json::to_string_pretty(&message_json).unwrap(), ) .expect("Failed to write menu settings file"); - } else if let Ok(message_json) = serde_json::from_str::(message) { + } else if let Ok(message_json) = tui_response { // Only includes MENU // From TUI MENU = message_json; @@ -94,7 +96,7 @@ pub unsafe fn set_menu_from_json(message: &str) { skyline::error::show_error( 0x70, "Could not parse the menu response!\nPlease send a screenshot of the details page to the developers.\n\0", - message + &*format!("{:#?}\0", web_response.err().unwrap()) ); }; if MENU.quick_menu == OnOff::Off { @@ -118,12 +120,12 @@ pub fn spawn_menu() { frame_counter::start_counting(QUICK_MENU_FRAME_COUNTER_INDEX); if MENU.quick_menu == OnOff::Off { - #[cfg(feature = "web_session")] + #[cfg(not(feature = "web_session_single_thread"))] { WEB_MENU_ACTIVE = true; } - #[cfg(not(feature = "web_session"))] + #[cfg(feature = "web_session_single_thread")] { spawn_web_session(new_web_session(false)); } @@ -415,6 +417,11 @@ unsafe fn spawn_web_session(session: WebSession) { serde_json::to_string_pretty(&message_send).unwrap() ); session.show(); + let loaded_msg = session.recv(); + println!( + "[Training Modpack] Received loaded message from web:\n{}", + &loaded_msg + ); let message_recv = session.recv(); println!( "[Training Modpack] Received menu from web:\n{}", diff --git a/src/lib.rs b/src/lib.rs index 4310773..a901eda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,7 @@ pub fn main() { std::thread::spawn(|| unsafe { quick_menu_loop() }); - #[cfg(feature = "web_session")] + #[cfg(not(feature = "web_session_single_thread"))] if !is_emulator() { std::thread::spawn(|| unsafe { web_session_loop() }); } diff --git a/src/static/js/training_modpack.js b/src/static/js/training_modpack.js index 6b33084..c2397d3 100644 --- a/src/static/js/training_modpack.js +++ b/src/static/js/training_modpack.js @@ -30,6 +30,7 @@ if (isNx) { window.nx.footer.setAssign('ZR', '', cycleNextTab, { se: '' }); window.nx.footer.setAssign('ZL', '', cyclePrevTab, { se: '' }); window.nx.addEventListener("message", function(msg) { setSettingsFromJSON(msg)}); + window.nx.sendMessage("loaded"); } else { document.addEventListener('keypress', (event) => { switch (event.key) {