mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
fix mac tray icon to use template icon, no need to know theme any more
This commit is contained in:
@@ -13,6 +13,11 @@ extern "C" bool CanUseNewApiForScreenCaptureCheck() {
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" uint32_t majorVersion() {
|
||||
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
|
||||
return version.majorVersion;
|
||||
}
|
||||
|
||||
extern "C" bool IsCanScreenRecording(bool prompt) {
|
||||
#ifdef NO_InputMonitoringAuthStatus
|
||||
return false;
|
||||
@@ -113,7 +118,7 @@ extern "C" float BackingScaleFactor() {
|
||||
// https://github.com/jhford/screenresolution/blob/master/cg_utils.c
|
||||
// https://github.com/jdoupe/screenres/blob/master/setgetscreen.m
|
||||
|
||||
size_t bitDepth(CGDisplayModeRef mode) {
|
||||
size_t bitDepth(CGDisplayModeRef mode) {
|
||||
size_t depth = 0;
|
||||
// Deprecated, same display same bpp?
|
||||
// https://stackoverflow.com/questions/8210824/how-to-avoid-cgdisplaymodecopypixelencoding-to-get-bpp
|
||||
|
||||
@@ -45,10 +45,15 @@ extern "C" {
|
||||
max: u32,
|
||||
numModes: *mut u32,
|
||||
) -> BOOL;
|
||||
fn majorVersion() -> u32;
|
||||
fn MacGetMode(display: u32, width: *mut u32, height: *mut u32) -> BOOL;
|
||||
fn MacSetMode(display: u32, width: u32, height: u32) -> BOOL;
|
||||
}
|
||||
|
||||
pub fn major_version() -> u32 {
|
||||
unsafe { majorVersion() }
|
||||
}
|
||||
|
||||
pub fn is_process_trusted(prompt: bool) -> bool {
|
||||
unsafe {
|
||||
let value = if prompt { YES } else { NO };
|
||||
|
||||
27
src/tray.rs
27
src/tray.rs
@@ -18,32 +18,12 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
use tao::event_loop::{ControlFlow, EventLoopBuilder};
|
||||
use tray_icon::{
|
||||
menu::{Menu, MenuEvent, MenuItem},
|
||||
TrayEvent, TrayIconBuilder,
|
||||
TrayIconBuilder, TrayIconEvent as TrayEvent,
|
||||
};
|
||||
let icon;
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
const DARK: &[u8] = include_bytes!("../res/mac-tray-dark-x2.png");
|
||||
const LIGHT: &[u8] = include_bytes!("../res/mac-tray-light-x2.png");
|
||||
let output = std::process::Command::new("sw_vers")
|
||||
.args(&["-productVersion"])
|
||||
.output()
|
||||
.map(|x| x.stdout)
|
||||
.unwrap_or_default();
|
||||
let version: f64 = String::from_utf8_lossy(output.as_slice())
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap_or_default();
|
||||
icon = if version >= 14. {
|
||||
// workaround for Sonoma, always light menubar
|
||||
DARK
|
||||
} else {
|
||||
let mode = dark_light::detect();
|
||||
match mode {
|
||||
dark_light::Mode::Dark => LIGHT,
|
||||
_ => DARK,
|
||||
}
|
||||
};
|
||||
icon = include_bytes!("../res/mac-tray-dark-x2.png"); // use as template, so color is not important
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
@@ -57,7 +37,7 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
let rgba = image.into_raw();
|
||||
(rgba, width, height)
|
||||
};
|
||||
let icon = tray_icon::icon::Icon::from_rgba(icon_rgba, icon_width, icon_height)
|
||||
let icon = tray_icon::Icon::from_rgba(icon_rgba, icon_width, icon_height)
|
||||
.context("Failed to open icon")?;
|
||||
|
||||
let event_loop = EventLoopBuilder::new().build();
|
||||
@@ -87,6 +67,7 @@ pub fn make_tray() -> hbb_common::ResultType<()> {
|
||||
.with_menu(Box::new(tray_menu))
|
||||
.with_tooltip(tooltip(0))
|
||||
.with_icon(icon)
|
||||
.with_icon_as_template(true) // mac only
|
||||
.build()?,
|
||||
);
|
||||
let _tray_icon = Arc::new(Mutex::new(_tray_icon));
|
||||
|
||||
Reference in New Issue
Block a user