Skip to content

Commit

Permalink
Rename BlitzEvent to BlitzShellEvent
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns committed Jan 6, 2025
1 parent 000662a commit e5c763b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 49 deletions.
10 changes: 6 additions & 4 deletions apps/readme/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<BlitzEvent>,
proxy: EventLoopProxy<BlitzShellEvent>,
}

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));
}
}

Expand Down Expand Up @@ -97,7 +99,7 @@ fn main() {
if let Some(path) = file_path {
let mut watcher =
notify::recommended_watcher(move |_: Result<NotifyEvent, NotifyError>| {
let event = BlitzEvent::Embedder(Arc::new(ReadmeEvent));
let event = BlitzShellEvent::Embedder(Arc::new(ReadmeEvent));
proxy.send_event(event).unwrap();
})
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions apps/readme/src/readme_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,7 @@ pub struct ReadmeApplication {

impl ReadmeApplication {
pub fn new(
proxy: EventLoopProxy<BlitzEvent>,
proxy: EventLoopProxy<BlitzShellEvent>,
raw_url: String,
net_provider: Arc<dyn NetProvider<Data = Resource>>,
navigation_provider: Arc<dyn NavigationProvider>,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl ReadmeApplication {
}
}

impl ApplicationHandler<BlitzEvent> for ReadmeApplication {
impl ApplicationHandler<BlitzShellEvent> for ReadmeApplication {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.inner.resumed(event_loop);
}
Expand Down Expand Up @@ -122,14 +122,14 @@ impl ApplicationHandler<BlitzEvent> 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::<ReadmeEvent>() {
self.reload_document();
}
}
BlitzEvent::Navigate(url) => {
BlitzShellEvent::Navigate(url) => {
self.raw_url = url;
self.reload_document();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-shell/src/accessibility.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -13,7 +13,7 @@ pub struct AccessibilityState {
}

impl AccessibilityState {
pub fn new(window: &Window, proxy: EventLoopProxy<BlitzEvent>) -> Self {
pub fn new(window: &Window, proxy: EventLoopProxy<BlitzShellEvent>) -> Self {
Self {
adapter: accesskit_winit::Adapter::with_event_loop_proxy(window, proxy.clone()),
next_id: 1,
Expand Down
22 changes: 11 additions & 11 deletions packages/blitz-shell/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::event::BlitzEvent;
use crate::event::BlitzShellEvent;

use blitz_dom::BaseDocument;
use blitz_traits::{Document, DocumentRenderer};
Expand All @@ -16,14 +16,14 @@ type D = BaseDocument;
pub struct BlitzApplication<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> {
pub windows: HashMap<WindowId, View<Doc, Rend>>,
pending_windows: Vec<WindowConfig<Doc, Rend>>,
proxy: EventLoopProxy<BlitzEvent>,
proxy: EventLoopProxy<BlitzShellEvent>,

#[cfg(all(feature = "menu", not(any(target_os = "android", target_os = "ios"))))]
menu_channel: muda::MenuEventReceiver,
}

impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> BlitzApplication<Doc, Rend> {
pub fn new(proxy: EventLoopProxy<BlitzEvent>) -> Self {
pub fn new(proxy: EventLoopProxy<BlitzShellEvent>) -> Self {
BlitzApplication {
windows: HashMap::new(),
pending_windows: Vec::new(),
Expand All @@ -43,7 +43,7 @@ impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> BlitzApplication<D
}
}

impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> ApplicationHandler<BlitzEvent>
impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> ApplicationHandler<BlitzShellEvent>
for BlitzApplication<Doc, Rend>
{
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
Expand Down Expand Up @@ -97,18 +97,18 @@ impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> 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);
Expand All @@ -117,7 +117,7 @@ impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> 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 => {
Expand All @@ -133,10 +133,10 @@ impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> 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).
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/blitz-shell/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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<T: Any + Send + Sync>(value: T) -> Self {
let boxed = Arc::new(value) as Arc<dyn Any + Send + Sync>;
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<AccessKitEvent> for BlitzEvent {
impl From<AccessKitEvent> for BlitzShellEvent {
fn from(value: AccessKitEvent) -> Self {
Self::Accessibility {
window_id: value.window_id,
Expand All @@ -57,9 +57,9 @@ impl From<AccessKitEvent> 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<BlitzEvent>, id: WindowId) -> std::task::Waker {
pub fn create_waker(proxy: &EventLoopProxy<BlitzShellEvent>, id: WindowId) -> std::task::Waker {
struct DomHandle {
proxy: EventLoopProxy<BlitzEvent>,
proxy: EventLoopProxy<BlitzShellEvent>,
id: WindowId,
}

Expand All @@ -70,7 +70,7 @@ pub fn create_waker(proxy: &EventLoopProxy<BlitzEvent>, id: WindowId) -> std::ta

impl ArcWake for DomHandle {
fn wake_by_ref(arc_self: &Arc<Self>) {
_ = arc_self.proxy.send_event(BlitzEvent::Poll {
_ = arc_self.proxy.send_event(BlitzShellEvent::Poll {
window_id: arc_self.id,
})
}
Expand Down
10 changes: 5 additions & 5 deletions packages/blitz-shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,22 +70,22 @@ pub fn current_android_app() -> android_activity::AndroidApp {
}

/// A NetCallback that injects the fetched Resource into our winit event loop
pub struct BlitzShellNetCallback(EventLoopProxy<BlitzEvent>);
pub struct BlitzShellNetCallback(EventLoopProxy<BlitzShellEvent>);

impl BlitzShellNetCallback {
pub fn new(proxy: EventLoopProxy<BlitzEvent>) -> Self {
pub fn new(proxy: EventLoopProxy<BlitzShellEvent>) -> Self {
Self(proxy)
}

pub fn shared(proxy: EventLoopProxy<BlitzEvent>) -> Arc<dyn NetCallback<Data = Resource>> {
pub fn shared(proxy: EventLoopProxy<BlitzShellEvent>) -> Arc<dyn NetCallback<Data = Resource>> {
Arc::new(Self(proxy))
}
}
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()
}
}
6 changes: 3 additions & 3 deletions packages/blitz-shell/src/window.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct View<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> {
pub(crate) renderer: Rend,
pub(crate) waker: Option<Waker>,

event_loop_proxy: EventLoopProxy<BlitzEvent>,
event_loop_proxy: EventLoopProxy<BlitzShellEvent>,
window: Arc<Window>,

/// The actual viewport of the page that we're getting a glimpse of.
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<Doc: Document<Doc = D>, Rend: DocumentRenderer<Doc = D>> View<Doc, Rend> {
pub(crate) fn init(
config: WindowConfig<Doc, Rend>,
event_loop: &ActiveEventLoop,
proxy: &EventLoopProxy<BlitzEvent>,
proxy: &EventLoopProxy<BlitzShellEvent>,
) -> Self {
let winit_window = Arc::from(event_loop.create_window(config.attributes).unwrap());

Expand Down
4 changes: 2 additions & 2 deletions packages/blitz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<BlitzEvent>();
let event_loop = create_default_event_loop::<BlitzShellEvent>();

#[cfg(feature = "net")]
let net_provider = {
Expand Down
10 changes: 5 additions & 5 deletions packages/dioxus-native/src/dioxus_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DioxusDocument, BlitzVelloRenderer>,
}

impl DioxusNativeApplication {
pub fn new(proxy: EventLoopProxy<BlitzEvent>) -> Self {
pub fn new(proxy: EventLoopProxy<BlitzShellEvent>) -> Self {
Self {
inner: BlitzApplication::new(proxy.clone()),
}
Expand Down Expand Up @@ -62,7 +62,7 @@ impl DioxusNativeApplication {
}
}

impl ApplicationHandler<BlitzEvent> for DioxusNativeApplication {
impl ApplicationHandler<BlitzShellEvent> for DioxusNativeApplication {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.inner.resumed(event_loop);
}
Expand All @@ -84,9 +84,9 @@ impl ApplicationHandler<BlitzEvent> 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::<DioxusNativeEvent>() {
self.handle_blitz_shell_event(event_loop, event);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/dioxus-native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +40,7 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
props: P,
_cfg: Config,
) {
let event_loop = create_default_event_loop::<BlitzEvent>();
let event_loop = create_default_event_loop::<BlitzShellEvent>();

#[cfg(feature = "net")]
let net_provider = {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
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));
})
}
}
Expand Down

0 comments on commit e5c763b

Please sign in to comment.