Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-prevent-default"
description = "Disable default browser shortcuts"
version = "0.7.8"
version = "0.8.0"
homepage = "https://github.com/ferreira-tb/tauri-plugin-prevent-default"
repository = "https://github.com/ferreira-tb/tauri-plugin-prevent-default"
documentation = "https://docs.rs/tauri-plugin-prevent-default"
Expand Down Expand Up @@ -37,12 +37,8 @@ priority = -1
[dependencies]
bitflags = "2.6"
itertools = "0.13"
tauri = "2.0"
thiserror = "2.0"

[dependencies.ahash]
version = "0.8"
optional = true
tauri = "2"
thiserror = "2"

[dependencies.serde]
version = "1.0"
Expand All @@ -65,5 +61,4 @@ version = "2.0"
features = ["build"]

[features]
ahash = ["dep:ahash"]
unstable-native-windows = ["dep:windows", "dep:webview2-com"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Install the plugin by adding the following to your `Cargo.toml` file:

```toml
[dependencies]
tauri-plugin-prevent-default = 0.7
tauri-plugin-prevent-default = 0.8
```

If using custom listeners, you must also enable the required permissions:
Expand Down Expand Up @@ -118,7 +118,7 @@ The `unstable-native-windows` feature must be enabled.

```toml
[dependencies]
tauri-plugin-prevent-default = { version = "0.7", features = ["unstable-native-windows"] }
tauri-plugin-prevent-default = { version = "0.8", features = ["unstable-native-windows"] }
```

```rust
Expand Down
27 changes: 8 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ mod shortcut;
mod state;

use bitflags::bitflags;
use state::PluginState;
use std::collections::HashSet;
use tauri::plugin::{Builder as PluginBuilder, TauriPlugin};
use tauri::{Manager, Runtime};

pub use error::Error;
pub use shortcut::{
KeyboardShortcut, KeyboardShortcutBuilder, ModifierKey, PointerEvent, PointerShortcut,
PointerShortcutBuilder, Shortcut, ShortcutKind,
};
use state::PluginState;
use tauri::plugin::{Builder as PluginBuilder, TauriPlugin};
use tauri::{Manager, Runtime};

#[cfg(feature = "ahash")]
use ahash::{HashSet, HashSetExt};
#[cfg(not(feature = "ahash"))]
use std::collections::HashSet;

bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -196,17 +193,9 @@ impl<R: Runtime> Builder<R> {
if let Some(it) = state.listeners.get_mut(&shortcut) {
it.extend(listeners);
} else {
#[cfg(feature = "ahash")]
let set = {
let mut set = HashSet::new();
set.extend(listeners);
set
};

#[cfg(not(feature = "ahash"))]
let set = HashSet::from_iter(listeners);

state.listeners.insert(shortcut, set);
state
.listeners
.insert(shortcut, HashSet::from_iter(listeners));
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use crate::listener::EventListener;
use tauri::{Runtime, Window};

#[cfg(feature = "ahash")]
use ahash::{HashMap, HashMapExt, HashSet};
#[cfg(not(feature = "ahash"))]
use std::collections::{HashMap, HashSet};
use tauri::{Runtime, Window};

pub(crate) struct PluginState<R: Runtime> {
pub(crate) listeners: HashMap<String, HashSet<EventListener<R>>>,
Expand All @@ -17,9 +13,9 @@ impl<R: Runtime> PluginState<R> {

pub(crate) fn call_listeners(&self, shortcut: &str, window: &Window<R>) {
if let Some(listeners) = self.listeners.get(shortcut) {
for listener in listeners {
listener.call(window);
}
listeners
.iter()
.for_each(|listener| listener.call(window));
}
}
}