cc-pets 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +11 -6
- package/CC_BRIDGE.zh-CN.md +8 -4
- package/CHANGELOG.md +59 -1
- package/CHANGELOG.zh-CN.md +59 -1
- package/README.md +60 -12
- package/README.zh-CN.md +58 -13
- package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +297 -0
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +187 -0
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +322 -0
- package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +205 -0
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +458 -0
- package/Sources/CCPets/CCPetsAppDelegate.h +17 -16
- package/Sources/CCPets/CCPetsAppDelegate.m +74 -2406
- package/Sources/CCPets/CCPetsCleanup.h +4 -0
- package/Sources/CCPets/CCPetsCleanup.m +35 -2
- package/Sources/CCPets/CCPetsCodexRateLimits.h +1 -0
- package/Sources/CCPets/CCPetsCodexRateLimits.m +7 -0
- package/Sources/CCPets/CCPetsEvents.m +1 -1
- package/Sources/CCPets/CCPetsGlassMenu.h +10 -0
- package/Sources/CCPets/CCPetsGlassMenu.m +196 -0
- package/Sources/CCPets/CCPetsGlassView.h +31 -0
- package/Sources/CCPets/CCPetsGlassView.m +246 -0
- package/Sources/CCPets/CCPetsPaths.h +7 -1
- package/Sources/CCPets/CCPetsPaths.m +14 -1
- package/Sources/CCPets/CCPetsTerminalFocus.h +15 -0
- package/Sources/CCPets/CCPetsTerminalFocus.m +306 -15
- package/Sources/CCPets/CCPetsUsage.h +2 -1
- package/Sources/CCPets/CCPetsUsage.m +69 -21
- package/Sources/CCPets/CCPetsUsageMonitor.m +43 -8
- package/Sources/CCPets/CCPetsVersion.h +7 -0
- package/Sources/CCPets/CCPetsVersion.m +82 -0
- package/Sources/CCPets/MenuChoiceRow.h +19 -0
- package/Sources/CCPets/MenuChoiceRow.m +96 -0
- package/Sources/CCPets/MenuHintView.h +15 -0
- package/Sources/CCPets/MenuHintView.m +128 -0
- package/Sources/CCPets/PetView.h +2 -0
- package/Sources/CCPets/PetView.m +121 -53
- package/Sources/CCPets/QuotaDashboardView.h +3 -4
- package/Sources/CCPets/QuotaDashboardView.m +222 -146
- package/Sources/CCPets/main.m +29 -0
- package/bin/cc-pets +39 -1
- package/bin/codex-with-pet +2 -0
- package/package.json +3 -2
- package/scripts/bridge/cli.mjs +9 -2
- package/scripts/bridge/core.mjs +1 -1
- package/scripts/bridge/install.mjs +23 -1
- package/scripts/bridge/process.mjs +22 -0
- package/scripts/doctor.mjs +456 -0
- package/scripts/install-claude-hooks.mjs +12 -18
- package/scripts/install-codex-hooks.mjs +3 -9
- package/scripts/integration-markers.mjs +51 -0
- package/scripts/pet-store.mjs +2 -1
- package/scripts/uninstall-integrations.mjs +16 -44
- package/scripts/uninstall-shell-integration.sh +3 -3
|
@@ -80,3 +80,85 @@ BOOL UpdateFailureIsTransient(NSString *log) {
|
|
|
80
80
|
}
|
|
81
81
|
return NO;
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
static NSString *StripReleaseNoteMarkdown(NSString *text) {
|
|
85
|
+
static NSRegularExpression *link, *image;
|
|
86
|
+
static dispatch_once_t once;
|
|
87
|
+
dispatch_once(&once, ^{
|
|
88
|
+
image = [NSRegularExpression regularExpressionWithPattern:@"!\\[[^\\]]*\\]\\([^)]*\\)"
|
|
89
|
+
options:0 error:nil];
|
|
90
|
+
link = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\]]*)\\]\\([^)]*\\)"
|
|
91
|
+
options:0 error:nil];
|
|
92
|
+
});
|
|
93
|
+
NSMutableString *result = [text mutableCopy];
|
|
94
|
+
[image replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@""];
|
|
95
|
+
[link replaceMatchesInString:result options:0 range:NSMakeRange(0, result.length) withTemplate:@"$1"];
|
|
96
|
+
for (NSString *marker in @[@"**", @"__", @"`"]) {
|
|
97
|
+
[result replaceOccurrencesOfString:marker withString:@"" options:0
|
|
98
|
+
range:NSMakeRange(0, result.length)];
|
|
99
|
+
}
|
|
100
|
+
return [result stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
NSArray<NSString *> *ReleaseNoteHighlights(NSString *body, NSUInteger limit, NSUInteger maxLength,
|
|
104
|
+
BOOL *truncated) {
|
|
105
|
+
if (truncated) *truncated = NO;
|
|
106
|
+
if (![body isKindOfClass:NSString.class] || body.length == 0 || limit == 0) return @[];
|
|
107
|
+
NSArray<NSString *> *lines = [[body stringByReplacingOccurrencesOfString:@"\r" withString:@""]
|
|
108
|
+
componentsSeparatedByString:@"\n"];
|
|
109
|
+
|
|
110
|
+
// 有「简体中文」段就只取这一段:从它的标题开始,到下一个同级或更高级标题为止。
|
|
111
|
+
NSRange section = NSMakeRange(0, lines.count);
|
|
112
|
+
for (NSUInteger index = 0; index < lines.count; index++) {
|
|
113
|
+
NSString *line = [lines[index] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
114
|
+
if (![line hasPrefix:@"#"]) continue;
|
|
115
|
+
NSUInteger level = 0;
|
|
116
|
+
while (level < line.length && [line characterAtIndex:level] == '#') level++;
|
|
117
|
+
NSString *title = [[line substringFromIndex:level]
|
|
118
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
119
|
+
if (![title isEqualToString:@"简体中文"] && ![title isEqualToString:@"中文"]) continue;
|
|
120
|
+
NSUInteger end = lines.count;
|
|
121
|
+
for (NSUInteger next = index + 1; next < lines.count; next++) {
|
|
122
|
+
NSString *candidate = lines[next];
|
|
123
|
+
if (![candidate hasPrefix:@"#"]) continue;
|
|
124
|
+
NSUInteger nextLevel = 0;
|
|
125
|
+
while (nextLevel < candidate.length && [candidate characterAtIndex:nextLevel] == '#') nextLevel++;
|
|
126
|
+
if (nextLevel <= level) { end = next; break; }
|
|
127
|
+
}
|
|
128
|
+
section = NSMakeRange(index + 1, end - index - 1);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static NSRegularExpression *bullet;
|
|
133
|
+
static dispatch_once_t once;
|
|
134
|
+
dispatch_once(&once, ^{
|
|
135
|
+
// 只认顶层列表项(行首不缩进),嵌套的子项是补充说明,挤不进三条要点。
|
|
136
|
+
bullet = [NSRegularExpression regularExpressionWithPattern:@"^(?:[-*+]|\\d+[.)])\\s+(.+)$"
|
|
137
|
+
options:0 error:nil];
|
|
138
|
+
});
|
|
139
|
+
NSMutableArray<NSString *> *items = [NSMutableArray array];
|
|
140
|
+
BOOL inFence = NO;
|
|
141
|
+
for (NSUInteger index = section.location; index < NSMaxRange(section); index++) {
|
|
142
|
+
NSString *line = lines[index];
|
|
143
|
+
if ([[line stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet] hasPrefix:@"```"]) {
|
|
144
|
+
inFence = !inFence;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (inFence) continue;
|
|
148
|
+
NSTextCheckingResult *match = [bullet firstMatchInString:line options:0
|
|
149
|
+
range:NSMakeRange(0, line.length)];
|
|
150
|
+
if (!match) continue;
|
|
151
|
+
NSString *text = StripReleaseNoteMarkdown([line substringWithRange:[match rangeAtIndex:1]]);
|
|
152
|
+
if (text.length == 0) continue;
|
|
153
|
+
if (items.count == limit) {
|
|
154
|
+
if (truncated) *truncated = YES;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (maxLength > 0 && text.length > maxLength) {
|
|
158
|
+
NSRange keep = [text rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, maxLength)];
|
|
159
|
+
text = [[text substringWithRange:keep] stringByAppendingString:@"…"];
|
|
160
|
+
}
|
|
161
|
+
[items addObject:text];
|
|
162
|
+
}
|
|
163
|
+
return items;
|
|
164
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
// 菜单里的单选行。普通 NSMenuItem 点完菜单就收起,想连着对比几个档位就得反复右键;
|
|
4
|
+
// 自绘行视图收到点击时菜单不会关闭。同一 group 的行互斥勾选,点击后同一菜单里所有行
|
|
5
|
+
// 重新计算 enabledHandler,让「切到经典主题后压暗档位置灰」这类联动当场生效。
|
|
6
|
+
@interface MenuChoiceRowView : NSView
|
|
7
|
+
@property(nonatomic, copy) NSString *title;
|
|
8
|
+
@property(nonatomic, copy) NSString *group;
|
|
9
|
+
@property(nonatomic) BOOL checked;
|
|
10
|
+
@property(nonatomic) BOOL enabled;
|
|
11
|
+
@property(nonatomic) CGFloat indentation;
|
|
12
|
+
@property(nonatomic, strong) id representedObject;
|
|
13
|
+
@property(nonatomic, weak) id target;
|
|
14
|
+
@property(nonatomic) SEL action;
|
|
15
|
+
@property(nonatomic, copy) BOOL (^enabledHandler)(void);
|
|
16
|
+
+ (NSMenuItem *)addToMenu:(NSMenu *)menu title:(NSString *)title group:(NSString *)group
|
|
17
|
+
representedObject:(id)representedObject checked:(BOOL)checked
|
|
18
|
+
target:(id)target action:(SEL)action width:(CGFloat)width;
|
|
19
|
+
@end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#import "MenuChoiceRow.h"
|
|
2
|
+
|
|
3
|
+
@implementation MenuChoiceRowView
|
|
4
|
+
+ (NSMenuItem *)addToMenu:(NSMenu *)menu title:(NSString *)title group:(NSString *)group
|
|
5
|
+
representedObject:(id)representedObject checked:(BOOL)checked
|
|
6
|
+
target:(id)target action:(SEL)action width:(CGFloat)width {
|
|
7
|
+
// item 要有 action 才会被菜单高亮。鼠标点击由行视图自己处理(菜单不关);
|
|
8
|
+
// 用键盘选中后按回车走的是这个 action,行为与点击一致,菜单照常关闭。
|
|
9
|
+
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:@selector(chooseFromMenuItem:)
|
|
10
|
+
keyEquivalent:@""];
|
|
11
|
+
MenuChoiceRowView *row = [[MenuChoiceRowView alloc] initWithFrame:NSMakeRect(0, 0, width, 24)];
|
|
12
|
+
row.autoresizingMask = NSViewWidthSizable;
|
|
13
|
+
row.title = title;
|
|
14
|
+
row.group = group;
|
|
15
|
+
row.representedObject = representedObject;
|
|
16
|
+
row.checked = checked;
|
|
17
|
+
row.enabled = YES;
|
|
18
|
+
row.target = target;
|
|
19
|
+
row.action = action;
|
|
20
|
+
[row setAccessibilityRole:NSAccessibilityRadioButtonRole];
|
|
21
|
+
[row setAccessibilityLabel:title];
|
|
22
|
+
item.target = row;
|
|
23
|
+
item.view = row;
|
|
24
|
+
[menu addItem:item];
|
|
25
|
+
return item;
|
|
26
|
+
}
|
|
27
|
+
- (void)chooseFromMenuItem:(id)sender { [self choose]; }
|
|
28
|
+
// 手绘行不是 NSButton,VoiceOver 的"按下"要自己接到 choose 上。
|
|
29
|
+
- (BOOL)accessibilityPerformPress {
|
|
30
|
+
if (!self.enabled) return NO;
|
|
31
|
+
[self choose];
|
|
32
|
+
return YES;
|
|
33
|
+
}
|
|
34
|
+
// 置灰的行不让菜单高亮,和系统禁用项一致。
|
|
35
|
+
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { return self.enabled; }
|
|
36
|
+
- (void)setChecked:(BOOL)checked {
|
|
37
|
+
_checked = checked;
|
|
38
|
+
[self setAccessibilityValue:@(checked)];
|
|
39
|
+
self.needsDisplay = YES;
|
|
40
|
+
}
|
|
41
|
+
- (void)setEnabled:(BOOL)enabled {
|
|
42
|
+
_enabled = enabled;
|
|
43
|
+
[self setAccessibilityEnabled:enabled];
|
|
44
|
+
self.needsDisplay = YES;
|
|
45
|
+
}
|
|
46
|
+
// 不实现 mouseDown: 的话按下事件会沿响应链交给菜单,菜单会当作一次普通选择然后收起。
|
|
47
|
+
- (void)mouseDown:(NSEvent *)event {}
|
|
48
|
+
- (void)mouseUp:(NSEvent *)event {
|
|
49
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
50
|
+
if (NSPointInRect(point, self.bounds)) [self choose];
|
|
51
|
+
}
|
|
52
|
+
- (void)choose {
|
|
53
|
+
if (!self.enabled || self.checked) return;
|
|
54
|
+
[NSApp sendAction:self.action to:self.target from:self];
|
|
55
|
+
for (NSMenuItem *item in self.enclosingMenuItem.menu.itemArray) {
|
|
56
|
+
if (![item.view isKindOfClass:MenuChoiceRowView.class]) continue;
|
|
57
|
+
MenuChoiceRowView *row = (MenuChoiceRowView *)item.view;
|
|
58
|
+
if ([row.group isEqualToString:self.group]) row.checked = row == self;
|
|
59
|
+
if (row.enabledHandler) row.enabled = row.enabledHandler();
|
|
60
|
+
}
|
|
61
|
+
[self.enclosingMenuItem.menu update];
|
|
62
|
+
}
|
|
63
|
+
- (void)drawRect:(NSRect)dirtyRect {
|
|
64
|
+
// 高亮跟随菜单自己的高亮项,而不是自己跟踪鼠标进出:菜单跟踪期间 mouseExited 经常
|
|
65
|
+
// 收不到,自己跟踪会让划过的每一行都停在高亮。菜单同一时刻只高亮一项,切换时会重绘视图。
|
|
66
|
+
BOOL highlighted = self.enclosingMenuItem.isHighlighted && self.enabled;
|
|
67
|
+
if (highlighted) {
|
|
68
|
+
[NSColor.selectedContentBackgroundColor setFill];
|
|
69
|
+
[[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds, 5, 0)
|
|
70
|
+
xRadius:6 yRadius:6] fill];
|
|
71
|
+
}
|
|
72
|
+
NSColor *textColor = !self.enabled ? NSColor.tertiaryLabelColor
|
|
73
|
+
: (highlighted ? NSColor.selectedMenuItemTextColor : NSColor.labelColor);
|
|
74
|
+
CGFloat x = 12 + self.indentation;
|
|
75
|
+
if (self.checked) {
|
|
76
|
+
NSImageSymbolConfiguration *configuration = [NSImageSymbolConfiguration
|
|
77
|
+
configurationWithPointSize:11 weight:NSFontWeightSemibold];
|
|
78
|
+
NSImage *mark = [[NSImage imageWithSystemSymbolName:@"checkmark"
|
|
79
|
+
accessibilityDescription:nil] imageWithSymbolConfiguration:configuration];
|
|
80
|
+
NSImage *tinted = [NSImage imageWithSize:mark.size flipped:NO
|
|
81
|
+
drawingHandler:^BOOL(NSRect rect) {
|
|
82
|
+
[mark drawInRect:rect];
|
|
83
|
+
[textColor set];
|
|
84
|
+
NSRectFillUsingOperation(rect, NSCompositingOperationSourceAtop);
|
|
85
|
+
return YES;
|
|
86
|
+
}];
|
|
87
|
+
[tinted drawInRect:NSMakeRect(x, (NSHeight(self.bounds) - mark.size.height) / 2.0,
|
|
88
|
+
mark.size.width, mark.size.height)];
|
|
89
|
+
}
|
|
90
|
+
NSDictionary *attributes = @{NSFontAttributeName: [NSFont menuFontOfSize:13],
|
|
91
|
+
NSForegroundColorAttributeName: textColor};
|
|
92
|
+
NSSize size = [self.title sizeWithAttributes:attributes];
|
|
93
|
+
[self.title drawAtPoint:NSMakePoint(x + 18, (NSHeight(self.bounds) - size.height) / 2.0)
|
|
94
|
+
withAttributes:attributes];
|
|
95
|
+
}
|
|
96
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
// 菜单里的悬停说明。系统 toolTip 只在 App 处于激活状态时显示,而桌宠窗口是
|
|
4
|
+
// NonactivatingPanel,右键弹菜单时前台通常还是终端,于是说明时有时无。这里自己画一个
|
|
5
|
+
// 浮窗,不依赖激活状态。
|
|
6
|
+
@interface MenuHint : NSObject
|
|
7
|
+
// 悬停一段时间后在 rect(屏幕坐标)下方显示 text;刚显示过别的说明时立即显示。
|
|
8
|
+
+ (void)scheduleText:(NSString *)text belowScreenRect:(NSRect)rect;
|
|
9
|
+
+ (void)cancel;
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
// 菜单自绘行。设置 hint 后,鼠标停在行内任意位置(包括其中的开关)都会显示说明。
|
|
13
|
+
@interface MenuHintRowView : NSView
|
|
14
|
+
@property(nonatomic, copy) NSString *hint;
|
|
15
|
+
@end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#import "MenuHintView.h"
|
|
2
|
+
|
|
3
|
+
// 与系统 toolTip 的节奏接近:首次悬停要停稳一会儿,刚看过一条再移到相邻行时立即显示。
|
|
4
|
+
static const NSTimeInterval MenuHintInitialDelay = 0.8;
|
|
5
|
+
static const NSTimeInterval MenuHintFollowupWindow = 0.5;
|
|
6
|
+
static const CGFloat MenuHintMaxTextWidth = 260.0;
|
|
7
|
+
static const CGFloat MenuHintPadding = 7.0;
|
|
8
|
+
|
|
9
|
+
static NSPanel *HintPanel;
|
|
10
|
+
static NSTextField *HintLabel;
|
|
11
|
+
static NSTimer *HintTimer;
|
|
12
|
+
static NSTimeInterval HintHiddenAt;
|
|
13
|
+
|
|
14
|
+
@implementation MenuHint
|
|
15
|
+
+ (void)preparePanel {
|
|
16
|
+
if (HintPanel) return;
|
|
17
|
+
HintPanel = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 10, 10)
|
|
18
|
+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel
|
|
19
|
+
backing:NSBackingStoreBuffered defer:YES];
|
|
20
|
+
HintPanel.opaque = NO;
|
|
21
|
+
HintPanel.backgroundColor = NSColor.clearColor;
|
|
22
|
+
HintPanel.hasShadow = YES;
|
|
23
|
+
HintPanel.ignoresMouseEvents = YES;
|
|
24
|
+
// 菜单窗口在 NSPopUpMenuWindowLevel,低于它会被菜单挡住。
|
|
25
|
+
HintPanel.level = NSPopUpMenuWindowLevel + 1;
|
|
26
|
+
HintPanel.collectionBehavior = NSWindowCollectionBehaviorTransient |
|
|
27
|
+
NSWindowCollectionBehaviorMoveToActiveSpace;
|
|
28
|
+
|
|
29
|
+
NSVisualEffectView *background = [[NSVisualEffectView alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)];
|
|
30
|
+
background.material = NSVisualEffectMaterialToolTip;
|
|
31
|
+
background.blendingMode = NSVisualEffectBlendingModeBehindWindow;
|
|
32
|
+
background.state = NSVisualEffectStateActive;
|
|
33
|
+
background.wantsLayer = YES;
|
|
34
|
+
background.layer.cornerRadius = 6.0;
|
|
35
|
+
background.layer.masksToBounds = YES;
|
|
36
|
+
background.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
37
|
+
|
|
38
|
+
HintLabel = [NSTextField wrappingLabelWithString:@""];
|
|
39
|
+
HintLabel.font = [NSFont toolTipsFontOfSize:0];
|
|
40
|
+
HintLabel.textColor = NSColor.labelColor;
|
|
41
|
+
HintLabel.selectable = NO;
|
|
42
|
+
[background addSubview:HintLabel];
|
|
43
|
+
HintPanel.contentView = background;
|
|
44
|
+
}
|
|
45
|
+
+ (void)scheduleText:(NSString *)text belowScreenRect:(NSRect)rect {
|
|
46
|
+
[HintTimer invalidate];
|
|
47
|
+
HintTimer = nil;
|
|
48
|
+
if (text.length == 0) {
|
|
49
|
+
[self cancel];
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
BOOL followup = HintPanel.isVisible ||
|
|
53
|
+
NSDate.date.timeIntervalSince1970 - HintHiddenAt < MenuHintFollowupWindow;
|
|
54
|
+
// 菜单打开期间主线程跑在 event tracking 模式,默认模式的定时器不会触发。
|
|
55
|
+
HintTimer = [NSTimer timerWithTimeInterval:followup ? 0.05 : MenuHintInitialDelay repeats:NO
|
|
56
|
+
block:^(NSTimer *timer) {
|
|
57
|
+
HintTimer = nil;
|
|
58
|
+
[self showText:text belowScreenRect:rect];
|
|
59
|
+
}];
|
|
60
|
+
[NSRunLoop.mainRunLoop addTimer:HintTimer forMode:NSRunLoopCommonModes];
|
|
61
|
+
}
|
|
62
|
+
+ (void)showText:(NSString *)text belowScreenRect:(NSRect)rect {
|
|
63
|
+
[self preparePanel];
|
|
64
|
+
HintLabel.stringValue = text;
|
|
65
|
+
NSSize textSize = [HintLabel.cell cellSizeForBounds:
|
|
66
|
+
NSMakeRect(0, 0, MenuHintMaxTextWidth, CGFLOAT_MAX)];
|
|
67
|
+
textSize.width = ceil(MIN(textSize.width, MenuHintMaxTextWidth));
|
|
68
|
+
textSize.height = ceil(textSize.height);
|
|
69
|
+
HintLabel.frame = NSMakeRect(MenuHintPadding, MenuHintPadding - 2, textSize.width, textSize.height);
|
|
70
|
+
NSSize panelSize = NSMakeSize(textSize.width + MenuHintPadding * 2,
|
|
71
|
+
textSize.height + MenuHintPadding * 2 - 4);
|
|
72
|
+
|
|
73
|
+
NSPoint mouse = NSEvent.mouseLocation;
|
|
74
|
+
NSScreen *screen = NSScreen.mainScreen ?: NSScreen.screens.firstObject;
|
|
75
|
+
for (NSScreen *candidate in NSScreen.screens) {
|
|
76
|
+
if (NSPointInRect(mouse, candidate.frame)) {
|
|
77
|
+
screen = candidate;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
NSRect visible = screen.visibleFrame;
|
|
82
|
+
// 贴着行的下沿、从鼠标所在位置起,与系统 toolTip 的位置习惯一致;下方放不下就放到行上方。
|
|
83
|
+
CGFloat x = MIN(MAX(mouse.x, NSMinX(visible)), NSMaxX(visible) - panelSize.width);
|
|
84
|
+
CGFloat y = NSMinY(rect) - panelSize.height - 2;
|
|
85
|
+
if (y < NSMinY(visible)) y = NSMaxY(rect) + 2;
|
|
86
|
+
[HintPanel setFrame:NSMakeRect(x, y, panelSize.width, panelSize.height) display:YES];
|
|
87
|
+
[HintPanel orderFront:nil];
|
|
88
|
+
}
|
|
89
|
+
+ (void)cancel {
|
|
90
|
+
[HintTimer invalidate];
|
|
91
|
+
HintTimer = nil;
|
|
92
|
+
if (HintPanel.isVisible) {
|
|
93
|
+
HintHiddenAt = NSDate.date.timeIntervalSince1970;
|
|
94
|
+
[HintPanel orderOut:nil];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
@end
|
|
98
|
+
|
|
99
|
+
@implementation MenuHintRowView {
|
|
100
|
+
NSTrackingArea *_hintTrackingArea;
|
|
101
|
+
}
|
|
102
|
+
- (void)setHint:(NSString *)hint {
|
|
103
|
+
_hint = [hint copy];
|
|
104
|
+
[self setAccessibilityHelp:hint];
|
|
105
|
+
}
|
|
106
|
+
// 菜单属于前台之外的 App 时也要收到进出事件,所以用 ActiveAlways。
|
|
107
|
+
- (void)updateTrackingAreas {
|
|
108
|
+
[super updateTrackingAreas];
|
|
109
|
+
if (_hintTrackingArea) [self removeTrackingArea:_hintTrackingArea];
|
|
110
|
+
_hintTrackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
|
|
111
|
+
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
112
|
+
owner:self userInfo:nil];
|
|
113
|
+
[self addTrackingArea:_hintTrackingArea];
|
|
114
|
+
}
|
|
115
|
+
- (void)mouseEntered:(NSEvent *)event {
|
|
116
|
+
if (self.hint.length == 0 || !self.window) return;
|
|
117
|
+
NSRect rect = [self.window convertRectToScreen:[self convertRect:self.bounds toView:nil]];
|
|
118
|
+
[MenuHint scheduleText:self.hint belowScreenRect:rect];
|
|
119
|
+
}
|
|
120
|
+
- (void)mouseExited:(NSEvent *)event {
|
|
121
|
+
[MenuHint cancel];
|
|
122
|
+
}
|
|
123
|
+
// 菜单关闭时行视图会被移出窗口,此时不一定还能收到 mouseExited。
|
|
124
|
+
- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
|
|
125
|
+
[super viewWillMoveToWindow:newWindow];
|
|
126
|
+
if (!newWindow && self.hint.length > 0) [MenuHint cancel];
|
|
127
|
+
}
|
|
128
|
+
@end
|
package/Sources/CCPets/PetView.h
CHANGED
|
@@ -30,6 +30,8 @@ extern NSString *const PetInteractionIntervalKey;
|
|
|
30
30
|
@property(copy) void (^dragStateChanged)(BOOL dragging);
|
|
31
31
|
@property(copy) void (^interactionPhraseRequested)(NSString *tag);
|
|
32
32
|
@property(copy) NSArray<NSDictionary *> *(^petOptionsRequested)(void);
|
|
33
|
+
// 有可安装的新版本时返回版本号,否则 nil。右键菜单据此决定要不要在顶层放「更新到 x.y.z…」。
|
|
34
|
+
@property(copy) NSString *(^pendingUpdateVersionRequested)(void);
|
|
33
35
|
@property(copy) void (^switchPetRequested)(NSString *petID);
|
|
34
36
|
@property(copy) BOOL (^deletePetRequested)(NSString *petID);
|
|
35
37
|
@property NSCache<NSString *, NSImage *> *petMenuPreviewCache;
|
package/Sources/CCPets/PetView.m
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
#import "PetView.h"
|
|
2
2
|
#import <QuartzCore/QuartzCore.h>
|
|
3
3
|
#import "MenuToggleSwitch.h"
|
|
4
|
+
#import "MenuHintView.h"
|
|
4
5
|
#import "CCPetsPaths.h"
|
|
5
6
|
#import "CCPetsImageLoader.h"
|
|
6
7
|
#import "CCPetsBridge.h"
|
|
8
|
+
#import "CCPetsGlassView.h"
|
|
9
|
+
#import "MenuChoiceRow.h"
|
|
7
10
|
|
|
8
|
-
// 碎碎念频率档位的 defaults 键。定义在 CCPetsAppDelegate.m,这里只读不写;
|
|
11
|
+
// 碎碎念频率档位的 defaults 键。定义在 CCPetsAppDelegate+Speech.m,这里只读不写;
|
|
9
12
|
// 单独 extern 而不 import 那个头文件,是因为它反过来 import 了 PetView.h。
|
|
10
13
|
extern NSString *const PetSpeechFrequencyKey;
|
|
11
14
|
|
|
@@ -1406,8 +1409,17 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1406
1409
|
? item.representedObject : nil;
|
|
1407
1410
|
if (pet) [self showMenuPreviewForPet:pet item:item menu:menu];
|
|
1408
1411
|
else [self.petMenuPreviewPanel orderOut:nil];
|
|
1412
|
+
// 自绘行的说明由 MenuHintRowView 自己的进出事件管,这里不能去取消它。
|
|
1413
|
+
if (item.view) return;
|
|
1414
|
+
NSString *hint = [item.representedObject isKindOfClass:NSString.class] ? item.representedObject : nil;
|
|
1415
|
+
NSRect itemFrame = item.accessibilityFrame;
|
|
1416
|
+
if (hint && !NSIsEmptyRect(itemFrame)) [MenuHint scheduleText:hint belowScreenRect:itemFrame];
|
|
1417
|
+
else [MenuHint cancel];
|
|
1409
1418
|
}
|
|
1410
1419
|
- (void)menuDidClose:(NSMenu *)menu {
|
|
1420
|
+
[MenuHint cancel];
|
|
1421
|
+
// CC Bridge 子菜单也以 self 为代理(为了悬停说明),删除确认和预览只属于"管理桌宠"。
|
|
1422
|
+
if (menu != self.activePetSwitchMenu) return;
|
|
1411
1423
|
[self resetPendingDeleteButton];
|
|
1412
1424
|
[self.petMenuPreviewPanel orderOut:nil];
|
|
1413
1425
|
}
|
|
@@ -1424,7 +1436,7 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1424
1436
|
const CGFloat leadingInset = 12;
|
|
1425
1437
|
CGFloat toggleX = width - trailingInset - toggleWidth;
|
|
1426
1438
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
|
1427
|
-
NSView *row = [[
|
|
1439
|
+
NSView *row = [[MenuHintRowView alloc] initWithFrame:NSMakeRect(0, 0, width, 28)];
|
|
1428
1440
|
NSTextField *label = [NSTextField labelWithString:title];
|
|
1429
1441
|
label.frame = NSMakeRect(leadingInset, 5, toggleX - leadingInset - trailingInset, 18);
|
|
1430
1442
|
label.font = [NSFont menuFontOfSize:13];
|
|
@@ -1469,34 +1481,62 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1469
1481
|
}
|
|
1470
1482
|
// CC Bridge 开关组。状态每次打开菜单时现读(开关文件 / 选项),不在视图里缓存。
|
|
1471
1483
|
// 除"消息角标 / 新消息通知"这两项只影响桌宠外,其余开关都通过 cc-pets bridge enable / configure
|
|
1472
|
-
// 落到 Claude Code / Codex
|
|
1484
|
+
// 落到 Claude Code / Codex 的配置里。
|
|
1473
1485
|
- (void)addBridgeSwitchToMenu:(NSMenu *)menu title:(NSString *)title checked:(BOOL)checked
|
|
1474
|
-
action:(SEL)action tag:(NSInteger)tag
|
|
1486
|
+
action:(SEL)action tag:(NSInteger)tag toolTip:(NSString *)toolTip {
|
|
1475
1487
|
// 与其他子菜单同宽。菜单宽度取最宽的一行:标题都控制在 5 个字以内,说明性文字放进悬停提示,
|
|
1476
1488
|
// 否则长文字行会把菜单撑宽,而自绘开关行是固定宽度,开关就不再贴右边。
|
|
1489
|
+
// 说明不用系统 toolTip:它只在 App 激活时显示,见 MenuHintView.h。
|
|
1477
1490
|
NSMenuItem *item = [self addPersistentSwitchToMenu:menu title:title checked:checked
|
|
1478
1491
|
action:action width:PetSubmenuRowWidth tag:tag];
|
|
1479
|
-
item.view.
|
|
1480
|
-
for (NSView *subview in item.view.subviews) {
|
|
1481
|
-
if ([subview isKindOfClass:MenuToggleSwitch.class]) ((MenuToggleSwitch *)subview).enabled = enabled;
|
|
1482
|
-
if ([subview isKindOfClass:NSTextField.class] && !enabled) {
|
|
1483
|
-
((NSTextField *)subview).textColor = NSColor.disabledControlTextColor;
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1492
|
+
((MenuHintRowView *)item.view).hint = toolTip;
|
|
1486
1493
|
}
|
|
1494
|
+
// 一级子菜单只放启用和最常动的两个开关(开关在上、二级菜单在下);免审批(设一次就不动)和只影响桌宠的提醒各收进二级菜单。
|
|
1495
|
+
// 未开启时只留"启用"一行:其余开关此时都不生效,列出来只是占地方。开启是异步的,
|
|
1496
|
+
// 菜单停留期间不会自己长出其余项,下次打开时按实际状态重建。
|
|
1487
1497
|
- (void)addBridgeMenuToMenu:(NSMenu *)menu {
|
|
1488
1498
|
NSMenuItem *bridgeItem = [menu addItemWithTitle:@"CC Bridge" action:nil keyEquivalent:@""];
|
|
1489
1499
|
NSMenu *bridgeMenu = [NSMenu new];
|
|
1500
|
+
// 免审批 / 桌宠提醒 是普通菜单项,悬停说明走 menu:willHighlightItem:。
|
|
1501
|
+
bridgeMenu.delegate = self;
|
|
1502
|
+
bridgeItem.submenu = bridgeMenu;
|
|
1490
1503
|
BOOL enabled = CCBridgeEnabled();
|
|
1491
|
-
NSDictionary *options = CCBridgeOptions();
|
|
1492
1504
|
[self addBridgeSwitchToMenu:bridgeMenu title:@"启用" checked:enabled
|
|
1493
|
-
action:@selector(toggleBridgeEnabled:) tag:0
|
|
1505
|
+
action:@selector(toggleBridgeEnabled:) tag:0
|
|
1494
1506
|
toolTip:@"让本机 Claude Code / Codex 会话互相发消息、唤醒对方、预留文件"];
|
|
1507
|
+
if (!enabled) return;
|
|
1508
|
+
|
|
1509
|
+
// 状态放在"启用"行的第二行,省掉底部单独的状态行和分隔线。开关上移与标题对齐,
|
|
1510
|
+
// 状态文字才能占满整行宽度,不被开关截断。
|
|
1511
|
+
NSDictionary *sessions = CCBridgeSessions();
|
|
1512
|
+
NSUInteger reservations = CCBridgeActiveReservationCount([NSSet setWithArray:sessions.allKeys]);
|
|
1513
|
+
MenuHintRowView *enableRow = (MenuHintRowView *)bridgeMenu.itemArray.lastObject.view;
|
|
1514
|
+
enableRow.hint = [enableRow.hint stringByAppendingString:@"\n下方为在线会话数 · 有效的文件预留数"];
|
|
1515
|
+
const CGFloat statusHeight = 14;
|
|
1516
|
+
[enableRow setFrameSize:NSMakeSize(NSWidth(enableRow.frame), NSHeight(enableRow.frame) + statusHeight)];
|
|
1517
|
+
for (NSView *subview in enableRow.subviews) {
|
|
1518
|
+
[subview setFrameOrigin:NSMakePoint(NSMinX(subview.frame), NSMinY(subview.frame) + statusHeight - 2)];
|
|
1519
|
+
}
|
|
1520
|
+
NSTextField *status = [NSTextField labelWithString:[NSString stringWithFormat:@"%lu 会话 · %lu 预留",
|
|
1521
|
+
(unsigned long)sessions.count, (unsigned long)reservations]];
|
|
1522
|
+
status.frame = NSMakeRect(12, 4, NSWidth(enableRow.frame) - 12 - PetMenuControlGap, statusHeight);
|
|
1523
|
+
status.font = [NSFont menuFontOfSize:11];
|
|
1524
|
+
status.textColor = NSColor.secondaryLabelColor;
|
|
1525
|
+
status.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
1526
|
+
[enableRow addSubview:status];
|
|
1495
1527
|
|
|
1496
1528
|
[bridgeMenu addItem:NSMenuItem.separatorItem];
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1529
|
+
NSDictionary *options = CCBridgeOptions();
|
|
1530
|
+
[self addBridgeSwitchToMenu:bridgeMenu title:@"自动唤醒" checked:[options[@"wake"] boolValue]
|
|
1531
|
+
action:@selector(toggleBridgeWake:) tag:0
|
|
1532
|
+
toolTip:@"自动唤醒空闲会话。关闭后消息只进信箱,等对方下次收到你的输入时带入,可省 token;Codex 需重启会话生效"];
|
|
1533
|
+
[self addBridgeSwitchToMenu:bridgeMenu title:@"编辑拦截" checked:[options[@"editGuard"] boolValue]
|
|
1534
|
+
action:@selector(toggleBridgeEditGuard:) tag:0
|
|
1535
|
+
toolTip:@"编辑他人预留的文件时先暂停一次并说明原因,重试即放行;Codex 需重启会话生效"];
|
|
1536
|
+
|
|
1537
|
+
NSMenuItem *approvalItem = [bridgeMenu addItemWithTitle:@"免审批" action:nil keyEquivalent:@""];
|
|
1538
|
+
approvalItem.representedObject = @"每组同时作用于 Codex 免审批与 Claude 免确认;Codex 需重启会话生效";
|
|
1539
|
+
NSMenu *approvalMenu = [NSMenu new];
|
|
1500
1540
|
NSArray<NSDictionary *> *groups = @[
|
|
1501
1541
|
@{@"title": @"查看类", @"group": @"view", @"tag": @1,
|
|
1502
1542
|
@"tip": @"列出会话、查看预留、读取信箱免审批;只读,放开没有风险"},
|
|
@@ -1507,47 +1547,28 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1507
1547
|
@{@"title": @"改会话名", @"group": @"name", @"tag": @4,
|
|
1508
1548
|
@"tip": @"修改当前会话在 CC Bridge 中的名字免审批"}
|
|
1509
1549
|
];
|
|
1550
|
+
NSSet *codex = [NSSet setWithArray:options[@"codexApprove"]];
|
|
1551
|
+
NSSet *claude = [NSSet setWithArray:options[@"claudeAllow"]];
|
|
1510
1552
|
for (NSDictionary *group in groups) {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
[[NSSet setWithArray:tools] isSubsetOfSet:claude];
|
|
1516
|
-
[self addBridgeSwitchToMenu:bridgeMenu title:group[@"title"] checked:checked
|
|
1517
|
-
action:@selector(toggleBridgeApproval:) tag:[group[@"tag"] integerValue] enabled:enabled
|
|
1518
|
-
toolTip:group[@"tip"]];
|
|
1553
|
+
NSSet *tools = [NSSet setWithArray:CCBridgeToolGroup(group[@"group"])];
|
|
1554
|
+
BOOL checked = tools.count > 0 && [tools isSubsetOfSet:codex] && [tools isSubsetOfSet:claude];
|
|
1555
|
+
[self addBridgeSwitchToMenu:approvalMenu title:group[@"title"] checked:checked
|
|
1556
|
+
action:@selector(toggleBridgeApproval:) tag:[group[@"tag"] integerValue] toolTip:group[@"tip"]];
|
|
1519
1557
|
}
|
|
1558
|
+
approvalItem.submenu = approvalMenu;
|
|
1520
1559
|
|
|
1521
|
-
[bridgeMenu
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
[self addBridgeSwitchToMenu:
|
|
1525
|
-
action:@selector(toggleBridgeWake:) tag:0 enabled:enabled
|
|
1526
|
-
toolTip:@"自动唤醒空闲会话。关闭后消息只进信箱,等对方下次收到你的输入时带入,可省 token;Codex 需重启会话生效"];
|
|
1527
|
-
[self addBridgeSwitchToMenu:bridgeMenu title:@"编辑拦截" checked:[options[@"editGuard"] boolValue]
|
|
1528
|
-
action:@selector(toggleBridgeEditGuard:) tag:0 enabled:enabled
|
|
1529
|
-
toolTip:@"编辑他人预留的文件时先暂停一次并说明原因,重试即放行;Codex 需重启会话生效"];
|
|
1530
|
-
[self addBridgeSwitchToMenu:bridgeMenu title:@"消息角标"
|
|
1560
|
+
NSMenuItem *alertItem = [bridgeMenu addItemWithTitle:@"桌宠提醒" action:nil keyEquivalent:@""];
|
|
1561
|
+
alertItem.representedObject = @"只影响桌宠,不改 Claude Code / Codex 的配置";
|
|
1562
|
+
NSMenu *alertMenu = [NSMenu new];
|
|
1563
|
+
[self addBridgeSwitchToMenu:alertMenu title:@"消息角标"
|
|
1531
1564
|
checked:[NSUserDefaults.standardUserDefaults boolForKey:BridgeBadgeEnabledKey]
|
|
1532
|
-
action:@selector(toggleBridgeBadge:) tag:0
|
|
1565
|
+
action:@selector(toggleBridgeBadge:) tag:0
|
|
1533
1566
|
toolTip:@"状态图标右下角:蓝色为新送达,橙色为信箱积压"];
|
|
1534
|
-
[self addBridgeSwitchToMenu:
|
|
1567
|
+
[self addBridgeSwitchToMenu:alertMenu title:@"新消息通知"
|
|
1535
1568
|
checked:[NSUserDefaults.standardUserDefaults boolForKey:BridgeNotificationKey]
|
|
1536
|
-
action:@selector(toggleBridgeNotification:) tag:0
|
|
1569
|
+
action:@selector(toggleBridgeNotification:) tag:0
|
|
1537
1570
|
toolTip:@"会话之间有消息送达时发一条系统通知(只含谁发给谁,不含正文)"];
|
|
1538
|
-
|
|
1539
|
-
[bridgeMenu addItem:NSMenuItem.separatorItem];
|
|
1540
|
-
NSString *status = @"未开启";
|
|
1541
|
-
if (enabled) {
|
|
1542
|
-
NSDictionary *sessions = CCBridgeSessions();
|
|
1543
|
-
NSUInteger reservations = CCBridgeActiveReservationCount([NSSet setWithArray:sessions.allKeys]);
|
|
1544
|
-
status = [NSString stringWithFormat:@"%lu 会话 · %lu 预留",
|
|
1545
|
-
(unsigned long)sessions.count, (unsigned long)reservations];
|
|
1546
|
-
}
|
|
1547
|
-
NSMenuItem *statusItem = [bridgeMenu addItemWithTitle:status action:nil keyEquivalent:@""];
|
|
1548
|
-
statusItem.enabled = NO;
|
|
1549
|
-
statusItem.toolTip = @"在线会话数 · 有效的文件预留数";
|
|
1550
|
-
bridgeItem.submenu = bridgeMenu;
|
|
1571
|
+
alertItem.submenu = alertMenu;
|
|
1551
1572
|
}
|
|
1552
1573
|
- (void)rightMouseDown:(NSEvent *)event {
|
|
1553
1574
|
NSArray<NSDictionary *> *availablePets = self.petOptionsRequested ? self.petOptionsRequested() : @[];
|
|
@@ -1562,8 +1583,6 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1562
1583
|
self.activePetSwitchMenu = switchMenu;
|
|
1563
1584
|
switchItem.submenu = switchMenu;
|
|
1564
1585
|
[menu addItem:NSMenuItem.separatorItem];
|
|
1565
|
-
NSMenuItem *refreshItem = [menu addItemWithTitle:@"刷新用量" action:@selector(refreshUsage:) keyEquivalent:@"r"];
|
|
1566
|
-
refreshItem.target = NSApp.delegate;
|
|
1567
1586
|
[self addPersistentSwitchToMenu:menu
|
|
1568
1587
|
title:@"显示消息气泡"
|
|
1569
1588
|
checked:[NSUserDefaults.standardUserDefaults boolForKey:StatusBubbleExpandedKey]
|
|
@@ -1583,6 +1602,40 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1583
1602
|
[self addUsageModeControlToMenu:usageModeMenu provider:@"Claude"
|
|
1584
1603
|
preferenceKey:ClaudeUsageDisplayModeKey tag:2];
|
|
1585
1604
|
usageModeItem.submenu = usageModeMenu;
|
|
1605
|
+
NSMenuItem *themeItem = [menu addItemWithTitle:@"面板主题" action:nil keyEquivalent:@""];
|
|
1606
|
+
NSMenu *themeMenu = [[NSMenu alloc] initWithTitle:@"面板主题"];
|
|
1607
|
+
// 两组都用自绘单选行:点了立即生效且菜单不收起,方便连着对比主题和压暗档位。
|
|
1608
|
+
NSString *selectedTheme = CCPetsPanelTheme();
|
|
1609
|
+
for (NSArray<NSString *> *option in @[
|
|
1610
|
+
@[@"经典", @"classic"], @[@"Liquid Glass", @"liquid"]]) {
|
|
1611
|
+
NSMenuItem *item = [MenuChoiceRowView addToMenu:themeMenu title:option[0] group:@"theme"
|
|
1612
|
+
representedObject:option[1] checked:[selectedTheme isEqualToString:option[1]]
|
|
1613
|
+
target:NSApp.delegate action:@selector(setPanelTheme:) width:PetSubmenuRowWidth];
|
|
1614
|
+
if ([option[1] isEqualToString:@"liquid"] && !CCPetsLiquidGlassAvailable()) {
|
|
1615
|
+
((MenuChoiceRowView *)item.view).enabled = NO;
|
|
1616
|
+
[item.view setAccessibilityHelp:@"需要 macOS 26 及以上"];
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
// 压暗作用于额度面板、状态卡和说话气泡的原生玻璃;经典主题下没有这层,置灰。切主题时当场联动。
|
|
1620
|
+
[themeMenu addItem:NSMenuItem.separatorItem];
|
|
1621
|
+
NSMenuItem *dimHeader = [themeMenu addItemWithTitle:@"玻璃压暗" action:nil keyEquivalent:@""];
|
|
1622
|
+
dimHeader.enabled = NO;
|
|
1623
|
+
BOOL (^dimApplies)(void) = ^BOOL {
|
|
1624
|
+
return [CCPetsPanelTheme() isEqualToString:@"liquid"] && CCPetsLiquidGlassAvailable();
|
|
1625
|
+
};
|
|
1626
|
+
NSDictionary<NSNumber *, NSString *> *dimTitles = @{
|
|
1627
|
+
@0: @"通透(0%)", @15: @"轻度(15%)", @25: @"标准(25%)", @45: @"清晰(45%)"};
|
|
1628
|
+
NSInteger selectedDim = CCPetsGlassDimLevel();
|
|
1629
|
+
for (NSNumber *level in CCPetsGlassDimLevels()) {
|
|
1630
|
+
NSMenuItem *item = [MenuChoiceRowView addToMenu:themeMenu title:dimTitles[level] group:@"dim"
|
|
1631
|
+
representedObject:level checked:level.integerValue == selectedDim
|
|
1632
|
+
target:NSApp.delegate action:@selector(setGlassDimLevel:) width:PetSubmenuRowWidth];
|
|
1633
|
+
MenuChoiceRowView *row = (MenuChoiceRowView *)item.view;
|
|
1634
|
+
row.indentation = 10;
|
|
1635
|
+
row.enabledHandler = dimApplies;
|
|
1636
|
+
row.enabled = dimApplies();
|
|
1637
|
+
}
|
|
1638
|
+
themeItem.submenu = themeMenu;
|
|
1586
1639
|
NSMenuItem *notificationItem = [menu addItemWithTitle:@"系统通知" action:nil keyEquivalent:@""];
|
|
1587
1640
|
NSMenu *notificationMenu = [NSMenu new];
|
|
1588
1641
|
NSArray<NSDictionary *> *notificationOptions = @[
|
|
@@ -1697,12 +1750,27 @@ typedef NS_ENUM(NSInteger, PetMicroBehaviorKind) {
|
|
|
1697
1750
|
action:@selector(editPhrasesFile:) keyEquivalent:@""];
|
|
1698
1751
|
editPhrases.target = NSApp.delegate;
|
|
1699
1752
|
speechItem.submenu = speechMenu;
|
|
1700
|
-
|
|
1753
|
+
// 检查更新和关于收进「帮助」;有新版本时在顶层临时多一项「更新到 x.y.z…」,一步就能更新,
|
|
1754
|
+
// 不必展开子菜单。气泡和角标错过了,这里仍是醒目的入口。
|
|
1755
|
+
NSString *pendingVersion = self.pendingUpdateVersionRequested ? self.pendingUpdateVersionRequested() : nil;
|
|
1756
|
+
if (pendingVersion.length > 0) {
|
|
1757
|
+
NSMenuItem *installItem = [menu addItemWithTitle:
|
|
1758
|
+
[NSString stringWithFormat:@"更新到 %@…", pendingVersion]
|
|
1759
|
+
action:@selector(showPendingUpdate:) keyEquivalent:@""];
|
|
1760
|
+
installItem.target = NSApp.delegate;
|
|
1761
|
+
}
|
|
1762
|
+
NSMenuItem *helpItem = [menu addItemWithTitle:@"帮助" action:nil keyEquivalent:@""];
|
|
1763
|
+
NSMenu *helpMenu = [NSMenu new];
|
|
1764
|
+
NSMenuItem *updateItem = [helpMenu addItemWithTitle:@"检查更新…" action:@selector(checkForUpdates:) keyEquivalent:@""];
|
|
1701
1765
|
updateItem.target = NSApp.delegate;
|
|
1766
|
+
NSMenuItem *aboutItem = [helpMenu addItemWithTitle:@"关于 CC Pets" action:@selector(showAboutPanel:) keyEquivalent:@""];
|
|
1767
|
+
aboutItem.target = NSApp.delegate;
|
|
1768
|
+
helpItem.submenu = helpMenu;
|
|
1702
1769
|
[menu addItem:NSMenuItem.separatorItem];
|
|
1703
1770
|
NSMenuItem *quitItem = [menu addItemWithTitle:@"退出桌宠" action:@selector(terminate:) keyEquivalent:@"q"];
|
|
1704
1771
|
quitItem.target = NSApp;
|
|
1705
1772
|
[NSMenu popUpContextMenu:menu withEvent:event forView:self];
|
|
1773
|
+
[MenuHint cancel];
|
|
1706
1774
|
self.activePetSwitchMenu = nil;
|
|
1707
1775
|
[self.petMenuPreviewPanel orderOut:nil];
|
|
1708
1776
|
}
|
|
@@ -10,6 +10,9 @@ CGFloat QuotaLogicalHeightForProviderCount(NSUInteger count);
|
|
|
10
10
|
NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName);
|
|
11
11
|
|
|
12
12
|
@interface QuotaDashboardView : NSView
|
|
13
|
+
@property BOOL usesLiquidGlass;
|
|
14
|
+
// 原生玻璃下卡片和汇总区衬底的不透明度,由 App 按压暗档位设置。
|
|
15
|
+
@property CGFloat cardScrimAlpha;
|
|
13
16
|
@property NSDictionary *codexUsage;
|
|
14
17
|
@property NSDictionary *claudeUsage;
|
|
15
18
|
@property NSArray<NSDictionary *> *codexHistory;
|
|
@@ -38,9 +41,5 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName);
|
|
|
38
41
|
- (BOOL)isProviderOnline:(NSString *)name;
|
|
39
42
|
@property NSImage *codexLogo;
|
|
40
43
|
@property NSImage *claudeLogo;
|
|
41
|
-
@property BOOL refreshHovered;
|
|
42
|
-
@property BOOL refreshPressed;
|
|
43
|
-
@property NSTimeInterval refreshedUntil;
|
|
44
44
|
@property(copy) void (^hoverChanged)(BOOL hovering);
|
|
45
|
-
@property(copy) void (^refreshRequested)(void);
|
|
46
45
|
@end
|