-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
45 lines (38 loc) · 1.22 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use cocoa::base::id;
use notification::NSNotificationCenter;
use objc::{class, msg_send, sel, sel_impl};
use tauri::{
plugin::{Builder, TauriPlugin},
AppHandle, Manager, Runtime,
};
use std::sync::Mutex;
mod color;
mod commands;
mod error;
mod notification;
use color::NSColorConverter;
pub use error::{Error, Result};
fn listen_change_accent_color<R: Runtime>(app: AppHandle<R>) {
let notification = NSNotificationCenter::new(String::from("NSDistributedNotificationCenter"));
let app = Mutex::new(app);
let _ = notification.listen(
String::from("AppleColorPreferencesChangedNotification"),
move |_| {
let app = app.lock().unwrap();
let color: id = unsafe { msg_send![class!(NSColor), controlAccentColor] };
let _ = app
.app_handle()
.emit("on_change_accent_color", color.to_rgba_string());
},
);
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("accent-color")
.invoke_handler(tauri::generate_handler![commands::get_accent_color])
.setup(|app, _| {
#[cfg(target_os = "macos")]
listen_change_accent_color(app.clone());
Ok(())
})
.build()
}