Skip to content

Commit ac50fa0

Browse files
authored
eframe web: Better panic handling (#2942)
* Refactor: remove extra store of events * Remove unnecessary extra function * Refactor: simplify event registering * Store panic summary * egui_demo_app: move web-part to own module * index.html: await * Properly unsubscribe from events on panic * Better error handling * Demo app html: hide the wasm canvas and show an error message on panic * egui_demo_app: add panic button to test panic response on web * fix typo * Use a constructor to create WebHandle * Refactor: less use of locks in the interfaces * More consistent naming
1 parent 7f2de42 commit ac50fa0

File tree

10 files changed

+680
-627
lines changed

10 files changed

+680
-627
lines changed

crates/eframe/src/lib.rs

+3-47
Original file line numberDiff line numberDiff line change
@@ -81,61 +81,17 @@ pub use epi::*;
8181
// ----------------------------------------------------------------------------
8282
// When compiling for web
8383

84-
#[cfg(target_arch = "wasm32")]
85-
pub mod web;
86-
8784
#[cfg(target_arch = "wasm32")]
8885
pub use wasm_bindgen;
8986

90-
#[cfg(target_arch = "wasm32")]
91-
use web::AppRunnerRef;
92-
9387
#[cfg(target_arch = "wasm32")]
9488
pub use web_sys;
9589

96-
/// Install event listeners to register different input events
97-
/// and start running the given app.
98-
///
99-
/// ``` no_run
100-
/// #[cfg(target_arch = "wasm32")]
101-
/// use wasm_bindgen::prelude::*;
102-
///
103-
/// /// This is the entry-point for all the web-assembly.
104-
/// /// This is called from the HTML.
105-
/// /// It loads the app, installs some callbacks, then returns.
106-
/// /// It returns a handle to the running app that can be stopped calling `AppRunner::stop_web`.
107-
/// /// You can add more callbacks like this if you want to call in to your code.
108-
/// #[cfg(target_arch = "wasm32")]
109-
/// #[wasm_bindgen]
110-
/// pub struct WebHandle {
111-
/// handle: AppRunnerRef,
112-
/// }
113-
/// #[cfg(target_arch = "wasm32")]
114-
/// #[wasm_bindgen]
115-
/// pub async fn start(canvas_id: &str) -> Result<WebHandle, eframe::wasm_bindgen::JsValue> {
116-
/// let web_options = eframe::WebOptions::default();
117-
/// eframe::start_web(
118-
/// canvas_id,
119-
/// web_options,
120-
/// Box::new(|cc| Box::new(MyEguiApp::new(cc))),
121-
/// )
122-
/// .await
123-
/// .map(|handle| WebHandle { handle })
124-
/// }
125-
/// ```
126-
///
127-
/// # Errors
128-
/// Failing to initialize WebGL graphics.
12990
#[cfg(target_arch = "wasm32")]
130-
pub async fn start_web(
131-
canvas_id: &str,
132-
web_options: WebOptions,
133-
app_creator: AppCreator,
134-
) -> std::result::Result<AppRunnerRef, wasm_bindgen::JsValue> {
135-
let handle = web::start(canvas_id, web_options, app_creator).await?;
91+
pub mod web;
13692

137-
Ok(handle)
138-
}
93+
#[cfg(target_arch = "wasm32")]
94+
pub use web::start_web;
13995

14096
// ----------------------------------------------------------------------------
14197
// When compiling natively

0 commit comments

Comments
 (0)