소스 검색

Merge pull request #869 from ndarilek/master

Add function to remove all global shortcuts.
Jon Kelley 2 년 전
부모
커밋
059f6b18db
2개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      packages/desktop/src/desktop_context.rs
  2. 12 0
      packages/desktop/src/shortcut.rs

+ 5 - 0
packages/desktop/src/desktop_context.rs

@@ -271,6 +271,11 @@ impl DesktopContext {
         self.shortcut_manager.remove_shortcut(id)
         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
     /// Push an objc view to the window
     #[cfg(target_os = "ios")]
     #[cfg(target_os = "ios")]
     pub fn push_view(&self, view: objc_id::ShareId<objc::runtime::Object>) {
     pub fn push_view(&self, view: objc_id::ShareId<objc::runtime::Object>) {

+ 12 - 0
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]
 #[non_exhaustive]