Skip to content

Commit

Permalink
Fix wasm build
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Sep 29, 2024
1 parent db10b04 commit f31a23b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/egui_router/src/history/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type HistoryResult<T = ()> = Result<T, HistoryError>;
/// History error
#[derive(Debug, thiserror::Error)]
pub enum HistoryError {
/// Updating the browser history failed
#[cfg(target_arch = "wasm32")]
#[error("History error: {0:?}")]
JsError(wasm_bindgen::JsValue),
Expand Down
11 changes: 10 additions & 1 deletion fancy-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,20 @@ fn main() -> eframe::Result<()> {
// when compiling to web using trunk.
#[cfg(target_arch = "wasm32")]
fn main() {
use wasm_bindgen::JsCast;
let web_options = eframe::WebOptions::default();
let element = eframe::web_sys::window()
.expect("failed to get window")
.document()
.expect("failed to get document")
.get_element_by_id("canvas")
.expect("failed to get canvas element")
.dyn_into::<eframe::web_sys::HtmlCanvasElement>()
.unwrap();
wasm_bindgen_futures::spawn_local(async {
eframe::WebRunner::new()
.start(
"canvas",
element,
web_options,
Box::new(|a| {
egui_extras::install_image_loaders(&a.egui_ctx);
Expand Down

0 comments on commit f31a23b

Please sign in to comment.