appearance.rs

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