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 <lucas@tauri.app>
This commit is contained in:
Sean Wang 2025-08-17 02:30:46 +08:00 committed by GitHub
parent b21d86a8a3
commit 22d6bcacbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,7 @@
---
"tauri-runtime-wry": minor:feat
"tauri-runtime": minor:feat
"tauri": minor:feat
---
Implement `App::set_device_event_filter` for `AppHandle` also.

View File

@ -1434,6 +1434,7 @@ pub enum WebviewMessage {
pub enum EventLoopWindowTargetMessage {
CursorPosition(Sender<Result<PhysicalPosition<f64>>>),
SetTheme(Option<Theme>),
SetDeviceEventFilter(DeviceEventFilter),
}
pub type CreateWindowClosure<T> =
@ -2641,6 +2642,13 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
)
}
fn set_device_event_filter(&self, filter: DeviceEventFilter) {
let _ = send_user_message(
&self.context,
Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::SetDeviceEventFilter(filter)),
);
}
#[cfg(target_os = "android")]
fn find_class<'a>(
&self,
@ -3901,6 +3909,9 @@ fn handle_user_message<T: UserEvent>(
EventLoopWindowTargetMessage::SetTheme(theme) => {
event_loop.set_theme(to_tao_theme(theme));
}
EventLoopWindowTargetMessage::SetDeviceEventFilter(filter) => {
event_loop.set_device_event_filter(DeviceEventFilterWrapper::from(filter).0);
}
},
}
}

View File

@ -329,6 +329,15 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
#[cfg_attr(docsrs, doc(cfg(target_os = "macos")))]
fn hide(&self) -> Result<()>;
/// Change the device event filter mode.
///
/// See [Runtime::set_device_event_filter] for details.
///
/// ## Platform-specific
///
/// See [Runtime::set_device_event_filter] for details.
fn set_device_event_filter(&self, filter: DeviceEventFilter);
/// Finds an Android class in the project scope.
#[cfg(target_os = "android")]
fn find_class<'a>(

View File

@ -623,6 +623,17 @@ impl<R: Runtime> AppHandle<R> {
.set_dock_visibility(visible)
.map_err(Into::into)
}
/// Change the device event filter mode.
///
/// See [App::set_device_event_filter] for details.
///
/// ## Platform-specific
///
/// See [App::set_device_event_filter] for details.
pub fn set_device_event_filter(&self, filter: DeviceEventFilter) {
self.runtime_handle.set_device_event_filter(filter);
}
}
impl<R: Runtime> Manager<R> for AppHandle<R> {

View File

@ -270,6 +270,10 @@ impl<T: UserEvent> RuntimeHandle<T> for MockRuntimeHandle {
Ok(())
}
fn set_device_event_filter(&self, _: DeviceEventFilter) {
// no-op
}
#[cfg(target_os = "android")]
fn find_class<'a>(
&self,