From 3956b0d03436534440a9365a0bf644c9eddf897d Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sat, 9 May 2026 02:31:16 +0800 Subject: [PATCH] fix(tray): include macOS speed text in click target --- src-tauri/src/utils/tray_speed.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/utils/tray_speed.rs b/src-tauri/src/utils/tray_speed.rs index 58989eebe..1367ac7f4 100644 --- a/src-tauri/src/utils/tray_speed.rs +++ b/src-tauri/src/utils/tray_speed.rs @@ -12,8 +12,8 @@ use objc2::rc::Retained; use objc2::runtime::AnyObject; use objc2_app_kit::{ NSBaselineOffsetAttributeName, NSColor, NSFont, NSFontAttributeName, NSFontWeightRegular, - NSForegroundColorAttributeName, NSMutableParagraphStyle, NSParagraphStyleAttributeName, NSStatusItem, - NSTextAlignment, + NSForegroundColorAttributeName, NSMutableParagraphStyle, NSParagraphStyleAttributeName, NSStatusBarButton, + NSStatusItem, NSTextAlignment, }; use objc2_foundation::{NSAttributedString, NSDictionary, NSNumber, NSString}; @@ -90,6 +90,16 @@ fn create_attributed_string( } } +fn sync_click_target_frame(button: &NSStatusBarButton) { + let bounds = button.bounds(); + let subviews = button.subviews(); + + for index in 0..subviews.count() { + let subview = subviews.objectAtIndex(index); + subview.setFrame(bounds); + } +} + /// 在主线程下设置 NSStatusItem 按钮的富文本标题 /// /// 依赖 Tauri `with_inner_tray_icon` 保证回调在主线程执行; @@ -113,6 +123,7 @@ fn apply_status_item_attributed_title( }; let attr_str = create_attributed_string(text, attrs); button.setAttributedTitle(&attr_str); + sync_click_target_frame(&button); } /// 将速率以富文本形式设置到 NSStatusItem 的按钮上