cfg out globalhotkey

This commit is contained in:
Jonathan Kelley committed 2024-03-06 16:42:45 -08:00
1 parent f7f416ee3a
commit 81f38a0bc5
11 files changed
+37 -26

No files matched your search

+1 -1
View File
@@ -52,8 +52,8 @@ async-trait = "0.1.68"
tao = { version = "0.24.0", features = ["rwh_05"] }
[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
global-hotkey = "0.5.0"
rfd = "0.12"
global-hotkey = "0.4.1"
muda = "0.11.3"
[target.'cfg(target_os = "ios")'.dependencies]
+5 -2
View File
@@ -5,7 +5,7 @@ use crate::{
file_upload::{DesktopFileDragEvent, DesktopFileUploadForm, FileDialogRequest},
ipc::{IpcMessage, UserWindowEvent},
query::QueryResult,
shortcut::{GlobalHotKeyEvent, ShortcutRegistry},
shortcut::ShortcutRegistry,
webview::WebviewInstance,
};
use dioxus_core::ElementId;
@@ -77,6 +77,7 @@ impl App {
dioxus_html::set_event_converter(Box::new(crate::events::SerializedHtmlEventConverter));
// Wire up the global hotkey handler
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
app.set_global_hotkey_handler();
// Allow hotreloading to work - but only in debug mode
@@ -93,7 +94,8 @@ impl App {
.apply_event(window_event, &self.shared.target);
}
pub fn handle_global_hotkey(&self, event: GlobalHotKeyEvent) {
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
pub fn handle_global_hotkey(&self, event: global_hotkey::GlobalHotKeyEvent) {
self.shared.shortcut_manager.call_handlers(event);
}
@@ -322,6 +324,7 @@ impl App {
view.poll_vdom();
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
fn set_global_hotkey_handler(&self) {
let receiver = self.shared.proxy.clone();
+2 -2
View File
@@ -10,7 +10,7 @@ use dioxus_html::{
prelude::{SerializedMouseData, SerializedPointInteraction},
FileEngine, HasDragData, HasFileData, HasFormData, HasMouseData,
};
use muda::accelerator::Modifiers;
use serde::Deserialize;
use std::{
cell::{Cell, RefCell},
@@ -223,7 +223,7 @@ impl InteractionElementOffset for DesktopFileDragEvent {
}
impl ModifiersInteraction for DesktopFileDragEvent {
fn modifiers(&self) -> Modifiers {
fn modifiers(&self) -> dioxus_html::prelude::Modifiers {
self.mouse.modifiers()
}
}
+2 -2
View File
@@ -1,11 +1,11 @@
use global_hotkey::GlobalHotKeyEvent;
use serde::{Deserialize, Serialize};
use tao::window::WindowId;
#[derive(Debug, Clone)]
pub enum UserWindowEvent {
/// A global hotkey event
GlobalHotKeyEvent(GlobalHotKeyEvent),
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
GlobalHotKeyEvent(global_hotkey::GlobalHotKeyEvent),
/// Poll the virtualdom
Poll(WindowId),
+4
View File
@@ -32,9 +32,13 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, desktop_config: Conf
UserWindowEvent::Poll(id) => app.poll_vdom(id),
UserWindowEvent::NewWindow => app.handle_new_window(),
UserWindowEvent::CloseWindow(id) => app.handle_close_msg(id),
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
UserWindowEvent::GlobalHotKeyEvent(evnt) => app.handle_global_hotkey(evnt),
#[cfg(all(feature = "hot-reload", debug_assertions))]
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),
UserWindowEvent::Ipc { id, msg } => match msg.method() {
IpcMethod::Initialize => app.handle_initialize_msg(id),
IpcMethod::FileDialog => app.handle_file_dialog_msg(msg, id),
+1
View File
@@ -64,6 +64,7 @@ impl ShortcutRegistry {
}
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
pub(crate) fn call_handlers(&self, id: GlobalHotKeyEvent) {
if let Some(ShortcutInner { callbacks, .. }) = self.shortcuts.borrow_mut().get_mut(&id.id) {
for (_, callback) in callbacks.iter_mut() {
+1 -1
View File
@@ -147,7 +147,7 @@ fn deserialize_raw(
#[cfg(feature = "serialize")]
impl HtmlEvent {
pub fn bubbles(&self) -> bool {
event_bubbles(&self.name)
self.bubbles
}
}
+6 -1
View File
@@ -75,7 +75,12 @@ mod js {
"{let node = document.createElement('pre'); node.hidden = true; this.stack.push(node); this.nodes[$id$] = node;}"
}
fn new_event_listener(event_name: &str<u8, evt>, id: u32, bubbles: u8) {
r#"let node = this.nodes[id]; if(node.listening){node.listening += 1;}else{node.listening = 1;} node.setAttribute('data-dioxus-id', `\${id}`); this.createListener($event_name$, node, $bubbles$);"#
r#"
let node = this.nodes[id];
if(node.listening){node.listening += 1;}else{node.listening = 1;}
node.setAttribute('data-dioxus-id', `\${id}`);
this.createListener($event_name$, node, $bubbles$);
"#
}
fn remove_event_listener(event_name: &str<u8, evt>, id: u32, bubbles: u8) {
"{let node = this.nodes[$id$]; node.listening -= 1; node.removeAttribute('data-dioxus-id'); this.removeListener(node, $event_name$, $bubbles$);}"
+1 -1
View File
@@ -73,7 +73,7 @@ impl WebsysDom {
move |event: &web_sys::Event| {
let name = event.type_();
let element = walk_event_for_id(event);
let bubbles = dioxus_html::event_bubbles(name.as_str());
let bubbles = event.bubbles();
let Some((element, target)) = element else {
return;