mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-16 19:30:27 +03:00
* fix(event): let once event return EventId * Update .changes/core-once-event-return-event-id.md
This commit is contained in:
parent
18ff84fc81
commit
3fb414b61a
5
.changes/core-once-event-return-event-id.md
Normal file
5
.changes/core-once-event-return-event-id.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'patch:enhance'
|
||||
---
|
||||
|
||||
Return an id when using from `Manager::once_any`, `App::once`, `Window::once`, `Webview::once`, `WebviewWindow::once` and `fs::Scope::once`.
|
@ -845,7 +845,7 @@ macro_rules! shared_app_impl {
|
||||
/// Listen to an event on this app only once.
|
||||
///
|
||||
/// See [`Self::listen`] for more information.
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F)
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
|
||||
where
|
||||
F: FnOnce(Event) + Send + 'static,
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ impl Listeners {
|
||||
event: String,
|
||||
target: EventTarget,
|
||||
handler: F,
|
||||
) {
|
||||
) -> EventId {
|
||||
let self_ = self.clone();
|
||||
let handler = Cell::new(Some(handler));
|
||||
|
||||
@ -170,7 +170,7 @@ impl Listeners {
|
||||
.expect("attempted to call handler more than once");
|
||||
handler(event);
|
||||
self_.unlisten(id);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/// Removes an event listener.
|
||||
|
@ -655,7 +655,7 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
|
||||
/// Listens once to an emitted event to any [target](EventTarget) .
|
||||
///
|
||||
/// See [`Self::listen_any`] for more information.
|
||||
fn once_any<F>(&self, event: impl Into<String>, handler: F)
|
||||
fn once_any<F>(&self, event: impl Into<String>, handler: F) -> EventId
|
||||
where
|
||||
F: FnOnce(Event) + Send + 'static,
|
||||
{
|
||||
|
@ -469,7 +469,7 @@ impl<R: Runtime> AppManager<R> {
|
||||
event: String,
|
||||
target: EventTarget,
|
||||
handler: F,
|
||||
) {
|
||||
) -> EventId {
|
||||
assert_event_name_is_valid(&event);
|
||||
self.listeners().once(event, target, handler)
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ impl Scope {
|
||||
}
|
||||
|
||||
/// Listen to an event on this scope and immediately unlisten.
|
||||
pub fn once<F: FnOnce(&Event) + Send + 'static>(&self, f: F) {
|
||||
pub fn once<F: FnOnce(&Event) + Send + 'static>(&self, f: F) -> ScopeEventId {
|
||||
let listerners = self.event_listeners.clone();
|
||||
let handler = std::cell::Cell::new(Some(f));
|
||||
let id = self.next_event_id();
|
||||
@ -212,6 +212,7 @@ impl Scope {
|
||||
.expect("attempted to call handler more than once");
|
||||
handler(event)
|
||||
});
|
||||
id
|
||||
}
|
||||
|
||||
/// Removes an event listener on this scope.
|
||||
|
@ -1460,7 +1460,7 @@ tauri::Builder::default()
|
||||
/// Listen to an event on this webview only once.
|
||||
///
|
||||
/// See [`Self::listen`] for more information.
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F)
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
|
||||
where
|
||||
F: FnOnce(Event) + Send + 'static,
|
||||
{
|
||||
|
@ -1766,7 +1766,7 @@ tauri::Builder::default()
|
||||
/// Listen to an event on this window webview only once.
|
||||
///
|
||||
/// See [`Self::listen`] for more information.
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F)
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
|
||||
where
|
||||
F: FnOnce(Event) + Send + 'static,
|
||||
{
|
||||
|
@ -1992,7 +1992,7 @@ tauri::Builder::default()
|
||||
/// Listen to an event on this window only once.
|
||||
///
|
||||
/// See [`Self::listen`] for more information.
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F)
|
||||
pub fn once<F>(&self, event: impl Into<String>, handler: F) -> EventId
|
||||
where
|
||||
F: FnOnce(Event) + Send + 'static,
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user