Skip to content

Commit

Permalink
fix: return error instead of panic in set_skip_taskbar method
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Aug 28, 2024
1 parent e47d4c4 commit 6789b2d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait WindowExtUnix {
fn default_vbox(&self) -> Option<&gtk::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 {
Expand All @@ -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<T: 'static>(
Expand Down
7 changes: 4 additions & 3 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::Path;

use crate::{
dpi::PhysicalSize,
error::ExternalError,
event::DeviceId,
event_loop::EventLoopBuilder,
monitor::MonitorHandle,
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
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);
}
}
};
Expand Down
17 changes: 9 additions & 8 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -1167,7 +1167,7 @@ unsafe fn init<T: 'static>(
.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);

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6789b2d

Please sign in to comment.