From 9b5aa60ba6f6e45ac3fc42dc715d7e071d29bb2b Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 29 Aug 2024 18:44:51 +0300 Subject: [PATCH 1/5] fix: return error instead of panic in `set_skip_taskbar` method (#970) * fix: return error instead of panic in `set_skip_taskbar` method ref: https://github.com/tauri-apps/tauri/issues/10422#issuecomment-2315014576 * change file * Update unix.rs * Apply suggestions from code review --- .changes/skip-taskbar-error.md | 5 +++++ src/platform/unix.rs | 8 ++++---- src/platform/windows.rs | 7 ++++--- src/platform_impl/linux/window.rs | 4 +++- src/platform_impl/windows/event_loop.rs | 2 +- src/platform_impl/windows/window.rs | 17 +++++++++-------- 6 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 .changes/skip-taskbar-error.md diff --git a/.changes/skip-taskbar-error.md b/.changes/skip-taskbar-error.md new file mode 100644 index 000000000..bf4227e5e --- /dev/null +++ b/.changes/skip-taskbar-error.md @@ -0,0 +1,5 @@ +--- +"tao": "minor" +--- + +Changed `WindowExtWindows::set_skip_taskbar` and `WindowExtUnix::set_skip_taskbar` to return a result instead of panicing internally. diff --git a/src/platform/unix.rs b/src/platform/unix.rs index 781c6b36b..743f5be9a 100644 --- a/src/platform/unix.rs +++ b/src/platform/unix.rs @@ -18,7 +18,7 @@ pub use crate::platform_impl::x11; pub use crate::platform_impl::EventLoop as UnixEventLoop; use crate::{ - error::OsError, + error::{ExternalError, OsError}, event_loop::{EventLoopBuilder, EventLoopWindowTarget}, platform_impl::{x11::xdisplay::XError, Parent, Window as UnixWindow}, window::{Window, WindowBuilder}, @@ -77,7 +77,7 @@ pub trait WindowExtUnix { fn default_vbox(&self) -> Option<>k::Box>; /// Whether to show the window icon in the taskbar or not. - fn set_skip_taskbar(&self, skip: bool); + fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError>; } impl WindowExtUnix for Window { @@ -89,8 +89,8 @@ impl WindowExtUnix for Window { self.window.default_vbox.as_ref() } - fn set_skip_taskbar(&self, skip: bool) { - self.window.set_skip_taskbar(skip); + fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError> { + self.window.set_skip_taskbar(skip) } fn new_from_gtk_window( diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 0f05eccd7..0d266b133 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -8,6 +8,7 @@ use std::path::Path; use crate::{ dpi::PhysicalSize, + error::ExternalError, event::DeviceId, event_loop::EventLoopBuilder, monitor::MonitorHandle, @@ -172,7 +173,7 @@ pub trait WindowExtWindows { fn begin_resize_drag(&self, edge: isize, button: u32, x: i32, y: i32); /// Whether to show the window icon in the taskbar or not. - fn set_skip_taskbar(&self, skip: bool); + fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError>; /// Shows or hides the background drop shadow for undecorated windows. /// @@ -224,8 +225,8 @@ impl WindowExtWindows for Window { } #[inline] - fn set_skip_taskbar(&self, skip: bool) { - self.window.set_skip_taskbar(skip); + fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError> { + self.window.set_skip_taskbar(skip) } #[inline] diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index 7bc9a44ba..63e027363 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -920,13 +920,15 @@ impl Window { } } - pub fn set_skip_taskbar(&self, skip: bool) { + pub fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError> { if let Err(e) = self .window_requests_tx .send((self.window_id, WindowRequest::SetSkipTaskbar(skip))) { log::warn!("Fail to send skip taskbar request: {}", e); } + + Ok(()) } pub fn set_progress_bar(&self, progress: ProgressBarState) { diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 472dd40d4..a64ac864a 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -2194,7 +2194,7 @@ unsafe fn public_window_callback_inner( result = ProcResult::Value(LRESULT(0)); } else if msg == *S_U_TASKBAR_RESTART { let window_state = subclass_input.window_state.lock(); - set_skip_taskbar(window, window_state.skip_taskbar); + let _ = set_skip_taskbar(window, window_state.skip_taskbar); } } }; diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index a422c8abf..e61c5cc33 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -955,9 +955,9 @@ impl Window { } #[inline] - pub(crate) fn set_skip_taskbar(&self, skip: bool) { + pub(crate) fn set_skip_taskbar(&self, skip: bool) -> Result<(), ExternalError> { self.window_state.lock().skip_taskbar = skip; - unsafe { set_skip_taskbar(self.hwnd(), skip) }; + unsafe { set_skip_taskbar(self.hwnd(), skip) } } #[inline] @@ -1167,7 +1167,7 @@ unsafe fn init( .lock() .insert(win.id(), KeyEventBuilder::default()); - win.set_skip_taskbar(pl_attribs.skip_taskbar); + let _ = win.set_skip_taskbar(pl_attribs.skip_taskbar); win.set_window_icon(attributes.window_icon); win.set_taskbar_icon(pl_attribs.taskbar_icon); @@ -1373,15 +1373,16 @@ unsafe fn force_window_active(handle: HWND) { let _ = SetForegroundWindow(handle); } -pub(crate) unsafe fn set_skip_taskbar(hwnd: HWND, skip: bool) { +pub(crate) unsafe fn set_skip_taskbar(hwnd: HWND, skip: bool) -> Result<(), ExternalError> { com_initialized(); - let taskbar_list: ITaskbarList = - CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER).expect("failed to create TaskBarList"); + let taskbar_list: ITaskbarList = CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER)?; if skip { - taskbar_list.DeleteTab(hwnd).expect("DeleteTab failed"); + taskbar_list.DeleteTab(hwnd)?; } else { - taskbar_list.AddTab(hwnd).expect("AddTab failed"); + taskbar_list.AddTab(hwnd)?; } + + Ok(()) } impl ResizeDirection { From 222d57862b24511eda733812524df1736cd1f64d Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 2 Sep 2024 16:52:05 +0300 Subject: [PATCH 2/5] fix(windows): fix monitor from_point retunring invalid handle (#971) closes tauri-apps/plugins-workspace#1714 --- .changes/fix-monitor-from-point-handle.md | 5 +++++ src/platform_impl/windows/monitor.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-monitor-from-point-handle.md diff --git a/.changes/fix-monitor-from-point-handle.md b/.changes/fix-monitor-from-point-handle.md new file mode 100644 index 000000000..d65054728 --- /dev/null +++ b/.changes/fix-monitor-from-point-handle.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +On Windows, fix `Window::monitor_from_point` and `EventLoopTargetWindow::monitor_from_point` returning invalid monitor handle. diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 24853e1f5..e209df746 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -133,7 +133,7 @@ pub fn from_point(x: f64, y: f64) -> Option { MONITOR_DEFAULTTONULL, ) }; - if hmonitor.is_invalid() { + if !hmonitor.is_invalid() { Some(MonitorHandle::new(hmonitor)) } else { None From 88f662c22c8f998e047d6867483ef5341ae66198 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:14:03 +0300 Subject: [PATCH 3/5] Publish New Versions (#968) Co-authored-by: amrbashir --- .changes/fix-monitor-from-point-handle.md | 5 ----- .changes/kde-taskbar-progress.md | 5 ----- .changes/skip-taskbar-error.md | 5 ----- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- 5 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 .changes/fix-monitor-from-point-handle.md delete mode 100644 .changes/kde-taskbar-progress.md delete mode 100644 .changes/skip-taskbar-error.md diff --git a/.changes/fix-monitor-from-point-handle.md b/.changes/fix-monitor-from-point-handle.md deleted file mode 100644 index d65054728..000000000 --- a/.changes/fix-monitor-from-point-handle.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"tao": patch ---- - -On Windows, fix `Window::monitor_from_point` and `EventLoopTargetWindow::monitor_from_point` returning invalid monitor handle. diff --git a/.changes/kde-taskbar-progress.md b/.changes/kde-taskbar-progress.md deleted file mode 100644 index a23413a8c..000000000 --- a/.changes/kde-taskbar-progress.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"tao": "patch" ---- - -On Linux, removed internal check for current desktop environment before applying `Window::set_progress_bar` API. This should allow `Window::set_progress_bar` to work on KDE Plasma and similar environments that support `libunity` APIs. diff --git a/.changes/skip-taskbar-error.md b/.changes/skip-taskbar-error.md deleted file mode 100644 index bf4227e5e..000000000 --- a/.changes/skip-taskbar-error.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"tao": "minor" ---- - -Changed `WindowExtWindows::set_skip_taskbar` and `WindowExtUnix::set_skip_taskbar` to return a result instead of panicing internally. diff --git a/CHANGELOG.md b/CHANGELOG.md index b11b2b956..b2a3b833e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## \[0.30.0] + +- [`222d5786`](https://github.com/tauri-apps/tao/commit/222d57862b24511eda733812524df1736cd1f64d) ([#971](https://github.com/tauri-apps/tao/pull/971) by [@amrbashir](https://github.com/tauri-apps/tao/../../amrbashir)) On Windows, fix `Window::monitor_from_point` and `EventLoopTargetWindow::monitor_from_point` returning invalid monitor handle. +- [`e47d4c4a`](https://github.com/tauri-apps/tao/commit/e47d4c4aa08cb1d0f431c6bdf8f81cc82ecc72d1) ([#967](https://github.com/tauri-apps/tao/pull/967) by [@amrbashir](https://github.com/tauri-apps/tao/../../amrbashir)) On Linux, removed internal check for current desktop environment before applying `Window::set_progress_bar` API. This should allow `Window::set_progress_bar` to work on KDE Plasma and similar environments that support `libunity` APIs. +- [`9b5aa60b`](https://github.com/tauri-apps/tao/commit/9b5aa60ba6f6e45ac3fc42dc715d7e071d29bb2b) ([#970](https://github.com/tauri-apps/tao/pull/970) by [@amrbashir](https://github.com/tauri-apps/tao/../../amrbashir)) Changed `WindowExtWindows::set_skip_taskbar` and `WindowExtUnix::set_skip_taskbar` to return a result instead of panicing internally. + ## \[0.29.1] - [`4cd53415`](https://github.com/tauri-apps/tao/commit/4cd534151a2d7a14ade906f960ec02655a91feae) ([#964](https://github.com/tauri-apps/tao/pull/964) by [@lucasfernog](https://github.com/tauri-apps/tao/../../lucasfernog)) Allow Android domain names to include `_1` as escaped `_` characters - required because `_` is the separator for domain parts. diff --git a/Cargo.toml b/Cargo.toml index 3bdd76772..5dddbf637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tao" -version = "0.29.1" +version = "0.30.0" description = "Cross-platform window manager library." authors = [ "Tauri Programme within The Commons Conservancy", From b6adbac15918359b1a2fa032bdf1e227cc629fb7 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 2 Sep 2024 17:30:48 +0300 Subject: [PATCH 4/5] chore: hide cargo generate-lock under Cargo Audit section in covector (#974) --- .changes/config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.changes/config.json b/.changes/config.json index f121a03be..8694ed12e 100644 --- a/.changes/config.json +++ b/.changes/config.json @@ -17,14 +17,14 @@ "dryRunCommand": true }, { - "command": "cargo generate-lockfile", + "command": "echo '
\n

Cargo Audit

\n\n```'", "dryRunCommand": true, - "runFromRoot": true, "pipe": true }, { - "command": "echo '
\n

Cargo Audit

\n\n```'", + "command": "cargo generate-lockfile", "dryRunCommand": true, + "runFromRoot": true, "pipe": true }, { From ad652e50bfca1195481cd347ccaa486818f9334d Mon Sep 17 00:00:00 2001 From: "Campione.Dev" Date: Tue, 3 Sep 2024 17:34:55 +0200 Subject: [PATCH 5/5] feat(iOS): added custom URL schemes handling in the `AppDelegate` class (#969) * feat(iOS): added custom URL schemes handling in the `AppDelegate` class Until now, only ["associated domains"](https://developer.apple.com/documentation/xcode/supporting-associated-domains) were handled, using the `application_continue` function, that implements [this Swift method from the `UIApplicationDelegate` class](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application). For [custom URL schemes](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app), I added a new `application_open_url` function that matches the signature of [this other Swift method](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application). Most of the code of the pre-existing `application_continue` has been moved into a separate `handle_deep_link` function so the new `application_open_url` can call it as well. I believe using the same `Event::Opened` event is appropriate in both situations. Since the scheme is part of the URL, a listener can differentiate between them if needed. **Tauri:** since we are emitting the same `Event::Opened` event, this change works automatically with the ["Deep Linking" plugin](https://v2.tauri.app/plugin/deep-linking/) without further modifications. Custom URL schemes in mobile apps are essential, for example, when dealing with OAuth redirect URLs. * Update .changes/ios-custom-url-schemes.md Co-authored-by: Jason Tsai --------- Co-authored-by: Jason Tsai --- .changes/ios-custom-url-schemes.md | 5 +++ src/platform_impl/ios/view.rs | 51 +++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 .changes/ios-custom-url-schemes.md diff --git a/.changes/ios-custom-url-schemes.md b/.changes/ios-custom-url-schemes.md new file mode 100644 index 000000000..810da0f6f --- /dev/null +++ b/.changes/ios-custom-url-schemes.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +On iOS, implement `application:openURL:options:` to handle custom URL schemes. diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 18b6025b8..bed79b856 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -555,7 +555,40 @@ pub fn create_delegate_class() { YES } + fn handle_deep_link(url: id) { + unsafe { + let absolute_url: id = msg_send![url, absoluteString]; + let bytes = { + let bytes: *const c_char = msg_send![absolute_url, UTF8String]; + bytes as *const u8 + }; + + // 4 represents utf8 encoding + let len = msg_send![absolute_url, lengthOfBytesUsingEncoding: 4]; + let bytes = std::slice::from_raw_parts(bytes, len); + + let url = url::Url::parse(std::str::from_utf8(bytes).unwrap()).unwrap(); + + app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Opened { urls: vec![url] })); + } + } + + // custom URL schemes + // https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app + extern "C" fn application_open_url( + _self: &mut Object, + _cmd: Sel, + _app: id, + url: id, + _options: id, + ) -> BOOL { + handle_deep_link(url); + + YES + } + // universal links + // https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app extern "C" fn application_continue( _: &mut Object, _: Sel, @@ -568,19 +601,8 @@ pub fn create_delegate_class() { if webpage_url == nil { return NO; } - let absolute_url: id = msg_send![webpage_url, absoluteString]; - let bytes = { - let bytes: *const c_char = msg_send![absolute_url, UTF8String]; - bytes as *const u8 - }; - // 4 represents utf8 encoding - let len = msg_send![absolute_url, lengthOfBytesUsingEncoding: 4]; - let bytes = std::slice::from_raw_parts(bytes, len); - - let url = url::Url::parse(std::str::from_utf8(bytes).unwrap()).unwrap(); - - app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Opened { urls: vec![url] })); + handle_deep_link(webpage_url); YES } @@ -631,6 +653,11 @@ pub fn create_delegate_class() { did_finish_launching as extern "C" fn(&mut Object, Sel, id, id) -> BOOL, ); + decl.add_method( + sel!(application:openURL:options:), + application_open_url as extern "C" fn(&mut Object, Sel, id, id, id) -> BOOL, + ); + decl.add_method( sel!(application:continueUserActivity:restorationHandler:), application_continue as extern "C" fn(&mut Object, Sel, id, id, id) -> BOOL,