From d513bc26894a2e0cd508908cdffa6226cdedce1b Mon Sep 17 00:00:00 2001 From: Daniel Faust Date: Wed, 8 Jan 2025 21:58:05 +0100 Subject: [PATCH] Fix ci pipeline --- src/items/check.rs | 21 +++++++++++++------ src/platform_impl/windows/dark_menu_bar.rs | 24 +++++++++------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/items/check.rs b/src/items/check.rs index c0d4517c..60ca9e83 100644 --- a/src/items/check.rs +++ b/src/items/check.rs @@ -168,14 +168,23 @@ impl CheckMenuItem { /// Check or Uncheck this check menu item. pub fn set_checked(&self, checked: bool) { - let mut inner = self.inner.borrow_mut(); - inner.set_checked(checked); + #[cfg(target_os = "macos")] + { + let inner = self.inner.borrow(); + inner.set_checked(checked); + } - #[cfg(all(feature = "linux-ksni", target_os = "linux"))] - self.compat.store(Arc::new(Self::compat_menu_item(&inner))); + #[cfg(not(target_os = "macos"))] + { + let mut inner = self.inner.borrow_mut(); + inner.set_checked(checked); - #[cfg(all(feature = "linux-ksni", target_os = "linux"))] - crate::send_menu_update(); + #[cfg(all(feature = "linux-ksni", target_os = "linux"))] + { + self.compat.store(Arc::new(Self::compat_menu_item(&inner))); + crate::send_menu_update(); + } + } } /// Convert this menu item into its menu ID. diff --git a/src/platform_impl/windows/dark_menu_bar.rs b/src/platform_impl/windows/dark_menu_bar.rs index ac105ada..e77bba04 100644 --- a/src/platform_impl/windows/dark_menu_bar.rs +++ b/src/platform_impl/windows/dark_menu_bar.rs @@ -6,6 +6,8 @@ #![allow(non_snake_case, clippy::upper_case_acronyms)] +use std::cell::OnceCell; + use once_cell::sync::Lazy; use windows_sys::{ s, @@ -76,24 +78,18 @@ impl Drop for HBrush { fn background_brush() -> HBRUSH { const BACKGROUND_COLOR: u32 = 2829099; - static mut BACKGROUND_BRUSH: Option = None; - unsafe { - if BACKGROUND_BRUSH.is_none() { - BACKGROUND_BRUSH = Some(HBrush(CreateSolidBrush(BACKGROUND_COLOR))); - } - BACKGROUND_BRUSH.as_ref().unwrap().0 - } + static BACKGROUND_BRUSH: OnceCell = OnceCell::new(); + + let hbrush = BACKGROUND_BRUSH.get_or_init(|| HBrush(CreateSolidBrush(BACKGROUND_COLOR))); + hbrush.as_ref().unwrap().0 } fn selected_background_brush() -> HBRUSH { const SELECTED_BACKGROUND_COLOR: u32 = 4276545; - static mut SELECTED_BACKGROUND_BRUSH: Option = None; - unsafe { - if SELECTED_BACKGROUND_BRUSH.is_none() { - SELECTED_BACKGROUND_BRUSH = Some(HBrush(CreateSolidBrush(SELECTED_BACKGROUND_COLOR))); - } - SELECTED_BACKGROUND_BRUSH.as_ref().unwrap().0 - } + static SELECTED_BACKGROUND_BRUSH: OnceCell = OnceCell::new(); + + let hbrush = SELECTED_BACKGROUND_BRUSH.get_or_init(|| HBrush(CreateSolidBrush(SELECTED_BACKGROUND_COLOR))); + hbrush.as_ref().unwrap().0 } /// Draws a dark menu bar if needed and returns whether it draws it or not