feat: add unread notification badge to dock icon
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#[cfg(target_os = "macos")]
|
||||
use cocoa::{appkit::NSApp, base::nil, foundation::NSString};
|
||||
use std::path::PathBuf;
|
||||
use tauri::utils::config::WindowEffectsConfig;
|
||||
use tauri::window::Effect;
|
||||
@@ -166,3 +168,17 @@ pub fn open_window(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn set_badge(count: i32) {
|
||||
#[cfg(target_os = "macos")]
|
||||
unsafe {
|
||||
let label = if count == 0 {
|
||||
nil
|
||||
} else {
|
||||
NSString::alloc(nil).init_str(&format!("{}", count))
|
||||
};
|
||||
let dock_tile: cocoa::base::id = msg_send![NSApp(), dockTile];
|
||||
let _: cocoa::base::id = msg_send![dock_tile, setBadgeLabel: label];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user