fix desktop events
This commit is contained in:
1 parent
bd387d601c
commit
8ba1c05a93
12 files changed
+507
-217
No files matched your search
@@ -3,6 +3,7 @@ use dioxus_html::{geometry::euclid::Rect, MountedResult, RenderedElementBacking}
|
||||
|
||||
use crate::{desktop_context::DesktopContext, query::QueryEngine};
|
||||
|
||||
#[derive(Clone)]
|
||||
/// A mounted element passed to onmounted events
|
||||
pub struct DesktopElement {
|
||||
id: ElementId,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! Convert a serialized event to an event trigger
|
||||
|
||||
use dioxus_html::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::element::DesktopElement;
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
pub struct IpcMessage {
|
||||
method: String,
|
||||
@@ -17,3 +20,147 @@ impl IpcMessage {
|
||||
self.params
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct SerializedHtmlEventConverter;
|
||||
|
||||
impl HtmlEventConverter for SerializedHtmlEventConverter {
|
||||
fn convert_animation_data(&self, event: &PlatformEventData) -> AnimationData {
|
||||
event
|
||||
.downcast::<SerializedAnimationData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_clipboard_data(&self, event: &PlatformEventData) -> ClipboardData {
|
||||
event
|
||||
.downcast::<SerializedClipboardData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_composition_data(&self, event: &PlatformEventData) -> CompositionData {
|
||||
event
|
||||
.downcast::<SerializedCompositionData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_drag_data(&self, event: &PlatformEventData) -> DragData {
|
||||
event
|
||||
.downcast::<SerializedDragData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_focus_data(&self, event: &PlatformEventData) -> FocusData {
|
||||
event
|
||||
.downcast::<SerializedFocusData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_form_data(&self, event: &PlatformEventData) -> FormData {
|
||||
event
|
||||
.downcast::<SerializedFormData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_image_data(&self, event: &PlatformEventData) -> ImageData {
|
||||
event
|
||||
.downcast::<SerializedImageData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_keyboard_data(&self, event: &PlatformEventData) -> KeyboardData {
|
||||
event
|
||||
.downcast::<SerializedKeyboardData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_media_data(&self, event: &PlatformEventData) -> MediaData {
|
||||
event
|
||||
.downcast::<SerializedMediaData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_mounted_data(&self, event: &PlatformEventData) -> MountedData {
|
||||
event.downcast::<DesktopElement>().cloned().unwrap().into()
|
||||
}
|
||||
|
||||
fn convert_mouse_data(&self, event: &PlatformEventData) -> MouseData {
|
||||
event
|
||||
.downcast::<SerializedMouseData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_pointer_data(&self, event: &PlatformEventData) -> PointerData {
|
||||
event
|
||||
.downcast::<SerializedPointerData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_scroll_data(&self, event: &PlatformEventData) -> ScrollData {
|
||||
event
|
||||
.downcast::<SerializedScrollData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_selection_data(&self, event: &PlatformEventData) -> SelectionData {
|
||||
event
|
||||
.downcast::<SerializedSelectionData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_toggle_data(&self, event: &PlatformEventData) -> ToggleData {
|
||||
event
|
||||
.downcast::<SerializedToggleData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_touch_data(&self, event: &PlatformEventData) -> TouchData {
|
||||
event
|
||||
.downcast::<SerializedTouchData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_transition_data(&self, event: &PlatformEventData) -> TransitionData {
|
||||
event
|
||||
.downcast::<SerializedTransitionData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn convert_wheel_data(&self, event: &PlatformEventData) -> WheelData {
|
||||
event
|
||||
.downcast::<SerializedWheelData>()
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,10 @@ pub use desktop_context::{
|
||||
use desktop_context::{EventData, UserWindowEvent, WebviewQueue, WindowEventHandlers};
|
||||
use dioxus_core::*;
|
||||
use dioxus_html::{native_bind::NativeFileEngine, HtmlEvent};
|
||||
use dioxus_html::{FileEngine, HasFormData, MountedData};
|
||||
use dioxus_html::{FileEngine, HasFormData, MountedData, PlatformEventData};
|
||||
use element::DesktopElement;
|
||||
use eval::init_eval;
|
||||
use events::SerializedHtmlEventConverter;
|
||||
use futures_util::{pin_mut, FutureExt};
|
||||
use shortcut::ShortcutRegistry;
|
||||
pub use shortcut::{use_global_shortcut, ShortcutHandle, ShortcutId, ShortcutRegistryError};
|
||||
@@ -136,6 +137,9 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
||||
}
|
||||
});
|
||||
|
||||
// Set the event converter
|
||||
dioxus_html::set_event_converter(Box::new(SerializedHtmlEventConverter));
|
||||
|
||||
// We start the tokio runtime *on this thread*
|
||||
// Any future we poll later will use this runtime to spawn tasks and for IO
|
||||
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||
@@ -292,7 +296,7 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
||||
let element =
|
||||
DesktopElement::new(element, view.desktop_context.clone(), query);
|
||||
|
||||
Rc::new(MountedData::new(element))
|
||||
Rc::new(PlatformEventData::new(Box::new(MountedData::new(element))))
|
||||
} else {
|
||||
data.into_any()
|
||||
};
|
||||
@@ -358,9 +362,10 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
|
||||
let event_name = &file_diolog.event;
|
||||
let event_bubbles = file_diolog.bubbles;
|
||||
let files = file_upload::get_file_event(&file_diolog);
|
||||
let data = Rc::new(DesktopFileUploadForm {
|
||||
files: Arc::new(NativeFileEngine::new(files)),
|
||||
});
|
||||
let data =
|
||||
Rc::new(PlatformEventData::new(Box::new(DesktopFileUploadForm {
|
||||
files: Arc::new(NativeFileEngine::new(files)),
|
||||
})));
|
||||
|
||||
let view = webviews.get_mut(&event.1).unwrap();
|
||||
|
||||
|
||||
Reference in new issue
Block a user