mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-22 14:26:11 +00:00
Revert to use web session
This commit is contained in:
parent
bb923b2124
commit
0e2500c77f
4 changed files with 15 additions and 7 deletions
|
@ -52,4 +52,4 @@ plugin-dependencies = [
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
outside_training_mode = []
|
outside_training_mode = []
|
||||||
web_session = []
|
web_session_single_thread = []
|
|
@ -69,7 +69,9 @@ pub unsafe fn write_menu() {
|
||||||
const MENU_CONF_PATH: &str = "sd:/TrainingModpack/training_modpack_menu.json";
|
const MENU_CONF_PATH: &str = "sd:/TrainingModpack/training_modpack_menu.json";
|
||||||
|
|
||||||
pub unsafe fn set_menu_from_json(message: &str) {
|
pub unsafe fn set_menu_from_json(message: &str) {
|
||||||
if let Ok(message_json) = serde_json::from_str::<MenuJsonStruct>(message) {
|
let web_response = serde_json::from_str::<MenuJsonStruct>(message);
|
||||||
|
let tui_response = serde_json::from_str::<TrainingModpackMenu>(message);
|
||||||
|
if let Ok(message_json) = web_response {
|
||||||
// Includes both MENU and DEFAULTS_MENU
|
// Includes both MENU and DEFAULTS_MENU
|
||||||
// From Web Applet
|
// From Web Applet
|
||||||
MENU = message_json.menu;
|
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(),
|
serde_json::to_string_pretty(&message_json).unwrap(),
|
||||||
)
|
)
|
||||||
.expect("Failed to write menu settings file");
|
.expect("Failed to write menu settings file");
|
||||||
} else if let Ok(message_json) = serde_json::from_str::<TrainingModpackMenu>(message) {
|
} else if let Ok(message_json) = tui_response {
|
||||||
// Only includes MENU
|
// Only includes MENU
|
||||||
// From TUI
|
// From TUI
|
||||||
MENU = message_json;
|
MENU = message_json;
|
||||||
|
@ -94,7 +96,7 @@ pub unsafe fn set_menu_from_json(message: &str) {
|
||||||
skyline::error::show_error(
|
skyline::error::show_error(
|
||||||
0x70,
|
0x70,
|
||||||
"Could not parse the menu response!\nPlease send a screenshot of the details page to the developers.\n\0",
|
"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 {
|
if MENU.quick_menu == OnOff::Off {
|
||||||
|
@ -118,12 +120,12 @@ pub fn spawn_menu() {
|
||||||
frame_counter::start_counting(QUICK_MENU_FRAME_COUNTER_INDEX);
|
frame_counter::start_counting(QUICK_MENU_FRAME_COUNTER_INDEX);
|
||||||
|
|
||||||
if MENU.quick_menu == OnOff::Off {
|
if MENU.quick_menu == OnOff::Off {
|
||||||
#[cfg(feature = "web_session")]
|
#[cfg(not(feature = "web_session_single_thread"))]
|
||||||
{
|
{
|
||||||
WEB_MENU_ACTIVE = true;
|
WEB_MENU_ACTIVE = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "web_session"))]
|
#[cfg(feature = "web_session_single_thread")]
|
||||||
{
|
{
|
||||||
spawn_web_session(new_web_session(false));
|
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()
|
serde_json::to_string_pretty(&message_send).unwrap()
|
||||||
);
|
);
|
||||||
session.show();
|
session.show();
|
||||||
|
let loaded_msg = session.recv();
|
||||||
|
println!(
|
||||||
|
"[Training Modpack] Received loaded message from web:\n{}",
|
||||||
|
&loaded_msg
|
||||||
|
);
|
||||||
let message_recv = session.recv();
|
let message_recv = session.recv();
|
||||||
println!(
|
println!(
|
||||||
"[Training Modpack] Received menu from web:\n{}",
|
"[Training Modpack] Received menu from web:\n{}",
|
||||||
|
|
|
@ -145,7 +145,7 @@ pub fn main() {
|
||||||
|
|
||||||
std::thread::spawn(|| unsafe { quick_menu_loop() });
|
std::thread::spawn(|| unsafe { quick_menu_loop() });
|
||||||
|
|
||||||
#[cfg(feature = "web_session")]
|
#[cfg(not(feature = "web_session_single_thread"))]
|
||||||
if !is_emulator() {
|
if !is_emulator() {
|
||||||
std::thread::spawn(|| unsafe { web_session_loop() });
|
std::thread::spawn(|| unsafe { web_session_loop() });
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ if (isNx) {
|
||||||
window.nx.footer.setAssign('ZR', '', cycleNextTab, { se: '' });
|
window.nx.footer.setAssign('ZR', '', cycleNextTab, { se: '' });
|
||||||
window.nx.footer.setAssign('ZL', '', cyclePrevTab, { se: '' });
|
window.nx.footer.setAssign('ZL', '', cyclePrevTab, { se: '' });
|
||||||
window.nx.addEventListener("message", function(msg) { setSettingsFromJSON(msg)});
|
window.nx.addEventListener("message", function(msg) { setSettingsFromJSON(msg)});
|
||||||
|
window.nx.sendMessage("loaded");
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener('keypress', (event) => {
|
document.addEventListener('keypress', (event) => {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue