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

+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() {