2026-03-11 13:52:13 +00:00
|
|
|
#![cfg(feature = "servo-embed")]
|
|
|
|
|
|
2026-03-11 16:52:37 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2026-03-11 13:52:13 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
|
|
use servo::{
|
2026-03-11 16:52:37 +00:00
|
|
|
EventLoopWaker, InputEvent, MouseButton as ServoMouseButton, MouseButtonAction,
|
|
|
|
|
MouseButtonEvent, MouseMoveEvent, ServoBuilder, ServoDelegate, ServoUrl, UserContentManager,
|
|
|
|
|
UserScript, WebViewBuilder, WebViewDelegate,
|
2026-03-11 13:52:13 +00:00
|
|
|
};
|
|
|
|
|
use winit::{
|
|
|
|
|
application::ApplicationHandler,
|
2026-03-11 16:52:37 +00:00
|
|
|
event::{ElementState, MouseButton, WindowEvent},
|
2026-03-11 13:52:13 +00:00
|
|
|
event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy},
|
2026-03-11 16:52:37 +00:00
|
|
|
keyboard::ModifiersState,
|
2026-03-11 13:52:13 +00:00
|
|
|
window::{Window, WindowAttributes, WindowId},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ── Event loop waker ──────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
struct WeftEventLoopWaker {
|
|
|
|
|
proxy: Arc<Mutex<EventLoopProxy<ServoWake>>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
struct ServoWake;
|
|
|
|
|
|
|
|
|
|
impl EventLoopWaker for WeftEventLoopWaker {
|
|
|
|
|
fn clone_box(&self) -> Box<dyn EventLoopWaker> {
|
|
|
|
|
Box::new(self.clone())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn wake(&self) {
|
|
|
|
|
let _ = self
|
|
|
|
|
.proxy
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap_or_else(|p| p.into_inner())
|
|
|
|
|
.send_event(ServoWake);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Servo delegate ────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
struct WeftServoDelegate;
|
|
|
|
|
|
|
|
|
|
impl ServoDelegate for WeftServoDelegate {
|
|
|
|
|
fn notify_error(&self, error: servo::ServoError) {
|
|
|
|
|
tracing::error!(?error, "Servo error");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── WebView delegate ──────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
struct WeftWebViewDelegate {
|
|
|
|
|
redraw_requested: Arc<std::sync::atomic::AtomicBool>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WebViewDelegate for WeftWebViewDelegate {
|
|
|
|
|
fn notify_new_frame_ready(&self, _webview: servo::WebView) {
|
|
|
|
|
self.redraw_requested
|
|
|
|
|
.store(true, std::sync::atomic::Ordering::Relaxed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:06:02 +00:00
|
|
|
// ── Rendering context abstraction (GAP-2) ───────────────────────────────────
|
|
|
|
|
|
|
|
|
|
enum RenderingCtx {
|
|
|
|
|
Software(Rc<servo::SoftwareRenderingContext>),
|
|
|
|
|
Egl(Rc<servo::WindowRenderingContext>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RenderingCtx {
|
|
|
|
|
fn as_dyn(&self) -> Rc<dyn servo::RenderingContext> {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Software(rc) => Rc::clone(rc) as Rc<dyn servo::RenderingContext>,
|
|
|
|
|
Self::Egl(rc) => Rc::clone(rc) as Rc<dyn servo::RenderingContext>,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 13:52:13 +00:00
|
|
|
// ── Application state ─────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
|
url: ServoUrl,
|
2026-03-11 16:52:37 +00:00
|
|
|
ws_port: u16,
|
2026-03-11 13:52:13 +00:00
|
|
|
window: Option<Arc<Window>>,
|
|
|
|
|
servo: Option<servo::Servo>,
|
|
|
|
|
webview: Option<servo::WebView>,
|
2026-03-11 17:06:02 +00:00
|
|
|
rendering_context: Option<RenderingCtx>,
|
2026-03-11 13:52:13 +00:00
|
|
|
redraw_requested: Arc<std::sync::atomic::AtomicBool>,
|
|
|
|
|
waker: WeftEventLoopWaker,
|
|
|
|
|
shutting_down: bool,
|
2026-03-11 16:52:37 +00:00
|
|
|
modifiers: ModifiersState,
|
|
|
|
|
cursor_pos: servo::euclid::default::Point2D<f32>,
|
2026-03-11 19:46:53 +00:00
|
|
|
shell_client: Option<crate::shell_client::ShellClient>,
|
2026-03-11 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl App {
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
fn new(
|
|
|
|
|
url: ServoUrl,
|
|
|
|
|
waker: WeftEventLoopWaker,
|
|
|
|
|
ws_port: u16,
|
2026-03-11 19:46:53 +00:00
|
|
|
shell_client: Option<crate::shell_client::ShellClient>,
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
) -> Self {
|
2026-03-11 13:52:13 +00:00
|
|
|
Self {
|
|
|
|
|
url,
|
2026-03-11 16:52:37 +00:00
|
|
|
ws_port,
|
2026-03-11 13:52:13 +00:00
|
|
|
window: None,
|
|
|
|
|
servo: None,
|
|
|
|
|
webview: None,
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
rendering_context: None,
|
2026-03-11 13:52:13 +00:00
|
|
|
redraw_requested: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
|
|
|
|
waker,
|
|
|
|
|
shutting_down: false,
|
2026-03-11 16:52:37 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
|
|
|
|
cursor_pos: servo::euclid::default::Point2D::zero(),
|
2026-03-11 19:46:53 +00:00
|
|
|
shell_client,
|
2026-03-11 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:06:02 +00:00
|
|
|
fn render_frame(window: &Arc<Window>, ctx: &RenderingCtx) {
|
|
|
|
|
match ctx {
|
|
|
|
|
RenderingCtx::Software(rc) => Self::blit_software(window, rc),
|
|
|
|
|
RenderingCtx::Egl(_) => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn blit_software(window: &Arc<Window>, rendering_context: &servo::SoftwareRenderingContext) {
|
2026-03-11 13:52:13 +00:00
|
|
|
let size = window.inner_size();
|
|
|
|
|
let Some(pixels) = rendering_context.read_pixels() else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
let ctx = softbuffer::Context::new(Arc::clone(window)).expect("softbuffer context");
|
|
|
|
|
let mut surface =
|
|
|
|
|
softbuffer::Surface::new(&ctx, Arc::clone(window)).expect("softbuffer surface");
|
|
|
|
|
let _ = surface.resize(
|
|
|
|
|
std::num::NonZeroU32::new(size.width).unwrap_or(std::num::NonZeroU32::new(1).unwrap()),
|
|
|
|
|
std::num::NonZeroU32::new(size.height).unwrap_or(std::num::NonZeroU32::new(1).unwrap()),
|
|
|
|
|
);
|
|
|
|
|
let Ok(mut buf) = surface.buffer_mut() else {
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
for (dst, src) in buf.iter_mut().zip(pixels.chunks(4)) {
|
|
|
|
|
*dst = u32::from_be_bytes([0, src[0], src[1], src[2]]);
|
|
|
|
|
}
|
|
|
|
|
let _ = buf.present();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ApplicationHandler<ServoWake> for App {
|
|
|
|
|
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
|
|
|
|
if self.window.is_some() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let attrs = WindowAttributes::default().with_title("WEFT Shell");
|
|
|
|
|
let window = Arc::new(
|
|
|
|
|
event_loop
|
|
|
|
|
.create_window(attrs)
|
|
|
|
|
.expect("failed to create shell window"),
|
|
|
|
|
);
|
|
|
|
|
let size = window.inner_size();
|
|
|
|
|
self.window = Some(Arc::clone(&window));
|
|
|
|
|
|
|
|
|
|
let servo = ServoBuilder::default()
|
|
|
|
|
.event_loop_waker(Box::new(self.waker.clone()))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
servo.set_delegate(Rc::new(WeftServoDelegate));
|
|
|
|
|
|
2026-03-11 17:06:02 +00:00
|
|
|
let rendering_context = build_rendering_ctx(event_loop, &window, size);
|
2026-03-11 13:52:13 +00:00
|
|
|
|
2026-03-11 16:52:37 +00:00
|
|
|
let user_content_manager = Rc::new(UserContentManager::new(&servo));
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
if let Some(kit_js) = load_ui_kit_script() {
|
|
|
|
|
user_content_manager.add_script(Rc::new(UserScript::new(kit_js, None)));
|
|
|
|
|
}
|
2026-03-11 16:52:37 +00:00
|
|
|
let bridge_js = format!(
|
|
|
|
|
r#"(function(){{var ws=new WebSocket('ws://127.0.0.1:{p}');var q=[];var r=false;ws.onopen=function(){{r=true;q.forEach(function(m){{ws.send(JSON.stringify(m))}});q.length=0}};window.weftIpc={{send:function(m){{if(r)ws.send(JSON.stringify(m));else q.push(m)}},onmessage:null}};ws.onmessage=function(e){{if(window.weftIpc.onmessage)window.weftIpc.onmessage(JSON.parse(e.data))}}}})()"#,
|
|
|
|
|
p = self.ws_port
|
|
|
|
|
);
|
|
|
|
|
user_content_manager.add_script(Rc::new(UserScript::new(bridge_js, None)));
|
|
|
|
|
|
2026-03-11 17:06:02 +00:00
|
|
|
let webview = WebViewBuilder::new(&servo, rendering_context.as_dyn())
|
2026-03-11 13:52:13 +00:00
|
|
|
.delegate(Rc::new(WeftWebViewDelegate {
|
|
|
|
|
redraw_requested: Arc::clone(&self.redraw_requested),
|
|
|
|
|
}))
|
2026-03-11 16:52:37 +00:00
|
|
|
.user_content_manager(Rc::clone(&user_content_manager))
|
2026-03-11 13:52:13 +00:00
|
|
|
.url(self.url.clone())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
self.servo = Some(servo);
|
|
|
|
|
self.webview = Some(webview);
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
self.rendering_context = Some(rendering_context);
|
2026-03-11 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn user_event(&mut self, _event_loop: &ActiveEventLoop, _event: ServoWake) {
|
|
|
|
|
if let Some(servo) = &self.servo {
|
|
|
|
|
servo.spin_event_loop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
|
|
|
|
|
if self.shutting_down {
|
|
|
|
|
event_loop.exit();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-11 19:46:53 +00:00
|
|
|
if let Some(sc) = &mut self.shell_client {
|
|
|
|
|
match sc.dispatch_pending() {
|
|
|
|
|
Ok(false) => {
|
|
|
|
|
self.shutting_down = true;
|
|
|
|
|
if let Some(servo) = &self.servo {
|
|
|
|
|
servo.start_shutting_down();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(e) => tracing::warn!("shell client dispatch error: {e}"),
|
|
|
|
|
Ok(true) => {}
|
|
|
|
|
}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
let gestures = sc.take_pending_gestures();
|
|
|
|
|
if !gestures.is_empty() {
|
|
|
|
|
let ws_port = self.ws_port;
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
forward_gestures_to_appd(ws_port, &gestures);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-11 19:46:53 +00:00
|
|
|
}
|
2026-03-11 13:52:13 +00:00
|
|
|
if let Some(servo) = &self.servo {
|
|
|
|
|
servo.spin_event_loop();
|
|
|
|
|
}
|
|
|
|
|
if self
|
|
|
|
|
.redraw_requested
|
|
|
|
|
.swap(false, std::sync::atomic::Ordering::Relaxed)
|
|
|
|
|
{
|
|
|
|
|
if let Some(w) = &self.window {
|
|
|
|
|
w.request_redraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn window_event(
|
|
|
|
|
&mut self,
|
|
|
|
|
event_loop: &ActiveEventLoop,
|
|
|
|
|
_window_id: WindowId,
|
|
|
|
|
event: WindowEvent,
|
|
|
|
|
) {
|
|
|
|
|
match event {
|
|
|
|
|
WindowEvent::RedrawRequested => {
|
|
|
|
|
if let (Some(window), Some(servo)) = (&self.window, &self.servo) {
|
2026-03-11 17:06:02 +00:00
|
|
|
if let Some(rc) = &self.rendering_context {
|
|
|
|
|
Self::render_frame(window, rc);
|
2026-03-11 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
servo.spin_event_loop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::Resized(new_size) => {
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
let sz = servo::euclid::Size2D::new(new_size.width, new_size.height);
|
2026-03-11 13:52:13 +00:00
|
|
|
if let Some(wv) = &self.webview {
|
feat(servo-shell): per-app WebView lifecycle driven by appd events (servo-embed only)
Task 10 -- App WebView lifecycle.
appd_ws module (servo-embed gated):
Background thread connects to the appd WebSocket on startup.
Sends QUERY_RUNNING to receive initial running sessions.
Translates LAUNCH_ACK -> AppdCmd::Launch and APP_STATE stopped
-> AppdCmd::Stop, then wakes the winit event loop via the
shared EventLoopWaker.
embedder changes:
App struct gains app_rx (mpsc receiver), app_webviews
(HashMap<session_id, WebView>), active_session, and a stored
rendering_context used when creating app WebViews later.
create_app_webview(): resolves weft-app://<app_id>/index.html
to a file URL, creates a dedicated UserContentManager with the
weftIpc bridge injected (includes window.weftSessionId), builds
and registers a new WebView.
about_to_wait() drains app_rx: creates WebViews for Launch
commands, removes and clears active_session for Stop commands.
active_webview() returns the active-session WebView when one
exists, falling back to the system-ui WebView. Rendering,
keyboard, and mouse events all route through active_webview().
Resize propagates to both the system WebView and all app WebViews.
run() creates the mpsc channel and spawns the appd listener
before entering the winit event loop.
2026-03-11 16:59:12 +00:00
|
|
|
wv.resize(sz);
|
|
|
|
|
}
|
2026-03-11 13:52:13 +00:00
|
|
|
}
|
2026-03-11 16:52:37 +00:00
|
|
|
WindowEvent::ModifiersChanged(mods) => {
|
|
|
|
|
self.modifiers = mods.state();
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::KeyboardInput { event, .. } => {
|
2026-03-12 09:58:45 +00:00
|
|
|
if let Some(wv) = &self.webview {
|
2026-03-11 16:52:37 +00:00
|
|
|
let ev = super::keyutils::keyboard_event_from_winit(&event, self.modifiers);
|
|
|
|
|
let _ = wv.notify_input_event(InputEvent::Keyboard(ev));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::CursorMoved { position, .. } => {
|
|
|
|
|
let pt = servo::euclid::default::Point2D::new(position.x as f32, position.y as f32);
|
|
|
|
|
self.cursor_pos = pt;
|
2026-03-12 09:58:45 +00:00
|
|
|
if let Some(wv) = &self.webview {
|
2026-03-11 16:52:37 +00:00
|
|
|
let _ = wv.notify_input_event(InputEvent::MouseMove(MouseMoveEvent::new(pt)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WindowEvent::MouseInput { state, button, .. } => {
|
|
|
|
|
let btn = match button {
|
|
|
|
|
MouseButton::Left => ServoMouseButton::Left,
|
|
|
|
|
MouseButton::Right => ServoMouseButton::Right,
|
|
|
|
|
MouseButton::Middle => ServoMouseButton::Middle,
|
|
|
|
|
_ => return,
|
|
|
|
|
};
|
|
|
|
|
let action = match state {
|
|
|
|
|
ElementState::Pressed => MouseButtonAction::Click,
|
|
|
|
|
ElementState::Released => MouseButtonAction::Up,
|
|
|
|
|
};
|
2026-03-12 09:58:45 +00:00
|
|
|
if let Some(wv) = &self.webview {
|
2026-03-11 16:52:37 +00:00
|
|
|
let _ = wv.notify_input_event(InputEvent::MouseButton(MouseButtonEvent::new(
|
|
|
|
|
action,
|
|
|
|
|
btn,
|
|
|
|
|
self.cursor_pos.cast_unit(),
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-11 13:52:13 +00:00
|
|
|
WindowEvent::CloseRequested => {
|
|
|
|
|
self.shutting_down = true;
|
|
|
|
|
if let Some(servo) = &self.servo {
|
|
|
|
|
servo.start_shutting_down();
|
|
|
|
|
}
|
|
|
|
|
event_loop.exit();
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 17:06:02 +00:00
|
|
|
// ── Rendering context factory ─────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
fn build_rendering_ctx(
|
|
|
|
|
event_loop: &ActiveEventLoop,
|
|
|
|
|
window: &Arc<Window>,
|
|
|
|
|
size: winit::dpi::PhysicalSize<u32>,
|
|
|
|
|
) -> RenderingCtx {
|
|
|
|
|
if std::env::var_os("WEFT_EGL_RENDERING").is_some() {
|
|
|
|
|
let display_handle = event_loop.display_handle();
|
|
|
|
|
let window_handle = window.window_handle();
|
|
|
|
|
if let (Ok(dh), Ok(wh)) = (display_handle, window_handle) {
|
|
|
|
|
match servo::WindowRenderingContext::new(dh, wh, size) {
|
|
|
|
|
Ok(rc) => {
|
|
|
|
|
tracing::info!("using EGL rendering context");
|
|
|
|
|
return RenderingCtx::Egl(Rc::new(rc));
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::warn!("EGL rendering context failed ({e}), falling back to software");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RenderingCtx::Software(Rc::new(
|
|
|
|
|
servo::SoftwareRenderingContext::new(servo::euclid::Size2D::new(size.width, size.height))
|
|
|
|
|
.expect("SoftwareRenderingContext"),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 13:52:13 +00:00
|
|
|
// ── Public entry point ────────────────────────────────────────────────────────
|
|
|
|
|
|
2026-03-11 16:52:37 +00:00
|
|
|
fn resolve_weft_app_url(url: &ServoUrl) -> Option<ServoUrl> {
|
|
|
|
|
if url.scheme() != "weft-app" {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let app_id = url.host_str()?;
|
|
|
|
|
let rel = url.path().trim_start_matches('/');
|
|
|
|
|
let file_path = app_store_roots()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|r| r.join(app_id).join("ui").join(rel))
|
|
|
|
|
.find(|p| p.exists())?;
|
|
|
|
|
let s = format!("file://{}", file_path.display());
|
|
|
|
|
ServoUrl::parse(&s).ok()
|
|
|
|
|
}
|
|
|
|
|
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
fn load_ui_kit_script() -> Option<String> {
|
|
|
|
|
let path = std::env::var("WEFT_UI_KIT_JS")
|
|
|
|
|
.map(std::path::PathBuf::from)
|
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
|
std::path::PathBuf::from("/usr/share/weft/system/weft-ui-kit.js")
|
|
|
|
|
});
|
|
|
|
|
std::fs::read_to_string(path).ok()
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 16:52:37 +00:00
|
|
|
fn app_store_roots() -> Vec<PathBuf> {
|
|
|
|
|
if let Ok(v) = std::env::var("WEFT_APP_STORE") {
|
|
|
|
|
return vec![PathBuf::from(v)];
|
|
|
|
|
}
|
|
|
|
|
let mut roots = Vec::new();
|
|
|
|
|
if let Ok(home) = std::env::var("HOME") {
|
|
|
|
|
roots.push(
|
|
|
|
|
PathBuf::from(home)
|
|
|
|
|
.join(".local")
|
|
|
|
|
.join("share")
|
|
|
|
|
.join("weft")
|
|
|
|
|
.join("apps"),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
roots.push(PathBuf::from("/usr/share/weft/apps"));
|
|
|
|
|
roots
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 19:46:53 +00:00
|
|
|
pub fn run(
|
|
|
|
|
html_path: &Path,
|
|
|
|
|
ws_port: u16,
|
|
|
|
|
shell_client: Option<crate::shell_client::ShellClient>,
|
|
|
|
|
) -> anyhow::Result<()> {
|
2026-03-11 13:52:13 +00:00
|
|
|
let url_str = format!("file://{}", html_path.display());
|
2026-03-11 16:52:37 +00:00
|
|
|
let raw_url =
|
2026-03-11 13:52:13 +00:00
|
|
|
ServoUrl::parse(&url_str).map_err(|e| anyhow::anyhow!("invalid URL {url_str}: {e}"))?;
|
2026-03-11 16:52:37 +00:00
|
|
|
let url = resolve_weft_app_url(&raw_url).unwrap_or(raw_url);
|
2026-03-11 13:52:13 +00:00
|
|
|
|
|
|
|
|
let event_loop = EventLoop::<ServoWake>::with_user_event()
|
|
|
|
|
.build()
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("event loop: {e}"))?;
|
|
|
|
|
|
|
|
|
|
let waker = WeftEventLoopWaker {
|
|
|
|
|
proxy: Arc::new(Mutex::new(event_loop.create_proxy())),
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-12 09:58:45 +00:00
|
|
|
let mut app = App::new(url, waker, ws_port, shell_client);
|
2026-03-11 13:52:13 +00:00
|
|
|
event_loop
|
|
|
|
|
.run_app(&mut app)
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("event loop run: {e}"))
|
|
|
|
|
}
|
feat: appd IPC relay, WIT interfaces, UI kit, gesture routing, and CI hardening
- weft-appd: per-session IPC socket paths; bidirectional Wasm-HTML JSON relay
via spawn_ipc_relay; SO_PEERCRED UID check on Unix socket connections;
PanelGesture request and NavigationGesture broadcast for compositor gestures
- weft-runtime: weft:app/ipc, weft:app/fetch, weft:app/notifications WIT
interfaces; IpcState non-blocking Unix socket host functions; ureq-backed
net:fetch host function (net-fetch feature); notify-send notifications host
- weft-file-portal: spawn a thread per accepted connection for concurrent access
- weft-app-shell: weft-system:// URL translation; WEFT UI Kit UserScript
injection; resolve_weft_system_url helper
- weft-servo-shell: forward compositor navigation gestures to weft-appd
WebSocket as PanelGesture; WEFT UI Kit UserScript injection
- infra/shell: weft-ui-kit.js with 11 custom elements (weft-button, weft-card,
weft-dialog, weft-icon, weft-list, weft-list-item, weft-menu, weft-menu-item,
weft-progress, weft-input, weft-label); system-ui.html handles
NAVIGATION_GESTURE messages and dispatches weft:navigation-gesture CustomEvent
- infra/systemd: add missing env vars to weft-appd.service; correct
servo-shell.service binary path and system-ui.html argument
- .github/workflows/ci.yml: exclude weft-servo-shell and weft-app-shell from
cross-platform job; add them to linux-only job with libsystemd-dev dependency
2026-03-12 11:49:45 +00:00
|
|
|
|
|
|
|
|
fn forward_gestures_to_appd(
|
|
|
|
|
ws_port: u16,
|
|
|
|
|
gestures: &[crate::shell_client::PendingGesture],
|
|
|
|
|
) {
|
|
|
|
|
use std::net::TcpStream;
|
|
|
|
|
let addr = format!("127.0.0.1:{ws_port}");
|
|
|
|
|
let stream = match TcpStream::connect(&addr) {
|
|
|
|
|
Ok(s) => s,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::warn!("gesture forward: connect to {addr} failed: {e}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let url = format!("ws://{addr}/");
|
|
|
|
|
let (mut ws, _) = match tungstenite::client::client(url, stream) {
|
|
|
|
|
Ok(pair) => pair,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
tracing::warn!("gesture forward: WebSocket handshake failed: {e}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
for g in gestures {
|
|
|
|
|
let json = format!(
|
|
|
|
|
r#"{{"type":"PANEL_GESTURE","gesture_type":{},"fingers":{},"dx":{},"dy":{}}}"#,
|
|
|
|
|
g.gesture_type, g.fingers, g.dx, g.dy
|
|
|
|
|
);
|
|
|
|
|
if let Err(e) = ws.send(tungstenite::Message::Text(json)) {
|
|
|
|
|
tracing::warn!("gesture forward: send failed: {e}");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let _ = ws.close(None);
|
|
|
|
|
}
|