Skip to content

Commit 6c9d423

Browse files
author
while
committed
调整 icon
1 parent 0c200e9 commit 6c9d423

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
### 修复
2626

2727
- 修复 macOS 应用图标在 Dock 中偏大的问题,为图标添加透明留白并重新生成各分辨率资源。
28+
- macOS 托盘与 Dock 使用同一机器人图案,独立生成适配菜单栏的小尺寸图标并保留透明留白。
2829
- 修复 macOS 截图框选层被系统菜单栏和程序坞遮挡、无法选取这些区域的问题,并显式开启菜单栏捕获。
2930
- 修复批量重命名规则卡片拖拽排序失效的问题:Windows 上 Tauri 接管了 WebView2 的原生拖放处理导致 HTML5 拖放的放置事件不触发,现改为 pointer 事件手动换位实现,规则与文件行拖拽排序均不受影响。
3031
- 修复批量重命名搜索替换勾选「同时作用于扩展名」时,查找内容带前导点(如 `.js`)无法命中扩展名的问题。
2.95 KB
Loading

‎packages/app/src-tauri/src/tray.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@ pub(crate) fn setup_tray(app: &tauri::App) -> tauri::Result<()> {
7878
let quit = MenuItem::with_id(app, "quit", "退出", true, None::<&str>)?;
7979
let menu = Menu::with_items(app, &[&show, &settings, &quit])?;
8080

81-
TrayIconBuilder::new()
82-
.icon(app.default_window_icon().unwrap().clone())
81+
let builder = TrayIconBuilder::new();
82+
#[cfg(target_os = "macos")]
83+
let builder = builder
84+
.icon(tauri::image::Image::from_bytes(include_bytes!(
85+
"../icons/tray-macos.png"
86+
))?)
87+
.icon_as_template(false);
88+
#[cfg(not(target_os = "macos"))]
89+
let builder = builder.icon(app.default_window_icon().unwrap().clone());
90+
91+
builder
8392
.tooltip("sbox")
8493
.menu(&menu)
8594
.show_menu_on_left_click(false)

‎scripts/mac-icon.swift‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,22 @@ output.append(tableOfContents)
6565
output.append(chunks)
6666
try output.write(to: icons.appendingPathComponent("icon.icns"), options: .atomic)
6767
print("Generated icons/icon.icns (856/1024 artwork, transparent padding)")
68+
69+
// Render the same robot artwork for the 18 pt menu bar slot at 2x resolution.
70+
// A 1 pt transparent inset keeps it clear of the menu bar edges.
71+
let trayContext = CGContext(
72+
data: nil, width: 36, height: 36, bitsPerComponent: 8, bytesPerRow: 36 * 4,
73+
space: CGColorSpace(name: CGColorSpace.sRGB)!,
74+
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
75+
)!
76+
trayContext.clear(CGRect(x: 0, y: 0, width: 36, height: 36))
77+
trayContext.interpolationQuality = .high
78+
trayContext.draw(image, in: CGRect(x: 2, y: 2, width: 32, height: 32))
79+
let trayURL = icons.appendingPathComponent("tray-macos.png")
80+
guard let trayImage = trayContext.makeImage(),
81+
let trayDestination = CGImageDestinationCreateWithURL(trayURL as CFURL, "public.png" as CFString, 1, nil) else {
82+
fatalError("Cannot create macOS tray icon")
83+
}
84+
CGImageDestinationAddImage(trayDestination, trayImage, nil)
85+
guard CGImageDestinationFinalize(trayDestination) else { fatalError("Cannot write macOS tray icon") }
86+
print("Generated icons/tray-macos.png (same robot artwork, 18 pt at 2x)")

0 commit comments

Comments
 (0)