Skip to content

Commit

Permalink
fix web build
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 26, 2024
1 parent 57816de commit eb1d469
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,35 @@ fn main() -> eframe::Result {
// When compiling to web using trunk:
#[cfg(target_arch = "wasm32")]
fn main() {
use eframe::wasm_bindgen::JsCast as _;

// Redirect `log` message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

let web_options = eframe::WebOptions::default();

wasm_bindgen_futures::spawn_local(async {
let document = web_sys::window()
.expect("No window")
.document()
.expect("No document");

let canvas = document
.get_element_by_id("the_canvas_id")
.expect("Faield to find the_canvas_id")

Check warning on line 45 in demo/src/main.rs

View workflow job for this annotation

GitHub Actions / Spell Check

"Faield" should be "Failed".
.dyn_into::<web_sys::HtmlCanvasElement>()
.expect("the_canvas_id was not a HtmlCanvasElement");

let start_result = eframe::WebRunner::new()
.start(
"the_canvas_id",
canvas,
web_options,
Box::new(|cc| Ok(Box::new(demo::TemplateApp::new(cc)))),
)
.await;

// Remove the loading text and spinner:
let loading_text = web_sys::window()
.and_then(|w| w.document())
.and_then(|d| d.get_element_by_id("loading_text"));
if let Some(loading_text) = loading_text {
if let Some(loading_text) = document.get_element_by_id("loading_text") {
match start_result {
Ok(_) => {
loading_text.remove();
Expand Down

0 comments on commit eb1d469

Please sign in to comment.