From e5c763b71c00b76f7bf3f55aa4099654b0546f94 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Mon, 6 Jan 2025 01:16:58 +1300 Subject: [PATCH] Rename BlitzEvent to BlitzShellEvent Signed-off-by: Nico Burns --- apps/readme/src/main.rs | 10 +++++---- apps/readme/src/readme_application.rs | 12 +++++----- packages/blitz-shell/src/accessibility.rs | 4 ++-- packages/blitz-shell/src/application.rs | 22 +++++++++---------- packages/blitz-shell/src/event.rs | 16 +++++++------- packages/blitz-shell/src/lib.rs | 10 ++++----- packages/blitz-shell/src/window.rs | 6 ++--- packages/blitz/src/lib.rs | 4 ++-- .../dioxus-native/src/dioxus_application.rs | 10 ++++----- packages/dioxus-native/src/lib.rs | 6 ++--- 10 files changed, 51 insertions(+), 49 deletions(-) diff --git a/apps/readme/src/main.rs b/apps/readme/src/main.rs index 73f95188..b30f22ac 100644 --- a/apps/readme/src/main.rs +++ b/apps/readme/src/main.rs @@ -9,7 +9,9 @@ use notify::{Error as NotifyError, Event as NotifyEvent, RecursiveMode, Watcher use readme_application::{ReadmeApplication, ReadmeEvent}; use reqwest::header::HeaderName; -use blitz_shell::{create_default_event_loop, BlitzEvent, BlitzShellNetCallback, WindowConfig}; +use blitz_shell::{ + create_default_event_loop, BlitzShellEvent, BlitzShellNetCallback, WindowConfig, +}; use std::env::current_dir; use std::fs; use std::path::{Path, PathBuf}; @@ -21,12 +23,12 @@ use winit::window::WindowAttributes; const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"; struct ReadmeNavigationProvider { - proxy: EventLoopProxy, + proxy: EventLoopProxy, } impl NavigationProvider for ReadmeNavigationProvider { fn navigate_new_page(&self, url: String) { - let _ = self.proxy.send_event(BlitzEvent::Navigate(url)); + let _ = self.proxy.send_event(BlitzShellEvent::Navigate(url)); } } @@ -97,7 +99,7 @@ fn main() { if let Some(path) = file_path { let mut watcher = notify::recommended_watcher(move |_: Result| { - let event = BlitzEvent::Embedder(Arc::new(ReadmeEvent)); + let event = BlitzShellEvent::Embedder(Arc::new(ReadmeEvent)); proxy.send_event(event).unwrap(); }) .unwrap(); diff --git a/apps/readme/src/readme_application.rs b/apps/readme/src/readme_application.rs index 82eac163..b24f7bb6 100644 --- a/apps/readme/src/readme_application.rs +++ b/apps/readme/src/readme_application.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use blitz_dom::net::Resource; use blitz_html::HtmlDocument; use blitz_renderer_vello::BlitzVelloRenderer; -use blitz_shell::{BlitzApplication, BlitzEvent, View, WindowConfig}; +use blitz_shell::{BlitzApplication, BlitzShellEvent, View, WindowConfig}; use blitz_traits::navigation::NavigationProvider; use blitz_traits::net::NetProvider; use tokio::runtime::Handle; @@ -29,7 +29,7 @@ pub struct ReadmeApplication { impl ReadmeApplication { pub fn new( - proxy: EventLoopProxy, + proxy: EventLoopProxy, raw_url: String, net_provider: Arc>, navigation_provider: Arc, @@ -85,7 +85,7 @@ impl ReadmeApplication { } } -impl ApplicationHandler for ReadmeApplication { +impl ApplicationHandler for ReadmeApplication { fn resumed(&mut self, event_loop: &ActiveEventLoop) { self.inner.resumed(event_loop); } @@ -122,14 +122,14 @@ impl ApplicationHandler for ReadmeApplication { self.inner.window_event(event_loop, window_id, event); } - fn user_event(&mut self, event_loop: &ActiveEventLoop, event: BlitzEvent) { + fn user_event(&mut self, event_loop: &ActiveEventLoop, event: BlitzShellEvent) { match event { - BlitzEvent::Embedder(event) => { + BlitzShellEvent::Embedder(event) => { if let Some(_event) = event.downcast_ref::() { self.reload_document(); } } - BlitzEvent::Navigate(url) => { + BlitzShellEvent::Navigate(url) => { self.raw_url = url; self.reload_document(); } diff --git a/packages/blitz-shell/src/accessibility.rs b/packages/blitz-shell/src/accessibility.rs index f583ebc0..c8798385 100644 --- a/packages/blitz-shell/src/accessibility.rs +++ b/packages/blitz-shell/src/accessibility.rs @@ -1,4 +1,4 @@ -use crate::event::BlitzEvent; +use crate::event::BlitzShellEvent; use accesskit::{NodeBuilder, NodeId, Role, Tree, TreeUpdate}; use blitz_dom::{local_name, BaseDocument, Node}; use winit::{event_loop::EventLoopProxy, window::Window}; @@ -13,7 +13,7 @@ pub struct AccessibilityState { } impl AccessibilityState { - pub fn new(window: &Window, proxy: EventLoopProxy) -> Self { + pub fn new(window: &Window, proxy: EventLoopProxy) -> Self { Self { adapter: accesskit_winit::Adapter::with_event_loop_proxy(window, proxy.clone()), next_id: 1, diff --git a/packages/blitz-shell/src/application.rs b/packages/blitz-shell/src/application.rs index d8c042c3..f39b2838 100644 --- a/packages/blitz-shell/src/application.rs +++ b/packages/blitz-shell/src/application.rs @@ -1,4 +1,4 @@ -use crate::event::BlitzEvent; +use crate::event::BlitzShellEvent; use blitz_dom::BaseDocument; use blitz_traits::{Document, DocumentRenderer}; @@ -16,14 +16,14 @@ type D = BaseDocument; pub struct BlitzApplication, Rend: DocumentRenderer> { pub windows: HashMap>, pending_windows: Vec>, - proxy: EventLoopProxy, + proxy: EventLoopProxy, #[cfg(all(feature = "menu", not(any(target_os = "android", target_os = "ios"))))] menu_channel: muda::MenuEventReceiver, } impl, Rend: DocumentRenderer> BlitzApplication { - pub fn new(proxy: EventLoopProxy) -> Self { + pub fn new(proxy: EventLoopProxy) -> Self { BlitzApplication { windows: HashMap::new(), pending_windows: Vec::new(), @@ -43,7 +43,7 @@ impl, Rend: DocumentRenderer> BlitzApplication, Rend: DocumentRenderer> ApplicationHandler +impl, Rend: DocumentRenderer> ApplicationHandler for BlitzApplication { fn resumed(&mut self, event_loop: &ActiveEventLoop) { @@ -97,18 +97,18 @@ impl, Rend: DocumentRenderer> ApplicationHandler window.handle_winit_event(event); } - let _ = self.proxy.send_event(BlitzEvent::Poll { window_id }); + let _ = self.proxy.send_event(BlitzShellEvent::Poll { window_id }); } - fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: BlitzEvent) { + fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: BlitzShellEvent) { match event { - BlitzEvent::Poll { window_id } => { + BlitzShellEvent::Poll { window_id } => { if let Some(window) = self.windows.get_mut(&window_id) { window.poll(); }; } - BlitzEvent::ResourceLoad { doc_id, data } => { + BlitzShellEvent::ResourceLoad { doc_id, data } => { // TODO: Handle multiple documents per window if let Some(window) = self.window_mut_by_doc_id(doc_id) { window.doc.as_mut().load_resource(data); @@ -117,7 +117,7 @@ impl, Rend: DocumentRenderer> ApplicationHandler } #[cfg(feature = "accessibility")] - BlitzEvent::Accessibility { window_id, data } => { + BlitzShellEvent::Accessibility { window_id, data } => { if let Some(window) = self.windows.get_mut(&window_id) { match &*data { accesskit_winit::WindowEvent::InitialTreeRequested => { @@ -133,10 +133,10 @@ impl, Rend: DocumentRenderer> ApplicationHandler } } - BlitzEvent::Embedder(_) => { + BlitzShellEvent::Embedder(_) => { // Do nothing. Should be handled by embedders (if required). } - BlitzEvent::Navigate(_url) => { + BlitzShellEvent::Navigate(_url) => { // Do nothing. Should be handled by embedders (if required). } } diff --git a/packages/blitz-shell/src/event.rs b/packages/blitz-shell/src/event.rs index ce5a9415..36ea0dfe 100644 --- a/packages/blitz-shell/src/event.rs +++ b/packages/blitz-shell/src/event.rs @@ -7,7 +7,7 @@ use accesskit_winit::{Event as AccessKitEvent, WindowEvent as AccessKitWindowEve use blitz_dom::net::Resource; #[derive(Debug, Clone)] -pub enum BlitzEvent { +pub enum BlitzShellEvent { Poll { window_id: WindowId, }, @@ -30,20 +30,20 @@ pub enum BlitzEvent { /// Navigate to another URL (triggered by e.g. clicking a link) Navigate(String), } -impl BlitzEvent { +impl BlitzShellEvent { pub fn embedder_event(value: T) -> Self { let boxed = Arc::new(value) as Arc; Self::Embedder(boxed) } } -impl From<(usize, Resource)> for BlitzEvent { +impl From<(usize, Resource)> for BlitzShellEvent { fn from((doc_id, data): (usize, Resource)) -> Self { - BlitzEvent::ResourceLoad { doc_id, data } + BlitzShellEvent::ResourceLoad { doc_id, data } } } #[cfg(feature = "accessibility")] -impl From for BlitzEvent { +impl From for BlitzShellEvent { fn from(value: AccessKitEvent) -> Self { Self::Accessibility { window_id: value.window_id, @@ -57,9 +57,9 @@ impl From for BlitzEvent { /// This lets the VirtualDom "come up for air" and process events while the main thread is blocked by the WebView. /// /// All other IO lives in the Tokio runtime, -pub fn create_waker(proxy: &EventLoopProxy, id: WindowId) -> std::task::Waker { +pub fn create_waker(proxy: &EventLoopProxy, id: WindowId) -> std::task::Waker { struct DomHandle { - proxy: EventLoopProxy, + proxy: EventLoopProxy, id: WindowId, } @@ -70,7 +70,7 @@ pub fn create_waker(proxy: &EventLoopProxy, id: WindowId) -> std::ta impl ArcWake for DomHandle { fn wake_by_ref(arc_self: &Arc) { - _ = arc_self.proxy.send_event(BlitzEvent::Poll { + _ = arc_self.proxy.send_event(BlitzShellEvent::Poll { window_id: arc_self.id, }) } diff --git a/packages/blitz-shell/src/lib.rs b/packages/blitz-shell/src/lib.rs index 42ab85e9..c04195e3 100644 --- a/packages/blitz-shell/src/lib.rs +++ b/packages/blitz-shell/src/lib.rs @@ -21,7 +21,7 @@ mod menu; mod accessibility; pub use crate::application::BlitzApplication; -pub use crate::event::BlitzEvent; +pub use crate::event::BlitzShellEvent; pub use crate::window::{View, WindowConfig}; use blitz_dom::net::Resource; @@ -70,14 +70,14 @@ pub fn current_android_app() -> android_activity::AndroidApp { } /// A NetCallback that injects the fetched Resource into our winit event loop -pub struct BlitzShellNetCallback(EventLoopProxy); +pub struct BlitzShellNetCallback(EventLoopProxy); impl BlitzShellNetCallback { - pub fn new(proxy: EventLoopProxy) -> Self { + pub fn new(proxy: EventLoopProxy) -> Self { Self(proxy) } - pub fn shared(proxy: EventLoopProxy) -> Arc> { + pub fn shared(proxy: EventLoopProxy) -> Arc> { Arc::new(Self(proxy)) } } @@ -85,7 +85,7 @@ impl NetCallback for BlitzShellNetCallback { type Data = Resource; fn call(&self, doc_id: usize, data: Self::Data) { self.0 - .send_event(BlitzEvent::ResourceLoad { doc_id, data }) + .send_event(BlitzShellEvent::ResourceLoad { doc_id, data }) .unwrap() } } diff --git a/packages/blitz-shell/src/window.rs b/packages/blitz-shell/src/window.rs index d99930a4..efa816c4 100644 --- a/packages/blitz-shell/src/window.rs +++ b/packages/blitz-shell/src/window.rs @@ -1,7 +1,7 @@ use crate::convert_events::{ winit_ime_to_blitz, winit_key_event_to_blitz, winit_modifiers_to_kbt_modifiers, }; -use crate::event::{create_waker, BlitzEvent}; +use crate::event::{create_waker, BlitzShellEvent}; use blitz_dom::BaseDocument; use blitz_traits::{BlitzMouseButtonEvent, ColorScheme, Devtools, Viewport}; use blitz_traits::{Document, DocumentRenderer, DomEvent, DomEventData}; @@ -53,7 +53,7 @@ pub struct View, Rend: DocumentRenderer> { pub(crate) renderer: Rend, pub(crate) waker: Option, - event_loop_proxy: EventLoopProxy, + event_loop_proxy: EventLoopProxy, window: Arc, /// The actual viewport of the page that we're getting a glimpse of. @@ -84,7 +84,7 @@ impl, Rend: DocumentRenderer> View { pub(crate) fn init( config: WindowConfig, event_loop: &ActiveEventLoop, - proxy: &EventLoopProxy, + proxy: &EventLoopProxy, ) -> Self { let winit_window = Arc::from(event_loop.create_window(config.attributes).unwrap()); diff --git a/packages/blitz/src/lib.rs b/packages/blitz/src/lib.rs index 8072a586..203bd241 100644 --- a/packages/blitz/src/lib.rs +++ b/packages/blitz/src/lib.rs @@ -14,7 +14,7 @@ use std::sync::Arc; use blitz_html::HtmlDocument; use blitz_renderer_vello::BlitzVelloRenderer; use blitz_shell::{ - create_default_event_loop, BlitzApplication, BlitzEvent, BlitzShellNetCallback, Config, + create_default_event_loop, BlitzApplication, BlitzShellEvent, BlitzShellNetCallback, Config, WindowConfig, }; use blitz_traits::navigation::DummyNavigationProvider; @@ -63,7 +63,7 @@ pub fn launch_static_html_cfg(html: &str, cfg: Config) { } fn launch_internal(html: &str, cfg: Config) { - let event_loop = create_default_event_loop::(); + let event_loop = create_default_event_loop::(); #[cfg(feature = "net")] let net_provider = { diff --git a/packages/dioxus-native/src/dioxus_application.rs b/packages/dioxus-native/src/dioxus_application.rs index 68ddc773..80b36286 100644 --- a/packages/dioxus-native/src/dioxus_application.rs +++ b/packages/dioxus-native/src/dioxus_application.rs @@ -5,14 +5,14 @@ use winit::event::{StartCause, WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoopProxy}; use winit::window::WindowId; -use crate::{BlitzEvent, DioxusDocument, DioxusNativeEvent, WindowConfig}; +use crate::{BlitzShellEvent, DioxusDocument, DioxusNativeEvent, WindowConfig}; pub struct DioxusNativeApplication { inner: BlitzApplication, } impl DioxusNativeApplication { - pub fn new(proxy: EventLoopProxy) -> Self { + pub fn new(proxy: EventLoopProxy) -> Self { Self { inner: BlitzApplication::new(proxy.clone()), } @@ -62,7 +62,7 @@ impl DioxusNativeApplication { } } -impl ApplicationHandler for DioxusNativeApplication { +impl ApplicationHandler for DioxusNativeApplication { fn resumed(&mut self, event_loop: &ActiveEventLoop) { self.inner.resumed(event_loop); } @@ -84,9 +84,9 @@ impl ApplicationHandler for DioxusNativeApplication { self.inner.window_event(event_loop, window_id, event); } - fn user_event(&mut self, event_loop: &ActiveEventLoop, event: BlitzEvent) { + fn user_event(&mut self, event_loop: &ActiveEventLoop, event: BlitzShellEvent) { match event { - BlitzEvent::Embedder(event) => { + BlitzShellEvent::Embedder(event) => { if let Some(event) = event.downcast_ref::() { self.handle_blitz_shell_event(event_loop, event); } diff --git a/packages/dioxus-native/src/lib.rs b/packages/dioxus-native/src/lib.rs index 14b87f61..8c67e928 100644 --- a/packages/dioxus-native/src/lib.rs +++ b/packages/dioxus-native/src/lib.rs @@ -20,7 +20,7 @@ pub use dioxus_application::DioxusNativeApplication; pub use dioxus_document::DioxusDocument; pub use event::DioxusNativeEvent; -use blitz_shell::{create_default_event_loop, BlitzEvent, Config, WindowConfig}; +use blitz_shell::{create_default_event_loop, BlitzShellEvent, Config, WindowConfig}; use dioxus_core::{ComponentFunction, Element, VirtualDom}; type NodeId = usize; @@ -40,7 +40,7 @@ pub fn launch_cfg_with_props( props: P, _cfg: Config, ) { - let event_loop = create_default_event_loop::(); + let event_loop = create_default_event_loop::(); #[cfg(feature = "net")] let net_provider = { @@ -83,7 +83,7 @@ pub fn launch_cfg_with_props( let proxy = event_loop.create_proxy(); dioxus_devtools::connect(endpoint, move |event| { let dxn_event = DioxusNativeEvent::DevserverEvent(event); - let _ = proxy.send_event(BlitzEvent::embedder_event(dxn_event)); + let _ = proxy.send_event(BlitzShellEvent::embedder_event(dxn_event)); }) } }