appearance.rs

 1use std::ffi::CStr;
 2
 3use crate::platform::Appearance;
 4use cocoa::{
 5    appkit::{NSAppearanceNameVibrantDark, NSAppearanceNameVibrantLight},
 6    base::id,
 7    foundation::NSString,
 8};
 9use objc::{msg_send, sel, sel_impl};
10
11impl Appearance {
12    pub unsafe fn from_native(appearance: id) -> Self {
13        let name: id = msg_send![appearance, name];
14        if name == NSAppearanceNameVibrantLight {
15            Self::VibrantLight
16        } else if name == NSAppearanceNameVibrantDark {
17            Self::VibrantDark
18        } else if name == NSAppearanceNameAqua {
19            Self::Light
20        } else if name == NSAppearanceNameDarkAqua {
21            Self::Dark
22        } else {
23            println!(
24                "unknown appearance: {:?}",
25                CStr::from_ptr(name.UTF8String())
26            );
27            Self::Light
28        }
29    }
30}
31
32#[link(name = "AppKit", kind = "framework")]
33extern "C" {
34    pub static NSAppearanceNameAqua: id;
35    pub static NSAppearanceNameDarkAqua: id;
36}