Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui_web: Update example to use `run_embedded()` instead of `run()` (#63235)

Bowen Xu206a863a9508
diff --git a/crates/gpui_web/examples/hello_web/main.rs b/crates/gpui_web/examples/hello_web/main.rs
index abda6895cb0..31f30431e2a 100644
--- a/crates/gpui_web/examples/hello_web/main.rs
+++ b/crates/gpui_web/examples/hello_web/main.rs
@@ -1,9 +1,10 @@
use std::borrow::Cow;
+use std::cell::RefCell;
use gpui::prelude::*;
use gpui::{
- App, Bounds, Context, ElementId, SharedString, Task, Window, WindowBounds, WindowOptions, div,
- px, rgb, size,
+ App, ApplicationHandle, Bounds, Context, ElementId, SharedString, Task, Window, WindowBounds,
+ WindowOptions, div, px, rgb, size,
};
// ---------------------------------------------------------------------------
@@ -428,29 +429,36 @@ fn requested_backend() -> gpui_platform::WebBackendPreference {
}
}
+thread_local! {
+ static APPLICATION: RefCell<Option<ApplicationHandle>> = RefCell::new(None);
+}
+
fn main() {
gpui_platform::web_init();
- gpui_platform::application_with_web_backend(requested_backend()).run(|cx: &mut App| {
- if let Err(error) = cx
- .text_system()
- .add_fonts(vec![Cow::Borrowed(include_bytes!(
- "../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf"
- ))])
- {
- web_sys::console::error_1(
- &format!("failed to load application fonts: {error:#}").into(),
- );
- return;
- }
- let bounds = Bounds::centered(None, size(px(640.), px(560.)), cx);
- cx.open_window(
- WindowOptions {
- window_bounds: Some(WindowBounds::Windowed(bounds)),
- ..Default::default()
- },
- |_, cx| cx.new(HelloWeb::new),
- )
- .expect("failed to open window");
- cx.activate(true);
- });
+ let handle = gpui_platform::application_with_web_backend(requested_backend()).run_embedded(
+ |cx: &mut App| {
+ if let Err(error) = cx
+ .text_system()
+ .add_fonts(vec![Cow::Borrowed(include_bytes!(
+ "../../../../assets/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf"
+ ))])
+ {
+ web_sys::console::error_1(
+ &format!("failed to load application fonts: {error:#}").into(),
+ );
+ return;
+ }
+ let bounds = Bounds::centered(None, size(px(640.), px(560.)), cx);
+ cx.open_window(
+ WindowOptions {
+ window_bounds: Some(WindowBounds::Windowed(bounds)),
+ ..Default::default()
+ },
+ |_, cx| cx.new(HelloWeb::new),
+ )
+ .expect("failed to open window");
+ cx.activate(true);
+ },
+ );
+ APPLICATION.with(|cell| *cell.borrow_mut() = Some(handle));
}