From 894f5c5e2052d704fa957904207252a7d083dea2 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Sat, 3 Jan 2026 20:56:41 +0100 Subject: [PATCH] Move wasm main to wasm.rs --- gui/src/config.rs | 4 ++-- gui/src/lib.rs | 17 +++++++---------- gui/src/wasm.rs | 6 ++++++ 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 gui/src/wasm.rs diff --git a/gui/src/config.rs b/gui/src/config.rs index 96336db..6441329 100644 --- a/gui/src/config.rs +++ b/gui/src/config.rs @@ -13,10 +13,10 @@ impl Default for Config { } } -#[cfg(not(target_arch = "wasm32"))] +#[cfg(target_os = "linux")] pub use fs::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(target_os = "linux")] mod fs { use super::Config; use anyhow::{Context, Ok}; diff --git a/gui/src/lib.rs b/gui/src/lib.rs index d2f5c13..f20f162 100644 --- a/gui/src/lib.rs +++ b/gui/src/lib.rs @@ -1,7 +1,12 @@ // Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + mod config; mod runtime; + +#[cfg(target_arch = "wasm32")] +mod wasm; + use std::{ rc::Rc, sync::{Arc, Mutex}, @@ -76,21 +81,13 @@ fn refresh_list(conf: &Arc>, app_weak: &slint::Weak) { }); } -#[cfg(target_arch = "wasm32")] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen(start))] -pub fn main() { - if let Err(e) = run() { - eprintln!("{e:?}"); - } -} - pub fn run() -> Result<(), anyhow::Error> { let app = App::new()?; let state = app.global::(); let list_shared = Rc::new(VecModel::default()); state.set_list(ModelRc::new(list_shared.clone())); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(target_os = "linux")] let conf = runtime::RT .block_on(config::get_config()) .inspect_err(|err| eprintln!("{err:?}")) @@ -197,7 +194,7 @@ pub fn run() -> Result<(), anyhow::Error> { state.on_set_server_address(move |address| { conf_shared.lock().unwrap().address = address.to_string(); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(target_os = "linux")] let _ = config::save_config(address.to_string()); }); diff --git a/gui/src/wasm.rs b/gui/src/wasm.rs new file mode 100644 index 0000000..f7b55e5 --- /dev/null +++ b/gui/src/wasm.rs @@ -0,0 +1,6 @@ +#[wasm_bindgen::prelude::wasm_bindgen(start)] +pub fn main() { + if let Err(e) = crate::run() { + eprintln!("{e:?}"); + } +}