From b1dcf8ee9e5185377932cc2ecef22c4195abf1b3 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Tue, 10 Oct 2023 19:47:32 +0300 Subject: [PATCH] refactor: enhance event system rust apis --- .changes/tauri-event-system-apis.md | 11 +++ core/tauri/src/event/commands.rs | 26 ++---- core/tauri/src/event/listener.rs | 117 ++++++++++++++++-------- core/tauri/src/event/mod.rs | 50 ++++++---- core/tauri/src/lib.rs | 137 ++++++++++++++-------------- core/tauri/src/manager.rs | 82 ++++++++++------- core/tauri/src/scope/fs.rs | 10 +- core/tauri/src/window.rs | 100 ++++---------------- 8 files changed, 272 insertions(+), 261 deletions(-) create mode 100644 .changes/tauri-event-system-apis.md diff --git a/.changes/tauri-event-system-apis.md b/.changes/tauri-event-system-apis.md new file mode 100644 index 000000000000..d476bfaabba5 --- /dev/null +++ b/.changes/tauri-event-system-apis.md @@ -0,0 +1,11 @@ +--- +'tauri': 'major:breaking' +--- + +The event system APIS on Rust is recieving a few changes for consistency and quality of life improvements: + +- Renamed `Manager::emit_all` to just `Manager::emit` and will now both trigger the events on JS side as well as Rust. +- Removed `Manager::trigger_global`, use `Manager::emit` +- Added `Manager::emit_filter`. +- Changed `Window::emit` to trigger the events on the Rust side as well. +- Removed `Window::emit_and_trigger` and `Window::trigger`, use `Window::emit` instead. diff --git a/core/tauri/src/event/commands.rs b/core/tauri/src/event/commands.rs index d710a84a0279..08e8abb80408 100644 --- a/core/tauri/src/event/commands.rs +++ b/core/tauri/src/event/commands.rs @@ -67,24 +67,10 @@ pub fn emit( window_label: Option, payload: Option, ) -> Result<()> { - // dispatch the event to Rust listeners - window.trigger( - &event.0, - payload.as_ref().and_then(|p| { - serde_json::to_string(&p) - .map_err(|e| { - #[cfg(debug_assertions)] - eprintln!("{e}"); - e - }) - .ok() - }), - ); - - // emit event to JS - if let Some(target) = window_label { - window.emit_to(&target.0, &event.0, payload) - } else { - window.emit_all(&event.0, payload) - } + window.emit_filter(&event.0, payload, |l| { + window_label + .as_ref() + .map(|label| label.0 == l.label()) + .unwrap_or(true) + }) } diff --git a/core/tauri/src/event/listener.rs b/core/tauri/src/event/listener.rs index db1263cf3da8..ea73c3f59c5e 100644 --- a/core/tauri/src/event/listener.rs +++ b/core/tauri/src/event/listener.rs @@ -2,8 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +use crate::{Runtime, Window}; + use super::{Event, EventHandler}; +use serde::Serialize; use std::{ boxed::Box, cell::Cell, @@ -13,32 +16,32 @@ use std::{ use uuid::Uuid; /// What to do with the pending handler when resolving it? -enum Pending { +enum Pending { Unlisten(EventHandler), - Listen(EventHandler, String, Handler), - Trigger(String, Option, Option), + Listen(EventHandler, String, Handler), + Emit(String, Option, Option), } /// Stored in [`Listeners`] to be called upon when the event that stored it is triggered. -struct Handler { - window: Option, +struct Handler { + window: Option>, callback: Box, } /// Holds event handlers and pending event handlers, along with the salts associating them. -struct InnerListeners { - handlers: Mutex>>, - pending: Mutex>, +struct InnerListeners { + handlers: Mutex>>>, + pending: Mutex>>, function_name: Uuid, listeners_object_name: Uuid, } /// A self-contained event manager. -pub struct Listeners { - inner: Arc, +pub struct Listeners { + inner: Arc>, } -impl Default for Listeners { +impl Default for Listeners { fn default() -> Self { Self { inner: Arc::new(InnerListeners { @@ -51,7 +54,7 @@ impl Default for Listeners { } } -impl Clone for Listeners { +impl Clone for Listeners { fn clone(&self) -> Self { Self { inner: self.inner.clone(), @@ -59,7 +62,7 @@ impl Clone for Listeners { } } -impl Listeners { +impl Listeners { /// Randomly generated function name to represent the JavaScript event function. pub(crate) fn function_name(&self) -> String { self.inner.function_name.to_string() @@ -71,7 +74,7 @@ impl Listeners { } /// Insert a pending event action to the queue. - fn insert_pending(&self, action: Pending) { + fn insert_pending(&self, action: Pending) { self .inner .pending @@ -81,7 +84,7 @@ impl Listeners { } /// Finish all pending event actions. - fn flush_pending(&self) { + fn flush_pending(&self) -> crate::Result<()> { let pending = { let mut lock = self .inner @@ -95,12 +98,16 @@ impl Listeners { match action { Pending::Unlisten(id) => self.unlisten(id), Pending::Listen(id, event, handler) => self.listen_(id, event, handler), - Pending::Trigger(ref event, window, payload) => self.trigger(event, window, payload), + Pending::Emit(ref event, window, payload) => { + self.emit(event, window, payload)?; + } } } + + Ok(()) } - fn listen_(&self, id: EventHandler, event: String, handler: Handler) { + fn listen_(&self, id: EventHandler, event: String, handler: Handler) { match self.inner.handlers.try_lock() { Err(_) => self.insert_pending(Pending::Listen(id, event, handler)), Ok(mut lock) => { @@ -109,11 +116,11 @@ impl Listeners { } } - /// Adds an event listener for JS events. + /// Adds an event listener. pub(crate) fn listen( &self, event: String, - window: Option, + window: Option>, handler: F, ) -> EventHandler { let id = EventHandler(Uuid::new_v4()); @@ -127,11 +134,11 @@ impl Listeners { id } - /// Listen to a JS event and immediately unlisten. + /// Listen to an event and immediately unlisten. pub(crate) fn once( &self, event: String, - window: Option, + window: Option>, handler: F, ) -> EventHandler { let self_ = self.clone(); @@ -156,20 +163,45 @@ impl Listeners { } } - /// Triggers the given global event with its payload. - pub(crate) fn trigger(&self, event: &str, window: Option, payload: Option) { + /// Emits the given event with its payload based on a filter. + pub(crate) fn emit_filter( + &self, + event: &str, + window: Option, + payload: Option, + filter: F, + ) -> crate::Result<()> + where + S: Serialize + Clone, + F: Fn(&Window) -> bool, + { let mut maybe_pending = false; match self.inner.handlers.try_lock() { - Err(_) => self.insert_pending(Pending::Trigger(event.to_owned(), window, payload)), + Err(_) => self.insert_pending(Pending::Emit( + event.to_owned(), + window, + payload.map(|p| serde_json::to_string(&p)).transpose()?, + )), Ok(lock) => { if let Some(handlers) = lock.get(event) { - for (&id, handler) in handlers { - if handler.window.is_none() || window == handler.window { - maybe_pending = true; - (handler.callback)(self::Event { - id, - data: payload.clone(), - }) + let handlers = handlers + .iter() + .filter(|h| h.1.window.as_ref().map(|w| filter(w)).unwrap_or(true)) + .collect::>(); + + if !handlers.is_empty() { + let data = payload.map(|p| serde_json::to_string(&p)).transpose()?; + + for (&id, handler) in handlers { + if handler.window.is_none() + || window.as_deref() == handler.window.as_ref().map(|w| w.label()) + { + maybe_pending = true; + (handler.callback)(self::Event { + id, + data: data.clone(), + }) + } } } } @@ -177,14 +209,27 @@ impl Listeners { } if maybe_pending { - self.flush_pending(); + self.flush_pending()?; } + + Ok(()) + } + + /// Emits the given event with its payload. + pub(crate) fn emit( + &self, + event: &str, + window: Option, + payload: Option, + ) -> crate::Result<()> { + self.emit_filter(event, window, payload, |_| true) } } #[cfg(test)] mod test { use super::*; + use crate::test::MockRuntime; use proptest::prelude::*; // dummy event handler function @@ -198,7 +243,7 @@ mod test { // check to see if listen() is properly passing keys into the LISTENERS map #[test] fn listeners_check_key(e in "[a-z]+") { - let listeners: Listeners = Default::default(); + let listeners: Listeners = Default::default(); // clone e as the key let key = e.clone(); // pass e and an dummy func into listen @@ -214,7 +259,7 @@ mod test { // check to see if listen inputs a handler function properly into the LISTENERS map. #[test] fn listeners_check_fn(e in "[a-z]+") { - let listeners: Listeners = Default::default(); + let listeners: Listeners = Default::default(); // clone e as the key let key = e.clone(); // pass e and an dummy func into listen @@ -240,11 +285,11 @@ mod test { // check to see if on_event properly grabs the stored function from listen. #[test] fn check_on_event(key in "[a-z]+", d in "[a-z]+") { - let listeners: Listeners = Default::default(); + let listeners: Listeners = Default::default(); // call listen with e and the event_fn dummy func listeners.listen(key.clone(), None, event_fn); // call on event with e and d. - listeners.trigger(&key, None, Some(d)); + listeners.emit(&key, None, Some(d))?; // lock the mutex let l = listeners.inner.handlers.lock().unwrap(); diff --git a/core/tauri/src/event/mod.rs b/core/tauri/src/event/mod.rs index ddc351d54867..8d877272b72a 100644 --- a/core/tauri/src/event/mod.rs +++ b/core/tauri/src/event/mod.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +use serde::Serialize; use std::{fmt, hash::Hash}; use uuid::Uuid; @@ -38,7 +39,7 @@ impl fmt::Display for EventHandler { } } -/// An event that was triggered. +/// An event that was emitted. #[derive(Debug, Clone)] pub struct Event { id: EventHandler, @@ -68,22 +69,6 @@ pub(crate) fn init() -> TauriPlugin { .build() } -pub fn unlisten_js(listeners_object_name: String, event_name: String, event_id: usize) -> String { - format!( - " - (function () {{ - const listeners = (window['{listeners_object_name}'] || {{}})['{event_name}'] - if (listeners) {{ - const index = window['{listeners_object_name}']['{event_name}'].findIndex(e => e.id === {event_id}) - if (index > -1) {{ - window['{listeners_object_name}']['{event_name}'].splice(index, 1) - }} - }} - }})() - ", - ) -} - pub fn listen_js( listeners_object_name: String, event: String, @@ -118,3 +103,34 @@ pub fn listen_js( }, ) } + +pub fn emit_js( + event_emit_function_name: &str, + event: &str, + source_window_label: Option<&str>, + payload: S, +) -> crate::Result { + Ok(format!( + "(function () {{ const fn = window['{}']; fn && fn({{event: {}, windowLabel: {}, payload: {}}}) }})()", + event_emit_function_name, + serde_json::to_string(event)?, + serde_json::to_string(&source_window_label)?, + serde_json::to_value(payload)?, + )) +} + +pub fn unlisten_js(listeners_object_name: String, event_name: String, event_id: usize) -> String { + format!( + " + (function () {{ + const listeners = (window['{listeners_object_name}'] || {{}})['{event_name}'] + if (listeners) {{ + const index = window['{listeners_object_name}']['{event_name}'].findIndex(e => e.id === {event_id}) + if (index > -1) {{ + window['{listeners_object_name}']['{event_name}'].splice(index, 1) + }} + }} + }})() + ", + ) +} diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index e7902fcd61b6..1f8f7cf12add 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -552,46 +552,6 @@ pub trait Manager: sealed::ManagerBase { self.manager().package_info() } - /// Emits a event to all windows. - /// - /// Only the webviews receives this event. - /// To trigger Rust listeners, use [`Self::trigger_global`], [`Window::trigger`] or [`Window::emit_and_trigger`]. - /// - /// # Examples - /// ``` - /// use tauri::Manager; - /// - /// #[tauri::command] - /// fn synchronize(app: tauri::AppHandle) { - /// // emits the synchronized event to all windows - /// app.emit_all("synchronized", ()); - /// } - /// ``` - fn emit_all(&self, event: &str, payload: S) -> Result<()> { - self.manager().emit_filter(event, None, payload, |_| true) - } - - /// Emits an event to the window with the specified label. - /// - /// # Examples - /// ``` - /// use tauri::Manager; - /// - /// #[tauri::command] - /// fn download(app: tauri::AppHandle) { - /// for i in 1..100 { - /// std::thread::sleep(std::time::Duration::from_millis(150)); - /// // emit a download progress event to the updater window - /// app.emit_to("updater", "download-progress", i); - /// } - /// } - /// ``` - fn emit_to(&self, label: &str, event: &str, payload: S) -> Result<()> { - self - .manager() - .emit_filter(event, None, payload, |w| label == w.label()) - } - /// Listen to a event triggered on any window ([`Window::trigger`] or [`Window::emit_and_trigger`]) or with [`Self::trigger_global`]. /// /// # Examples @@ -620,6 +580,34 @@ pub trait Manager: sealed::ManagerBase { self.manager().listen(event.into(), None, handler) } + /// Remove an event listener. + /// + /// # Examples + /// ``` + /// use tauri::Manager; + /// + /// tauri::Builder::default() + /// .setup(|app| { + /// let handle = app.handle().clone(); + /// let handler = app.listen_global("ready", move |event| { + /// println!("app is ready"); + /// + /// // we no longer need to listen to the event + /// // we also could have used `app.once_global` instead + /// handle.unlisten(event.id()); + /// }); + /// + /// // stop listening to the event when you do not need it anymore + /// app.unlisten(handler); + /// + /// + /// Ok(()) + /// }); + /// ``` + fn unlisten(&self, handler_id: EventHandler) { + self.manager().unlisten(handler_id) + } + /// Listen to a global event only once. /// /// See [`Self::listen_global`] for more information. @@ -630,12 +618,26 @@ pub trait Manager: sealed::ManagerBase { self.manager().once(event.into(), None, handler) } - /// Trigger a global event to Rust listeners. - /// To send the events to the webview, see [`Self::emit_all`] and [`Self::emit_to`]. - /// To trigger listeners registed on an specific window, see [`Window::trigger`]. - /// To trigger all listeners, see [`Window::emit_and_trigger`]. + /// Emits a event to all windows. + /// + /// Only the webviews receives this event. + /// To trigger Rust listeners, use [`Self::trigger_global`], [`Window::trigger`] or [`Window::emit_and_trigger`]. + /// + /// # Examples + /// ``` + /// use tauri::Manager; /// - /// A global event does not have a source or target window attached. + /// #[tauri::command] + /// fn synchronize(app: tauri::AppHandle) { + /// // emits the synchronized event to all windows + /// app.emit("synchronized", ()); + /// } + /// ``` + fn emit(&self, event: &str, payload: S) -> Result<()> { + self.manager().emit_filter(event, None, payload, |_| true) + } + + /// Emits an event to the window with the specified label. /// /// # Examples /// ``` @@ -645,41 +647,38 @@ pub trait Manager: sealed::ManagerBase { /// fn download(app: tauri::AppHandle) { /// for i in 1..100 { /// std::thread::sleep(std::time::Duration::from_millis(150)); - /// // emit a download progress event to all listeners registed in Rust - /// app.trigger_global("download-progress", Some(i.to_string())); + /// // emit a download progress event to the updater window + /// app.emit_to("updater", "download-progress", i); /// } /// } /// ``` - fn trigger_global(&self, event: &str, data: Option) { - self.manager().trigger(event, None, data) + fn emit_to(&self, label: &str, event: &str, payload: S) -> Result<()> { + self + .manager() + .emit_filter(event, None, payload, |w| label == w.label()) } - /// Remove an event listener. + /// Emits an event to the windows based on a filter. /// /// # Examples /// ``` /// use tauri::Manager; /// - /// tauri::Builder::default() - /// .setup(|app| { - /// let handle = app.handle().clone(); - /// let handler = app.listen_global("ready", move |event| { - /// println!("app is ready"); - /// - /// // we no longer need to listen to the event - /// // we also could have used `app.once_global` instead - /// handle.unlisten(event.id()); - /// }); - /// - /// // stop listening to the event when you do not need it anymore - /// app.unlisten(handler); - /// - /// - /// Ok(()) - /// }); + /// #[tauri::command] + /// fn download(app: tauri::AppHandle) { + /// for i in 1..100 { + /// std::thread::sleep(std::time::Duration::from_millis(150)); + /// // emit a download progress event to the updater window + /// app.emit_filter("download-progress", i, |w| w.label() == "main" ); + /// } + /// } /// ``` - fn unlisten(&self, handler_id: EventHandler) { - self.manager().unlisten(handler_id) + fn emit_filter(&self, event: &str, payload: S, filter: F) -> Result<()> + where + S: Serialize + Clone, + F: Fn(&Window) -> bool, + { + self.manager().emit_filter(event, None, payload, filter) } /// Fetch a single window from the manager. diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index bd5320191840..e3027e677731 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -217,7 +217,7 @@ fn replace_csp_nonce( pub struct InnerWindowManager { pub(crate) windows: Mutex>>, pub(crate) plugins: Mutex>, - listeners: Listeners, + listeners: Listeners, pub(crate) state: Arc, /// The JS message handler. @@ -1155,25 +1155,6 @@ impl WindowManager { self.windows_lock().remove(label); } - pub fn emit_filter( - &self, - event: &str, - source_window_label: Option<&str>, - payload: S, - filter: F, - ) -> crate::Result<()> - where - S: Serialize + Clone, - F: Fn(&Window) -> bool, - { - assert_event_name_is_valid(event); - self - .windows_lock() - .values() - .filter(|&w| filter(w)) - .try_for_each(|window| window.emit_internal(event, source_window_label, payload.clone())) - } - pub fn eval_script_all>(&self, script: S) -> crate::Result<()> { let script = script.into(); self @@ -1194,15 +1175,6 @@ impl WindowManager { &self.inner.package_info } - pub fn unlisten(&self, handler_id: EventHandler) { - self.inner.listeners.unlisten(handler_id) - } - - pub fn trigger(&self, event: &str, window: Option, data: Option) { - assert_event_name_is_valid(event); - self.inner.listeners.trigger(event, window, data) - } - pub fn listen( &self, event: String, @@ -1210,7 +1182,14 @@ impl WindowManager { handler: F, ) -> EventHandler { assert_event_name_is_valid(&event); - self.inner.listeners.listen(event, window, handler) + self + .inner + .listeners + .listen(event, window.and_then(|w| self.get_window(&w)), handler) + } + + pub fn unlisten(&self, handler_id: EventHandler) { + self.inner.listeners.unlisten(handler_id) } pub fn once( @@ -1220,7 +1199,48 @@ impl WindowManager { handler: F, ) -> EventHandler { assert_event_name_is_valid(&event); - self.inner.listeners.once(event, window, handler) + self + .inner + .listeners + .once(event, window.and_then(|w| self.get_window(&w)), handler) + } + + pub fn emit_filter( + &self, + event: &str, + source_window_label: Option<&str>, + payload: S, + filter: F, + ) -> crate::Result<()> + where + S: Serialize + Clone, + F: Fn(&Window) -> bool, + { + assert_event_name_is_valid(event); + + self + .windows_lock() + .values() + .filter(|&w| filter(w)) + .try_for_each(|window| window.emit_js(event, source_window_label, payload.clone()))?; + + self.inner.listeners.emit_filter( + event, + source_window_label.map(ToString::to_string), + Some(payload), + filter, + )?; + + Ok(()) + } + + pub fn emit( + self, + event: &str, + source_window_label: Option<&str>, + payload: S, + ) -> crate::Result<()> { + self.emit_filter(event, source_window_label, payload, |_| true) } pub fn event_listeners_object_name(&self) -> String { diff --git a/core/tauri/src/scope/fs.rs b/core/tauri/src/scope/fs.rs index 3d1f57b0e96a..4c61799ef052 100644 --- a/core/tauri/src/scope/fs.rs +++ b/core/tauri/src/scope/fs.rs @@ -145,7 +145,7 @@ impl Scope { id } - fn trigger(&self, event: Event) { + fn emit(&self, event: Event) { let listeners = self.event_listeners.lock().unwrap(); let handlers = listeners.values(); for listener in handlers { @@ -169,7 +169,7 @@ impl Scope { escaped_pattern_with(p, if recursive { "**" } else { "*" }) })?; } - self.trigger(Event::PathAllowed(path.to_path_buf())); + self.emit(Event::PathAllowed(path.to_path_buf())); Ok(()) } @@ -183,7 +183,7 @@ impl Scope { path, escaped_pattern, )?; - self.trigger(Event::PathAllowed(path.to_path_buf())); + self.emit(Event::PathAllowed(path.to_path_buf())); Ok(()) } @@ -202,7 +202,7 @@ impl Scope { escaped_pattern_with(p, if recursive { "**" } else { "*" }) })?; } - self.trigger(Event::PathForbidden(path.to_path_buf())); + self.emit(Event::PathForbidden(path.to_path_buf())); Ok(()) } @@ -216,7 +216,7 @@ impl Scope { path, escaped_pattern, )?; - self.trigger(Event::PathForbidden(path.to_path_buf())); + self.emit(Event::PathForbidden(path.to_path_buf())); Ok(()) } diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index e0c35bcb9ad2..d725f83e1d8d 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -946,24 +946,7 @@ impl PartialEq for Window { } } -impl Manager for Window { - fn emit_to( - &self, - label: &str, - event: &str, - payload: S, - ) -> crate::Result<()> { - self - .manager() - .emit_filter(event, Some(self.label()), payload, |w| label == w.label()) - } - - fn emit_all(&self, event: &str, payload: S) -> crate::Result<()> { - self - .manager() - .emit_filter(event, Some(self.label()), payload, |_| true) - } -} +impl Manager for Window {} impl ManagerBase for Window { fn manager(&self) -> &WindowManager { &self.manager @@ -2281,6 +2264,21 @@ impl Window { Ok(()) } + pub(crate) fn emit_js( + &self, + event: &str, + source_window_label: Option<&str>, + payload: S, + ) -> crate::Result<()> { + self.eval(&crate::event::emit_js( + &self.manager().event_emit_function_name(), + event, + source_window_label, + payload, + )?)?; + Ok(()) + } + /// Whether this window registered a listener to an event from the given window and event name. pub(crate) fn has_js_listener(&self, window_label: Option, event: &str) -> bool { self @@ -2389,50 +2387,6 @@ impl Window { /// Event system APIs. impl Window { - /// Emits an event to both the JavaScript and the Rust listeners. - /// - /// This API is a combination of [`Self::trigger`] and [`Self::emit`]. - /// - /// # Examples - /// ``` - /// use tauri::Manager; - /// - /// #[tauri::command] - /// fn download(window: tauri::Window) { - /// window.emit_and_trigger("download-started", ()); - /// - /// for i in 1..100 { - /// std::thread::sleep(std::time::Duration::from_millis(150)); - /// // emit a download progress event to all listeners - /// window.emit_and_trigger("download-progress", i); - /// } - /// } - /// ``` - pub fn emit_and_trigger( - &self, - event: &str, - payload: S, - ) -> crate::Result<()> { - self.trigger(event, Some(serde_json::to_string(&payload)?)); - self.emit(event, payload) - } - - pub(crate) fn emit_internal( - &self, - event: &str, - source_window_label: Option<&str>, - payload: S, - ) -> crate::Result<()> { - self.eval(&format!( - "(function () {{ const fn = window['{}']; fn && fn({{event: {}, windowLabel: {}, payload: {}}}) }})()", - self.manager.event_emit_function_name(), - serde_json::to_string(event)?, - serde_json::to_string(&source_window_label)?, - serde_json::to_value(payload)?, - ))?; - Ok(()) - } - /// Emits an event to the JavaScript listeners on the current window or globally. /// /// # Examples @@ -2450,7 +2404,7 @@ impl Window { /// ``` pub fn emit(&self, event: &str, payload: S) -> crate::Result<()> { self - .manager + .manager() .emit_filter(event, Some(self.label()), payload, |w| { w.has_js_listener(None, event) || w.has_js_listener(Some(self.label().into()), event) })?; @@ -2524,26 +2478,6 @@ impl Window { let label = self.window.label.clone(); self.manager.once(event.into(), Some(label), handler) } - - /// Triggers an event to the Rust listeners on this window or global listeners. - /// - /// # Examples - /// ``` - /// use tauri::Manager; - /// - /// #[tauri::command] - /// fn download(window: tauri::Window) { - /// for i in 1..100 { - /// std::thread::sleep(std::time::Duration::from_millis(150)); - /// // emit a download progress event to all listeners registed on `window` in Rust - /// window.trigger("download-progress", Some(i.to_string())); - /// } - /// } - /// ``` - pub fn trigger(&self, event: &str, data: Option) { - let label = self.window.label.clone(); - self.manager.trigger(event, Some(label), data) - } } /// The [`WindowEffectsConfig`] object builder