|
@@ -1,38 +1,51 @@
|
|
#![allow(unused)]
|
|
#![allow(unused)]
|
|
|
|
|
|
use super::*;
|
|
use super::*;
|
|
-use wry::application::accelerator::Accelerator;
|
|
|
|
|
|
+use std::str::FromStr;
|
|
use wry::application::event_loop::EventLoopWindowTarget;
|
|
use wry::application::event_loop::EventLoopWindowTarget;
|
|
|
|
|
|
-pub struct HotKey();
|
|
|
|
|
|
+use dioxus_html::input_data::keyboard_types::Modifiers;
|
|
|
|
+
|
|
|
|
+#[derive(Clone, Debug)]
|
|
|
|
+pub struct Accelerator;
|
|
|
|
+
|
|
|
|
+#[derive(Clone, Copy)]
|
|
|
|
+pub struct HotKey;
|
|
|
|
+
|
|
|
|
+impl HotKey {
|
|
|
|
+ pub fn new(mods: Option<Modifiers>, key: Code) -> Self {
|
|
|
|
+ Self
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub fn id(&self) -> u32 {
|
|
|
|
+ 0
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
impl FromStr for HotKey {
|
|
impl FromStr for HotKey {
|
|
type Err = ();
|
|
type Err = ();
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
- Ok(HotKey())
|
|
|
|
|
|
+ Ok(HotKey)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-pub struct ShortcutManager();
|
|
|
|
|
|
+pub struct GlobalHotKeyManager();
|
|
|
|
|
|
-impl ShortcutManager {
|
|
|
|
- pub fn new<T>(target: &EventLoopWindowTarget<T>) -> Self {
|
|
|
|
- Self()
|
|
|
|
|
|
+impl GlobalHotKeyManager {
|
|
|
|
+ pub fn new() -> Result<Self, HotkeyError> {
|
|
|
|
+ Ok(Self())
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn register(
|
|
|
|
- &mut self,
|
|
|
|
- accelerator: Accelerator,
|
|
|
|
- ) -> Result<GlobalShortcut, ShortcutManagerError> {
|
|
|
|
- Ok(GlobalShortcut())
|
|
|
|
|
|
+ pub fn register(&mut self, accelerator: HotKey) -> Result<HotKey, HotkeyError> {
|
|
|
|
+ Ok(HotKey)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn unregister(&mut self, id: ShortcutId) -> Result<(), ShortcutManagerError> {
|
|
|
|
|
|
+ pub fn unregister(&mut self, id: HotKey) -> Result<(), HotkeyError> {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn unregister_all(&mut self) -> Result<(), ShortcutManagerError> {
|
|
|
|
|
|
+ pub fn unregister_all(&mut self, _: &[HotKey]) -> Result<(), HotkeyError> {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -42,33 +55,35 @@ use std::{error, fmt};
|
|
/// An error whose cause the `ShortcutManager` to fail.
|
|
/// An error whose cause the `ShortcutManager` to fail.
|
|
#[non_exhaustive]
|
|
#[non_exhaustive]
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
-pub enum ShortcutManagerError {
|
|
|
|
|
|
+pub enum HotkeyError {
|
|
AcceleratorAlreadyRegistered(Accelerator),
|
|
AcceleratorAlreadyRegistered(Accelerator),
|
|
AcceleratorNotRegistered(Accelerator),
|
|
AcceleratorNotRegistered(Accelerator),
|
|
- InvalidAccelerator(String),
|
|
|
|
|
|
+ HotKeyParseError(String),
|
|
}
|
|
}
|
|
|
|
|
|
-impl error::Error for ShortcutManagerError {}
|
|
|
|
-impl fmt::Display for ShortcutManagerError {
|
|
|
|
|
|
+impl error::Error for HotkeyError {}
|
|
|
|
+impl fmt::Display for HotkeyError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
match self {
|
|
match self {
|
|
- ShortcutManagerError::AcceleratorAlreadyRegistered(e) => {
|
|
|
|
|
|
+ HotkeyError::AcceleratorAlreadyRegistered(e) => {
|
|
f.pad(&format!("hotkey already registered: {:?}", e))
|
|
f.pad(&format!("hotkey already registered: {:?}", e))
|
|
}
|
|
}
|
|
- ShortcutManagerError::AcceleratorNotRegistered(e) => {
|
|
|
|
|
|
+ HotkeyError::AcceleratorNotRegistered(e) => {
|
|
f.pad(&format!("hotkey not registered: {:?}", e))
|
|
f.pad(&format!("hotkey not registered: {:?}", e))
|
|
}
|
|
}
|
|
- ShortcutManagerError::InvalidAccelerator(e) => e.fmt(f),
|
|
|
|
|
|
+ HotkeyError::HotKeyParseError(e) => e.fmt(f),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-struct HotkeyError;
|
|
|
|
-
|
|
|
|
-struct GlobalHotKeyEvent {
|
|
|
|
- id: u32,
|
|
|
|
|
|
+pub struct GlobalHotKeyEvent {
|
|
|
|
+ pub id: u32,
|
|
}
|
|
}
|
|
|
|
|
|
-pub(crate) type Code = dioxus::prelude::Code;
|
|
|
|
|
|
+impl GlobalHotKeyEvent {
|
|
|
|
+ pub fn receiver() -> crossbeam_channel::Receiver<GlobalHotKeyEvent> {
|
|
|
|
+ crossbeam_channel::unbounded().1
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
-struct GlobalHotKeyManager {}
|
|
|
|
|
|
+pub(crate) type Code = dioxus_html::input_data::keyboard_types::Code;
|