mobile_shortcut.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #![allow(unused)]
  2. use super::*;
  3. use std::str::FromStr;
  4. use wry::application::event_loop::EventLoopWindowTarget;
  5. use dioxus_html::input_data::keyboard_types::Modifiers;
  6. #[derive(Clone, Debug)]
  7. pub struct Accelerator;
  8. #[derive(Clone, Copy)]
  9. pub struct HotKey;
  10. impl HotKey {
  11. pub fn new(mods: Option<Modifiers>, key: Code) -> Self {
  12. Self
  13. }
  14. pub fn id(&self) -> u32 {
  15. 0
  16. }
  17. }
  18. impl FromStr for HotKey {
  19. type Err = ();
  20. fn from_str(s: &str) -> Result<Self, Self::Err> {
  21. Ok(HotKey)
  22. }
  23. }
  24. pub struct GlobalHotKeyManager();
  25. impl GlobalHotKeyManager {
  26. pub fn new() -> Result<Self, HotkeyError> {
  27. Ok(Self())
  28. }
  29. pub fn register(&mut self, accelerator: HotKey) -> Result<HotKey, HotkeyError> {
  30. Ok(HotKey)
  31. }
  32. pub fn unregister(&mut self, id: HotKey) -> Result<(), HotkeyError> {
  33. Ok(())
  34. }
  35. pub fn unregister_all(&mut self, _: &[HotKey]) -> Result<(), HotkeyError> {
  36. Ok(())
  37. }
  38. }
  39. use std::{error, fmt};
  40. /// An error whose cause the `ShortcutManager` to fail.
  41. #[non_exhaustive]
  42. #[derive(Debug)]
  43. pub enum HotkeyError {
  44. AcceleratorAlreadyRegistered(Accelerator),
  45. AcceleratorNotRegistered(Accelerator),
  46. HotKeyParseError(String),
  47. }
  48. impl error::Error for HotkeyError {}
  49. impl fmt::Display for HotkeyError {
  50. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
  51. match self {
  52. HotkeyError::AcceleratorAlreadyRegistered(e) => {
  53. f.pad(&format!("hotkey already registered: {:?}", e))
  54. }
  55. HotkeyError::AcceleratorNotRegistered(e) => {
  56. f.pad(&format!("hotkey not registered: {:?}", e))
  57. }
  58. HotkeyError::HotKeyParseError(e) => e.fmt(f),
  59. }
  60. }
  61. }
  62. pub struct GlobalHotKeyEvent {
  63. pub id: u32,
  64. }
  65. impl GlobalHotKeyEvent {
  66. pub fn receiver() -> crossbeam_channel::Receiver<GlobalHotKeyEvent> {
  67. crossbeam_channel::unbounded().1
  68. }
  69. }
  70. pub(crate) type Code = dioxus_html::input_data::keyboard_types::Code;