update web

This commit is contained in:
2026-07-28 14:03:56 +07:00
parent a8bdd49072
commit 3a95456917
15 changed files with 575 additions and 171 deletions

84
web/src/lib.rs Normal file
View File

@@ -0,0 +1,84 @@
use gpui::*;
use ui::{Root, v_flex};
use universal_time::{
Duration, Instant, MonotonicClock, SystemTime, WallClock, define_time_provider,
};
use wasm_bindgen::prelude::*;
struct CustomTimeProvider;
impl WallClock for CustomTimeProvider {
fn system_time(&self) -> SystemTime {
SystemTime::from_unix_duration(Duration::from_secs(0))
}
}
impl MonotonicClock for CustomTimeProvider {
fn instant(&self) -> Instant {
Instant::from_ticks(Duration::from_secs(0))
}
}
define_time_provider!(CustomTimeProvider);
#[wasm_bindgen]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
// Initialize logging to browser console
console_log::init_with_level(log::Level::Info).expect("Failed to initialize logger");
// Also initialize tracing for WASM
tracing_wasm::set_as_global_default();
#[cfg(target_family = "wasm")]
gpui_platform::web_init();
#[cfg(not(target_family = "wasm"))]
let app = gpui_platform::application();
#[cfg(target_family = "wasm")]
let app = {
let app = gpui_platform::single_threaded_web();
// Temporary fix: intentionally leak the `Rc<AppCell>` to keep the application alive
struct WasmApplication(std::rc::Rc<AppCell>);
let wasm_app = unsafe { std::mem::transmute::<Application, WasmApplication>(app) };
std::mem::forget(wasm_app.0.clone());
unsafe { std::mem::transmute::<WasmApplication, Application>(wasm_app) }
};
app.run(|cx| {
// Initialize components
ui::init(cx);
// Initialize theme registry
theme::init(cx);
// Open the root window
cx.open_window(WindowOptions::default(), |window, cx| {
let view = cx.new(HelloWeb::new);
cx.new(|cx| Root::new(view.into(), window, cx))
})
.expect("Failed to open window. Please restart the application.");
cx.activate(true);
});
Ok(())
}
struct HelloWeb {}
impl HelloWeb {
fn new(_cx: &mut Context<Self>) -> Self {
Self {}
}
}
impl Render for HelloWeb {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.size_full()
.items_center()
.justify_center()
.child("Hello web")
}
}