From 9d9a3b4248c9eedd29bc158795e31f311d06a022 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 12:44:47 +0800 Subject: [PATCH 1/5] chore(deps): update rust crate libc to v0.2.189 (#15900) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f97a33cdd6ed..cd16084e8f63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4381,9 +4381,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.178" +version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libdbus-sys" From 046a4da21c37ad8b959be7dfe607a181fb4cda21 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 12:45:22 +0800 Subject: [PATCH 2/5] chore(deps): update rust crate ignore to v0.4.33 (#15827) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd16084e8f63..f4e777eaa44f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1315,7 +1315,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] @@ -2492,7 +2492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3177,9 +3177,9 @@ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" [[package]] name = "globset" -version = "0.4.15" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19" +checksum = "07c34a9410465b45bd9787443bc7370f37735bad04b0f0cd57ff1a3186c98988" dependencies = [ "aho-corasick", "bstr", @@ -3730,9 +3730,9 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.23" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" +checksum = "00b69833ed729dc5aa7d19541d96d6cf8e9137194207a04916d658e43168402f" dependencies = [ "crossbeam-deque", "globset", @@ -7390,7 +7390,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -7403,7 +7403,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -9350,7 +9350,7 @@ dependencies = [ "getrandom 0.2.15", "once_cell", "rustix 0.38.43", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -10611,7 +10611,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.48.0", ] [[package]] From ba0828c76a2d532808ffe88adc94ad04214a1384 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 2 Sep 2026 16:43:15 +0800 Subject: [PATCH 3/5] perf: skip serializing to JSON for `Image::rgba` (#15955) --- .changes/image-rgba-perf.md | 5 +++++ crates/tauri/src/image/plugin.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/image-rgba-perf.md diff --git a/.changes/image-rgba-perf.md b/.changes/image-rgba-perf.md new file mode 100644 index 000000000000..a958aee6f229 --- /dev/null +++ b/.changes/image-rgba-perf.md @@ -0,0 +1,5 @@ +--- +tauri: patch:perf +--- + +Skip serializing to JSON for `Image::rgba` diff --git a/crates/tauri/src/image/plugin.rs b/crates/tauri/src/image/plugin.rs index 039924ae9c0b..71642958ba7d 100644 --- a/crates/tauri/src/image/plugin.rs +++ b/crates/tauri/src/image/plugin.rs @@ -55,10 +55,10 @@ fn from_path() -> std::result::Result<(), &'static str> { } #[command(root = "crate")] -fn rgba(webview: Webview, rid: ResourceId) -> crate::Result> { +fn rgba(webview: Webview, rid: ResourceId) -> crate::Result { let resources_table = webview.resources_table(); let image = resources_table.get::>(rid)?; - Ok(image.rgba().to_vec()) + Ok(crate::ipc::Response::new(image.rgba().to_owned())) } #[derive(Serialize)] From 32efd0232d868984ac8de9efebae19e464c7c536 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 2 Sep 2026 17:21:53 +0800 Subject: [PATCH 4/5] fix: specify `Uint8Array` generic for `Image.rgba` (#15957) * fix: specify `Uint8Array` generic for `Image.rgba` * Add change file --- .changes/image-rgba-uint8array-generic.md | 5 +++++ packages/api/src/image.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changes/image-rgba-uint8array-generic.md diff --git a/.changes/image-rgba-uint8array-generic.md b/.changes/image-rgba-uint8array-generic.md new file mode 100644 index 000000000000..39811807101e --- /dev/null +++ b/.changes/image-rgba-uint8array-generic.md @@ -0,0 +1,5 @@ +--- +"@tauri-apps/api": patch:bug +--- + +`Image.rgba` now returns a more specific type `Promise>` instead of the default `Promise` diff --git a/packages/api/src/image.ts b/packages/api/src/image.ts index 20fb51b7ead7..e1711d97318f 100644 --- a/packages/api/src/image.ts +++ b/packages/api/src/image.ts @@ -86,7 +86,7 @@ export class Image extends Resource { } /** Returns the RGBA data for this image, in row-major order from top to bottom. */ - async rgba(): Promise { + async rgba(): Promise> { return invoke('plugin:image|rgba', { rid: this.rid }).then((buffer) => new Uint8Array(buffer)) From 461221feb6d5636da732278eb4cbd483553c3caa Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 2 Sep 2026 17:47:21 +0800 Subject: [PATCH 5/5] refactor: move `send_user_message` into `Context` (#15960) --- crates/tauri-runtime-wry/src/lib.rs | 894 ++++++++++++---------------- 1 file changed, 391 insertions(+), 503 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index d24875624330..6ae88e7985ce 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -195,7 +195,7 @@ impl WindowIdStore { #[macro_export] macro_rules! getter { ($self: ident, $rx: expr, $message: expr) => {{ - $crate::send_user_message(&$self.context, $message)?; + $self.context.send_user_message($message)?; $rx .recv() .map_err(|_| $crate::Error::FailedToReceiveMessage) @@ -231,28 +231,6 @@ macro_rules! webview_getter { }}; } -pub(crate) fn send_user_message( - context: &Context, - message: Message, -) -> Result<()> { - if current_thread().id() == context.main_thread_id { - handle_user_message( - &context.main_thread.window_target, - message, - UserMessageContext { - window_id_map: &context.window_id_map, - windows: &context.main_thread.windows, - }, - ); - Ok(()) - } else { - context - .proxy - .send_event(message) - .map_err(|_| Error::FailedToSendMessage) - } -} - #[derive(Clone)] pub struct Context { pub window_id_map: WindowIdStore, @@ -282,6 +260,25 @@ impl Context { }) } + fn send_user_message(&self, message: Message) -> Result<()> { + if current_thread().id() == self.main_thread_id { + handle_user_message( + &self.main_thread.window_target, + message, + UserMessageContext { + window_id_map: &self.window_id_map, + windows: &self.main_thread.windows, + }, + ); + Ok(()) + } else { + self + .proxy + .send_event(message) + .map_err(|_| Error::FailedToSendMessage) + } + } + fn next_window_id(&self) -> WindowId { self.next_window_id.fetch_add(1, Ordering::Relaxed).into() } @@ -320,23 +317,20 @@ impl Context { .unwrap_or((None, false)); let (tx, rx) = channel(); - send_user_message( - self, - Message::CreateWindow( - window_id, - Box::new(move |event_loop| { - create_window( - window_id, - webview_id.unwrap_or_default(), - event_loop, - &context, - pending, - after_window_creation, - ) - }), - tx, - ), - )?; + self.send_user_message(Message::CreateWindow( + window_id, + Box::new(move |event_loop| { + create_window( + window_id, + webview_id.unwrap_or_default(), + event_loop, + &context, + pending, + after_window_creation, + ) + }), + tx, + ))?; rx.recv() .map_err(|_| crate::Error::FailedToReceiveMessage)??; @@ -382,25 +376,22 @@ impl Context { let window_id_wrapper_ = window_id_wrapper.clone(); let (tx, rx) = channel(); - send_user_message( - self, - Message::CreateWebview( - window_id, - Box::new(move |window, _options| { - create_webview( - WebviewKind::WindowChild, - window, - window_id_wrapper_, - webview_id, - &context, - pending, - #[cfg(windows)] - _options.focused_webview, - ) - }), - tx, - ), - )?; + self.send_user_message(Message::CreateWebview( + window_id, + Box::new(move |window, _options| { + create_webview( + WebviewKind::WindowChild, + window, + window_id_wrapper_, + webview_id, + &context, + pending, + #[cfg(windows)] + _options.focused_webview, + ) + }), + tx, + ))?; rx.recv() .map_err(|_| crate::Error::FailedToReceiveMessage)??; @@ -1539,7 +1530,7 @@ impl WebviewDispatch for WryWebviewDispatcher { type Runtime = Wry; fn run_on_main_thread(&self, f: F) -> Result<()> { - send_user_message(&self.context, Message::Task(Box::new(f))) + self.context.send_user_message(Message::Task(Box::new(f))) } fn on_webview_event(&self, f: F) -> WindowEventId { @@ -1553,38 +1544,29 @@ impl WebviewDispatch for WryWebviewDispatcher { } fn with_webview) + Send + 'static>(&self, f: F) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::WithWebview(Box::new(move |webview| f(Box::new(webview)))), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::WithWebview(Box::new(move |webview| f(Box::new(webview)))), + )) } #[cfg(any(debug_assertions, feature = "devtools"))] fn open_devtools(&self) { - let _ = send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::OpenDevTools, - ), - ); + let _ = self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::OpenDevTools, + )); } #[cfg(any(debug_assertions, feature = "devtools"))] fn close_devtools(&self) { - let _ = send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::CloseDevTools, - ), - ); + let _ = self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::CloseDevTools, + )); } /// Gets the devtools window's current open state. @@ -1614,104 +1596,77 @@ impl WebviewDispatch for WryWebviewDispatcher { // Setters fn navigate(&self, url: Url) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Navigate(url), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Navigate(url), + )) } fn reload(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Reload, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Reload, + )) } fn print(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Print, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Print, + )) } fn close(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Close, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Close, + )) } fn set_bounds(&self, bounds: tauri_runtime::dpi::Rect) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetBounds(bounds), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetBounds(bounds), + )) } fn set_size(&self, size: Size) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetSize(size), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetSize(size), + )) } fn set_position(&self, position: Position) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetPosition(position), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetPosition(position), + )) } fn set_focus(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetFocus, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetFocus, + )) } fn reparent(&self, window_id: WindowId) -> Result<()> { let mut current_window_id = self.window_id.lock().unwrap(); let (tx, rx) = channel(); - send_user_message( - &self.context, - Message::Webview( - *current_window_id, - self.webview_id, - WebviewMessage::Reparent(window_id, tx), - ), - )?; + self.context.send_user_message(Message::Webview( + *current_window_id, + self.webview_id, + WebviewMessage::Reparent(window_id, tx), + ))?; rx.recv().unwrap()?; @@ -1721,14 +1676,11 @@ impl WebviewDispatch for WryWebviewDispatcher { fn cookies_for_url(&self, url: Url) -> Result>> { let (tx, rx) = channel(); - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::CookiesForUrl(url, tx), - ), - )?; + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::CookiesForUrl(url, tx), + ))?; rx.recv().unwrap() } @@ -1738,38 +1690,29 @@ impl WebviewDispatch for WryWebviewDispatcher { } fn set_cookie(&self, cookie: Cookie<'_>) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetCookie(cookie.into_owned()), - ), - )?; + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetCookie(cookie.into_owned()), + ))?; Ok(()) } fn delete_cookie(&self, cookie: Cookie<'_>) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::DeleteCookie(cookie.into_owned()), - ), - )?; + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::DeleteCookie(cookie.into_owned()), + ))?; Ok(()) } fn set_auto_resize(&self, auto_resize: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetAutoResize(auto_resize), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetAutoResize(auto_resize), + )) } #[cfg(all(feature = "tracing", not(target_os = "android")))] @@ -1789,14 +1732,11 @@ impl WebviewDispatch for WryWebviewDispatcher { #[cfg(not(all(feature = "tracing", not(target_os = "android"))))] fn eval_script>(&self, script: S) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::EvaluateScript(script.into()), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::EvaluateScript(script.into()), + )) } #[cfg(all(feature = "tracing", not(target_os = "android")))] @@ -1829,69 +1769,51 @@ impl WebviewDispatch for WryWebviewDispatcher { script: S, callback: impl Fn(String) + Send + 'static, ) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::EvaluateScriptWithCallback(script.into(), Box::new(callback)), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::EvaluateScriptWithCallback(script.into(), Box::new(callback)), + )) } fn set_zoom(&self, scale_factor: f64) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetZoom(scale_factor), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetZoom(scale_factor), + )) } fn clear_all_browsing_data(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::ClearAllBrowsingData, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::ClearAllBrowsingData, + )) } fn hide(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Hide, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Hide, + )) } fn show(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::Show, - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::Show, + )) } fn set_background_color(&self, color: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Webview( - *self.window_id.lock().unwrap(), - self.webview_id, - WebviewMessage::SetBackgroundColor(color), - ), - ) + self.context.send_user_message(Message::Webview( + *self.window_id.lock().unwrap(), + self.webview_id, + WebviewMessage::SetBackgroundColor(color), + )) } } @@ -1902,7 +1824,7 @@ pub struct WryWindowDispatcher { context: Context, } -// SAFETY: this is safe since the `Context` usage is guarded on `send_user_message`. +// SAFETY: this is safe since the `Context` usage is guarded by `Context::send_user_message`. #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Sync for WryWindowDispatcher {} @@ -1917,7 +1839,7 @@ impl WindowDispatch for WryWindowDispatcher { type WindowBuilder = WindowBuilderWrapper; fn run_on_main_thread(&self, f: F) -> Result<()> { - send_user_message(&self.context, Message::Task(Box::new(f))) + self.context.send_user_message(Message::Task(Box::new(f))) } fn on_window_event(&self, f: F) -> WindowEventId { @@ -2011,10 +1933,10 @@ impl WindowDispatch for WryWindowDispatcher { fn monitor_from_point(&self, x: f64, y: f64) -> Result> { let (tx, rx) = channel(); - let _ = send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::MonitorFromPoint(tx, (x, y))), - ); + let _ = self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::MonitorFromPoint(tx, (x, y)), + )); Ok( rx.recv() @@ -2089,20 +2011,16 @@ impl WindowDispatch for WryWindowDispatcher { // Setters fn center(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Center), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Center)) } fn request_user_attention(&self, request_type: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::RequestUserAttention(request_type.map(Into::into)), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::RequestUserAttention(request_type.map(Into::into)), + )) } // Creates a window by dispatching a message to the event loop. @@ -2125,91 +2043,85 @@ impl WindowDispatch for WryWindowDispatcher { } fn set_resizable(&self, resizable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetResizable(resizable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetResizable(resizable), + )) } fn set_enabled(&self, enabled: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetEnabled(enabled)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetEnabled(enabled), + )) } fn set_maximizable(&self, maximizable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetMaximizable(maximizable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetMaximizable(maximizable), + )) } fn set_minimizable(&self, minimizable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetMinimizable(minimizable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetMinimizable(minimizable), + )) } fn set_closable(&self, closable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetClosable(closable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetClosable(closable), + )) } fn set_title>(&self, title: S) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetTitle(title.into())), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetTitle(title.into()), + )) } fn maximize(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Maximize), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Maximize)) } fn unmaximize(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Unmaximize), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Unmaximize)) } fn minimize(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Minimize), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Minimize)) } fn unminimize(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Unminimize), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Unminimize)) } fn show(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Show), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Show)) } fn hide(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::Hide), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::Hide)) } fn close(&self) -> Result<()> { - // NOTE: close cannot use the `send_user_message` function because it accesses the event loop callback + // NOTE: close cannot use `Context::send_user_message` because it accesses the event loop callback self .context .proxy @@ -2218,7 +2130,7 @@ impl WindowDispatch for WryWindowDispatcher { } fn destroy(&self) -> Result<()> { - // NOTE: destroy cannot use the `send_user_message` function because it accesses the event loop callback + // NOTE: destroy cannot use `Context::send_user_message` because it accesses the event loop callback self .context .proxy @@ -2227,257 +2139,228 @@ impl WindowDispatch for WryWindowDispatcher { } fn set_decorations(&self, decorations: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetDecorations(decorations)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetDecorations(decorations), + )) } fn set_shadow(&self, enable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetShadow(enable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetShadow(enable), + )) } fn set_always_on_bottom(&self, always_on_bottom: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetAlwaysOnBottom(always_on_bottom), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetAlwaysOnBottom(always_on_bottom), + )) } fn set_always_on_top(&self, always_on_top: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetAlwaysOnTop(always_on_top)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetAlwaysOnTop(always_on_top), + )) } fn set_visible_on_all_workspaces(&self, visible_on_all_workspaces: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetVisibleOnAllWorkspaces(visible_on_all_workspaces), + )) } fn set_content_protected(&self, protected: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetContentProtected(protected), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetContentProtected(protected), + )) } fn set_size(&self, size: Size) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetSize(size)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetSize(size), + )) } fn set_min_size(&self, size: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetMinSize(size)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetMinSize(size), + )) } fn set_max_size(&self, size: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetMaxSize(size)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetMaxSize(size), + )) } fn set_size_constraints(&self, constraints: WindowSizeConstraints) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetSizeConstraints(constraints), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetSizeConstraints(constraints), + )) } fn set_position(&self, position: Position) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetPosition(position)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetPosition(position), + )) } fn set_fullscreen(&self, fullscreen: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetFullscreen(fullscreen)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetFullscreen(fullscreen), + )) } #[cfg(target_os = "macos")] fn set_simple_fullscreen(&self, enable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetSimpleFullscreen(enable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetSimpleFullscreen(enable), + )) } fn set_focus(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetFocus), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::SetFocus)) } fn set_focusable(&self, focusable: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetFocusable(focusable)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetFocusable(focusable), + )) } fn set_icon(&self, icon: Icon) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetIcon(TaoIcon::try_from(icon)?.0), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetIcon(TaoIcon::try_from(icon)?.0), + )) } fn set_skip_taskbar(&self, skip: bool) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetSkipTaskbar(skip)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetSkipTaskbar(skip), + )) } fn set_cursor_grab(&self, grab: bool) -> crate::Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetCursorGrab(grab)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetCursorGrab(grab), + )) } fn set_cursor_visible(&self, visible: bool) -> crate::Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetCursorVisible(visible)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetCursorVisible(visible), + )) } fn set_cursor_icon(&self, icon: CursorIcon) -> crate::Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetCursorIcon(icon)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetCursorIcon(icon), + )) } fn set_cursor_position>(&self, position: Pos) -> crate::Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetCursorPosition(position.into()), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetCursorPosition(position.into()), + )) } fn set_ignore_cursor_events(&self, ignore: bool) -> crate::Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetIgnoreCursorEvents(ignore)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetIgnoreCursorEvents(ignore), + )) } fn start_dragging(&self) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::DragWindow), - ) + self + .context + .send_user_message(Message::Window(self.window_id, WindowMessage::DragWindow)) } fn start_resize_dragging(&self, direction: tauri_runtime::ResizeDirection) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::ResizeDragWindow(direction)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::ResizeDragWindow(direction), + )) } fn set_badge_count(&self, count: Option, desktop_filename: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetBadgeCount(count, desktop_filename), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetBadgeCount(count, desktop_filename), + )) } fn set_badge_label(&self, label: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetBadgeLabel(label)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetBadgeLabel(label), + )) } fn set_overlay_icon(&self, icon: Option) -> Result<()> { let icon: Result> = icon.map_or(Ok(None), |x| Ok(Some(TaoIcon::try_from(x)?))); - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetOverlayIcon(icon?)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetOverlayIcon(icon?), + )) } fn set_progress_bar(&self, progress_state: ProgressBarState) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetProgressBar(progress_state), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetProgressBar(progress_state), + )) } fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetTitleBarStyle(style)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetTitleBarStyle(style), + )) } fn set_traffic_light_position(&self, position: Position) -> Result<()> { - send_user_message( - &self.context, - Message::Window( - self.window_id, - WindowMessage::SetTrafficLightPosition(position), - ), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetTrafficLightPosition(position), + )) } fn set_theme(&self, theme: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetTheme(theme)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetTheme(theme), + )) } fn set_background_color(&self, color: Option) -> Result<()> { - send_user_message( - &self.context, - Message::Window(self.window_id, WindowMessage::SetBackgroundColor(color)), - ) + self.context.send_user_message(Message::Window( + self.window_id, + WindowMessage::SetBackgroundColor(color), + )) } } @@ -2640,7 +2523,7 @@ pub struct WryHandle { context: Context, } -// SAFETY: this is safe since the `Context` usage is guarded on `send_user_message`. +// SAFETY: this is safe since the `Context` usage is guarded by `Context::send_user_message`. #[allow(clippy::non_send_fields_in_send_ty)] unsafe impl Sync for WryHandle {} @@ -2652,7 +2535,9 @@ impl WryHandle { ) -> Result> { let id = self.context.next_window_id(); let (tx, rx) = channel(); - send_user_message(&self.context, Message::CreateRawWindow(id, Box::new(f), tx))?; + self + .context + .send_user_message(Message::CreateRawWindow(id, Box::new(f), tx))?; rx.recv().unwrap() } @@ -2693,19 +2578,20 @@ impl RuntimeHandle for WryHandle { #[cfg(target_os = "macos")] fn set_activation_policy(&self, activation_policy: ActivationPolicy) -> Result<()> { - send_user_message( - &self.context, - Message::SetActivationPolicy(activation_policy), - ) + self + .context + .send_user_message(Message::SetActivationPolicy(activation_policy)) } #[cfg(target_os = "macos")] fn set_dock_visibility(&self, visible: bool) -> Result<()> { - send_user_message(&self.context, Message::SetDockVisibility(visible)) + self + .context + .send_user_message(Message::SetDockVisibility(visible)) } fn request_exit(&self, code: i32) -> Result<()> { - // NOTE: request_exit cannot use the `send_user_message` function because it accesses the event loop callback + // NOTE: request_exit cannot use `Context::send_user_message` because it accesses the event loop callback self .context .proxy @@ -2734,7 +2620,7 @@ impl RuntimeHandle for WryHandle { } fn run_on_main_thread(&self, f: F) -> Result<()> { - send_user_message(&self.context, Message::Task(Box::new(f))) + self.context.send_user_message(Message::Task(Box::new(f))) } fn display_handle( @@ -2752,10 +2638,11 @@ impl RuntimeHandle for WryHandle { fn monitor_from_point(&self, x: f64, y: f64) -> Result> { let (tx, rx) = channel(); - send_user_message( - &self.context, - Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::MonitorFromPoint(tx, (x, y))), - )?; + self + .context + .send_user_message(Message::EventLoopWindowTarget( + EventLoopWindowTargetMessage::MonitorFromPoint(tx, (x, y)), + ))?; Ok(rx.recv().unwrap().map(|m| MonitorHandleWrapper(m).into())) } @@ -2776,33 +2663,33 @@ impl RuntimeHandle for WryHandle { } fn set_theme(&self, theme: Option) { - let _ = send_user_message( - &self.context, - Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::SetTheme(theme)), - ); + let _ = self + .context + .send_user_message(Message::EventLoopWindowTarget( + EventLoopWindowTargetMessage::SetTheme(theme), + )); } #[cfg(target_os = "macos")] fn show(&self) -> tauri_runtime::Result<()> { - send_user_message( - &self.context, - Message::Application(ApplicationMessage::Show), - ) + self + .context + .send_user_message(Message::Application(ApplicationMessage::Show)) } #[cfg(target_os = "macos")] fn hide(&self) -> tauri_runtime::Result<()> { - send_user_message( - &self.context, - Message::Application(ApplicationMessage::Hide), - ) + self + .context + .send_user_message(Message::Application(ApplicationMessage::Hide)) } fn set_device_event_filter(&self, filter: DeviceEventFilter) { - let _ = send_user_message( - &self.context, - Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::SetDeviceEventFilter(filter)), - ); + let _ = self + .context + .send_user_message(Message::EventLoopWindowTarget( + EventLoopWindowTargetMessage::SetDeviceEventFilter(filter), + )); } #[cfg(target_os = "android")] @@ -2830,10 +2717,9 @@ impl RuntimeHandle for WryHandle { &self, cb: F, ) -> Result<()> { - send_user_message( - &self.context, - Message::Application(ApplicationMessage::FetchDataStoreIdentifiers(Box::new(cb))), - ) + self.context.send_user_message(Message::Application( + ApplicationMessage::FetchDataStoreIdentifiers(Box::new(cb)), + )) } #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -2842,10 +2728,12 @@ impl RuntimeHandle for WryHandle { uuid: [u8; 16], cb: F, ) -> Result<()> { - send_user_message( - &self.context, - Message::Application(ApplicationMessage::RemoveDataStore(uuid, Box::new(cb))), - ) + self + .context + .send_user_message(Message::Application(ApplicationMessage::RemoveDataStore( + uuid, + Box::new(cb), + ))) } }