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 {