From 8657b474015b28984c999b54f1af338d076fbf60 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 9 Mar 2023 11:05:41 -0600 Subject: [PATCH] Add function to remove all global shortcuts. --- packages/desktop/src/desktop_context.rs | 5 +++++ packages/desktop/src/shortcut.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 7db554517..2ed4bbee9 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -271,6 +271,11 @@ impl DesktopContext { self.shortcut_manager.remove_shortcut(id) } + /// Remove all global shortcuts + pub fn remove_all_shortcuts(&self) { + self.shortcut_manager.remove_all() + } + /// Push an objc view to the window #[cfg(target_os = "ios")] pub fn push_view(&self, view: objc_id::ShareId) { diff --git a/packages/desktop/src/shortcut.rs b/packages/desktop/src/shortcut.rs index cf70d307a..5232bdb8b 100644 --- a/packages/desktop/src/shortcut.rs +++ b/packages/desktop/src/shortcut.rs @@ -113,6 +113,18 @@ impl ShortcutRegistry { } } } + + pub(crate) fn remove_all(&self) { + let mut shortcuts = self.shortcuts.borrow_mut(); + shortcuts.clear(); + let _ = self.manager.borrow_mut().unregister_all(); + // prevent CTRL+R from reloading the page which breaks apps + let _ = self.add_shortcut( + Some(ModifiersState::CONTROL), + KeyCode::KeyR, + Box::new(|| {}), + ); + } } #[non_exhaustive]