wasm-rdp/frontend/src/lib.rs

34 lines
782 B
Rust
Raw Normal View History

2021-11-01 13:36:38 +00:00
mod app;
2021-11-03 16:03:35 +00:00
mod components;
2021-11-01 16:30:23 +00:00
mod pages;
2021-11-01 16:58:24 +00:00
mod utils;
2021-11-01 13:36:38 +00:00
use wasm_bindgen::prelude::*;
2021-11-01 16:30:23 +00:00
use wasm_bindgen::JsCast;
use web_sys::{console, KeyboardEvent};
2021-11-01 13:36:38 +00:00
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
pub fn run_app() -> Result<(), JsValue> {
2021-11-01 16:30:23 +00:00
let window = web_sys::window().unwrap();
let handler_submit = move |e: KeyboardEvent| {
e.stop_propagation();
console::log_1(&format!("{:?}", e).into())
};
let handler = Box::new(handler_submit) as Box<dyn FnMut(_)>;
let cb = Closure::wrap(handler);
window
.add_event_listener_with_callback("keydown", cb.as_ref().unchecked_ref())
.unwrap();
cb.forget();
2021-11-01 13:36:38 +00:00
yew::start_app::<app::App>();
Ok(())
}