Skip to content

Commit 22d6bca

Browse files
WSH032lucasfernog
andauthored
feat(tauri): impl App::set_device_event_filter for AppHandle also (#14008)
* feat(tauri): impl `App::set_device_event_filter` for `AppHandle` also * Update .changes/impl-set_device_event_filter-for-apphandle.md * Update .changes/impl-set_device_event_filter-for-apphandle.md --------- Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
1 parent b21d86a commit 22d6bca

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-runtime-wry": minor:feat
3+
"tauri-runtime": minor:feat
4+
"tauri": minor:feat
5+
---
6+
7+
Implement `App::set_device_event_filter` for `AppHandle` also.

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ pub enum WebviewMessage {
14341434
pub enum EventLoopWindowTargetMessage {
14351435
CursorPosition(Sender<Result<PhysicalPosition<f64>>>),
14361436
SetTheme(Option<Theme>),
1437+
SetDeviceEventFilter(DeviceEventFilter),
14371438
}
14381439

14391440
pub type CreateWindowClosure<T> =
@@ -2641,6 +2642,13 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
26412642
)
26422643
}
26432644

2645+
fn set_device_event_filter(&self, filter: DeviceEventFilter) {
2646+
let _ = send_user_message(
2647+
&self.context,
2648+
Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::SetDeviceEventFilter(filter)),
2649+
);
2650+
}
2651+
26442652
#[cfg(target_os = "android")]
26452653
fn find_class<'a>(
26462654
&self,
@@ -3901,6 +3909,9 @@ fn handle_user_message<T: UserEvent>(
39013909
EventLoopWindowTargetMessage::SetTheme(theme) => {
39023910
event_loop.set_theme(to_tao_theme(theme));
39033911
}
3912+
EventLoopWindowTargetMessage::SetDeviceEventFilter(filter) => {
3913+
event_loop.set_device_event_filter(DeviceEventFilterWrapper::from(filter).0);
3914+
}
39043915
},
39053916
}
39063917
}

crates/tauri-runtime/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,15 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
329329
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
330330
fn hide(&self) -> Result<()>;
331331

332+
/// Change the device event filter mode.
333+
///
334+
/// See [Runtime::set_device_event_filter] for details.
335+
///
336+
/// ## Platform-specific
337+
///
338+
/// See [Runtime::set_device_event_filter] for details.
339+
fn set_device_event_filter(&self, filter: DeviceEventFilter);
340+
332341
/// Finds an Android class in the project scope.
333342
#[cfg(target_os = "android")]
334343
fn find_class<'a>(

crates/tauri/src/app.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,17 @@ impl<R: Runtime> AppHandle<R> {
623623
.set_dock_visibility(visible)
624624
.map_err(Into::into)
625625
}
626+
627+
/// Change the device event filter mode.
628+
///
629+
/// See [App::set_device_event_filter] for details.
630+
///
631+
/// ## Platform-specific
632+
///
633+
/// See [App::set_device_event_filter] for details.
634+
pub fn set_device_event_filter(&self, filter: DeviceEventFilter) {
635+
self.runtime_handle.set_device_event_filter(filter);
636+
}
626637
}
627638

628639
impl<R: Runtime> Manager<R> for AppHandle<R> {

crates/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ impl<T: UserEvent> RuntimeHandle<T> for MockRuntimeHandle {
270270
Ok(())
271271
}
272272

273+
fn set_device_event_filter(&self, _: DeviceEventFilter) {
274+
// no-op
275+
}
276+
273277
#[cfg(target_os = "android")]
274278
fn find_class<'a>(
275279
&self,

0 commit comments

Comments
 (0)