From 83bba508c3cdc6850d969a72e8bd14756575e559 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 3 Jan 2025 18:29:12 +0800 Subject: [PATCH 1/6] Make window and webview getter commands sync --- crates/tauri/src/webview/plugin.rs | 4 ++-- crates/tauri/src/window/plugin.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/tauri/src/webview/plugin.rs b/crates/tauri/src/webview/plugin.rs index aa92050e3..c5875d477 100644 --- a/crates/tauri/src/webview/plugin.rs +++ b/crates/tauri/src/webview/plugin.rs @@ -74,7 +74,7 @@ mod desktop_commands { } #[command(root = "crate")] - pub async fn get_all_webviews(app: AppHandle) -> Vec { + pub fn get_all_webviews(app: AppHandle) -> Vec { app .manager() .webviews() @@ -148,7 +148,7 @@ mod desktop_commands { }; ($fn: ident, $cmd: ident, $ret: ty) => { #[command(root = "crate")] - pub async fn $fn( + pub fn $fn( webview: Webview, label: Option, ) -> crate::Result<$ret> { diff --git a/crates/tauri/src/window/plugin.rs b/crates/tauri/src/window/plugin.rs index 56512d99c..aea0b8e41 100644 --- a/crates/tauri/src/window/plugin.rs +++ b/crates/tauri/src/window/plugin.rs @@ -26,7 +26,7 @@ mod desktop_commands { }; #[command(root = "crate")] - pub async fn get_all_windows(app: AppHandle) -> Vec { + pub fn get_all_windows(app: AppHandle) -> Vec { app.manager().windows().keys().cloned().collect() } @@ -49,7 +49,7 @@ mod desktop_commands { macro_rules! getter { ($cmd: ident, $ret: ty) => { #[command(root = "crate")] - pub async fn $cmd( + pub fn $cmd( window: Window, label: Option, ) -> crate::Result<$ret> { @@ -209,7 +209,7 @@ mod desktop_commands { } #[command(root = "crate")] - pub async fn monitor_from_point( + pub fn monitor_from_point( window: Window, label: Option, x: f64, From 8cd168757f543e420522265fd9e61f130b4727a0 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 3 Jan 2025 18:30:58 +0800 Subject: [PATCH 2/6] Add change file --- .changes/sync-getter-commands.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/sync-getter-commands.md diff --git a/.changes/sync-getter-commands.md b/.changes/sync-getter-commands.md new file mode 100644 index 000000000..79dafba10 --- /dev/null +++ b/.changes/sync-getter-commands.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch:enhance' +--- + +Use sync commands for window and webview commands to reduce overhead and make the final binary size smaller From 4b239824261c02dd570b6be64eb87fb74fe7abf2 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 3 Jan 2025 18:31:45 +0800 Subject: [PATCH 3/6] typo --- .changes/sync-getter-commands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/sync-getter-commands.md b/.changes/sync-getter-commands.md index 79dafba10..2a791cf9a 100644 --- a/.changes/sync-getter-commands.md +++ b/.changes/sync-getter-commands.md @@ -2,4 +2,4 @@ 'tauri': 'patch:enhance' --- -Use sync commands for window and webview commands to reduce overhead and make the final binary size smaller +Use sync commands for window and webview getters to reduce overhead and make the final binary size smaller From 1d29fe8f36879a74ee37830b16c8ea027c659f85 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 3 Jan 2025 18:39:44 +0800 Subject: [PATCH 4/6] format --- crates/tauri/src/webview/plugin.rs | 5 +---- crates/tauri/src/window/plugin.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/tauri/src/webview/plugin.rs b/crates/tauri/src/webview/plugin.rs index c5875d477..ee1f064ca 100644 --- a/crates/tauri/src/webview/plugin.rs +++ b/crates/tauri/src/webview/plugin.rs @@ -148,10 +148,7 @@ mod desktop_commands { }; ($fn: ident, $cmd: ident, $ret: ty) => { #[command(root = "crate")] - pub fn $fn( - webview: Webview, - label: Option, - ) -> crate::Result<$ret> { + pub fn $fn(webview: Webview, label: Option) -> crate::Result<$ret> { get_webview(webview, label)?.$cmd().map_err(Into::into) } }; diff --git a/crates/tauri/src/window/plugin.rs b/crates/tauri/src/window/plugin.rs index aea0b8e41..27714bfc2 100644 --- a/crates/tauri/src/window/plugin.rs +++ b/crates/tauri/src/window/plugin.rs @@ -49,10 +49,7 @@ mod desktop_commands { macro_rules! getter { ($cmd: ident, $ret: ty) => { #[command(root = "crate")] - pub fn $cmd( - window: Window, - label: Option, - ) -> crate::Result<$ret> { + pub fn $cmd(window: Window, label: Option) -> crate::Result<$ret> { get_window(window, label)?.$cmd().map_err(Into::into) } }; From 6a56b26b4c3afb34479b4dbe758c9e3930bd9cc1 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 1 Mar 2025 19:43:52 +0800 Subject: [PATCH 5/6] Use proxy.send_event if we're handling events --- crates/tauri-runtime-wry/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 07626250b..e2641a9ac 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -213,7 +213,7 @@ pub(crate) fn send_user_message( context: &Context, message: Message, ) -> Result<()> { - if current_thread().id() == context.main_thread_id { + if current_thread().id() == context.main_thread_id && context.plugins.try_lock().is_ok() { handle_user_message( &context.main_thread.window_target, message, From e89f96602fd600f461dc170acd4ca29918c1a907 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 1 Mar 2025 20:20:03 +0800 Subject: [PATCH 6/6] Revert "Use proxy.send_event if we're handling events" This reverts commit 6a56b26b4c3afb34479b4dbe758c9e3930bd9cc1. --- crates/tauri-runtime-wry/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index e2641a9ac..07626250b 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -213,7 +213,7 @@ pub(crate) fn send_user_message( context: &Context, message: Message, ) -> Result<()> { - if current_thread().id() == context.main_thread_id && context.plugins.try_lock().is_ok() { + if current_thread().id() == context.main_thread_id { handle_user_message( &context.main_thread.window_target, message,