Skip to content

Commit

Permalink
feat: no-op implementations (#64)
Browse files Browse the repository at this point in the history
closes #63
  • Loading branch information
amrbashir authored Mar 7, 2024
1 parent 89f9679 commit 89199d9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/no-op.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"global-hotkey": "patch"
---

Add no-op implementations for unsupported targets.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ use hotkey::HotKey;
/// Describes the state of the [`HotKey`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum HotKeyState {
/// The [`HotKey`] is pressed (the key is down).
/// The [`HotKey`] is pressed (the key is down).
Pressed,
/// The [`HotKey`] is released (the key is up).
/// The [`HotKey`] is released (the key is up).
Released,
}

Expand Down
20 changes: 19 additions & 1 deletion src/platform_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
#[cfg(target_os = "windows")]
#[path = "windows/mod.rs"]
mod platform;
#[cfg(target_os = "linux")]
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
))]
#[path = "x11/mod.rs"]
mod platform;
#[cfg(target_os = "macos")]
#[path = "macos/mod.rs"]
mod platform;

#[cfg(not(any(
target_os = "windows",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos"
)))]
#[path = "no-op.rs"]
mod platform;

pub(crate) use self::platform::*;
38 changes: 38 additions & 0 deletions src/platform_impl/no-op.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
// Copyright 2022-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use crate::hotkey::HotKey;

pub struct GlobalHotKeyManager {}

impl GlobalHotKeyManager {
pub fn new() -> crate::Result<Self> {
Ok(Self {})
}

pub fn register(&self, hotkey: HotKey) -> crate::Result<()> {
Ok(())
}

pub fn unregister(&self, hotkey: HotKey) -> crate::Result<()> {
Ok(())
}

pub fn register_all(&self, hotkeys: &[HotKey]) -> crate::Result<()> {
for hotkey in hotkeys {
self.register(*hotkey)?;
}
Ok(())
}

pub fn unregister_all(&self, hotkeys: &[HotKey]) -> crate::Result<()> {
for hotkey in hotkeys {
self.unregister(*hotkey)?;
}
Ok(())
}
}

0 comments on commit 89199d9

Please sign in to comment.