Merge branch 'tunglies' into dev

This commit is contained in:
Tunglies 2025-04-05 20:00:55 +08:00
commit 2ad20ed239
3 changed files with 31 additions and 22 deletions

View File

@ -309,13 +309,8 @@ impl Tray {
let rate = rate_guard.as_ref();
let rate_bytes = SpeedRate::add_speed_text(is_custom_icon, bytes, rate).unwrap();
let _ = tray.set_icon(Some(tauri::image::Image::from_bytes(&rate_bytes)?));
if !is_custom_icon {
let _ = tray.set_icon_as_template(!is_colorful);
} else {
let _ = tray.set_icon_as_template(false);
}
let _ = tray.set_icon_as_template(!is_custom_icon && !is_colorful);
}
Ok(())
}

View File

@ -119,12 +119,26 @@ impl SpeedRate {
}
}
let is_colorful = if let Some(bytes) = icon_bytes.clone() {
!crate::utils::help::is_monochrome_image_from_bytes(&bytes).unwrap_or(false)
} else {
false
};
// 选择文本颜色
// 单色图标使用白色文本和轻微黑色阴影
let (text_color, shadow_color) = (
Rgba([255u8, 255u8, 255u8, 255u8]),
Rgba([0u8, 0u8, 0u8, 120u8]),
);
let (text_color, shadow_color) = if is_colorful {
(
// Rgba([0u8, 0u8, 0u8, 255u8]),
// Rgba([255u8, 255u8, 255u8, 128u8]),
Rgba([255u8, 255u8, 255u8, 255u8]),
Rgba([0u8, 0u8, 0u8, 08u8]),
)
} else {
(
Rgba([255u8, 255u8, 255u8, 255u8]),
Rgba([0u8, 0u8, 0u8, 128u8]),
)
};
// 减小字体大小以适应文本区域
let font_data = include_bytes!("../../../assets/fonts/SF-Pro.ttf");
let font = FontArc::try_from_vec(font_data.to_vec()).unwrap();

View File

@ -125,18 +125,18 @@ pub fn open_file(_: tauri::AppHandle, path: PathBuf) -> Result<()> {
Ok(())
}
// #[cfg(target_os = "macos")]
// pub fn is_monochrome_image_from_bytes(data: &[u8]) -> anyhow::Result<bool> {
// let img = image::load_from_memory(data)?;
// let rgb_img = img.to_rgb8();
#[cfg(target_os = "macos")]
pub fn is_monochrome_image_from_bytes(data: &[u8]) -> anyhow::Result<bool> {
let img = image::load_from_memory(data)?;
let rgb_img = img.to_rgb8();
// for pixel in rgb_img.pixels() {
// if pixel[0] != pixel[1] || pixel[1] != pixel[2] {
// return Ok(false);
// }
// }
// Ok(true)
// }
for pixel in rgb_img.pixels() {
if pixel[0] != pixel[1] || pixel[1] != pixel[2] {
return Ok(false);
}
}
Ok(true)
}
#[cfg(target_os = "linux")]
pub fn linux_elevator() -> String {