mirror of
https://github.com/hulthe/inkopslista.git
synced 2026-08-03 23:11:28 +02:00
Move wasm main to wasm.rs
This commit is contained in:
+2
-2
@@ -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};
|
||||
|
||||
+7
-10
@@ -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<Mutex<Config>>, app_weak: &slint::Weak<App>) {
|
||||
});
|
||||
}
|
||||
|
||||
#[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::<State>();
|
||||
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());
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||
pub fn main() {
|
||||
if let Err(e) = crate::run() {
|
||||
eprintln!("{e:?}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user