feat: add unread notification badge to dock icon

This commit is contained in:
reya
2024-05-07 14:38:00 +07:00
parent 437cd71f7e
commit c8e1b8b8bd
6 changed files with 69 additions and 66 deletions

View File

@@ -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];
}
}