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.
Files changed (58) hide show
  1. package/CC_BRIDGE.md +11 -6
  2. package/CC_BRIDGE.zh-CN.md +8 -4
  3. package/CHANGELOG.md +59 -1
  4. package/CHANGELOG.zh-CN.md +59 -1
  5. package/README.md +60 -12
  6. package/README.zh-CN.md +58 -13
  7. package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
  8. package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
  9. package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +297 -0
  10. package/Sources/CCPets/CCPetsAppDelegate+Pets.m +187 -0
  11. package/Sources/CCPets/CCPetsAppDelegate+Private.h +322 -0
  12. package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
  13. package/Sources/CCPets/CCPetsAppDelegate+Settings.m +205 -0
  14. package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
  15. package/Sources/CCPets/CCPetsAppDelegate+Update.m +458 -0
  16. package/Sources/CCPets/CCPetsAppDelegate.h +17 -16
  17. package/Sources/CCPets/CCPetsAppDelegate.m +74 -2406
  18. package/Sources/CCPets/CCPetsCleanup.h +4 -0
  19. package/Sources/CCPets/CCPetsCleanup.m +35 -2
  20. package/Sources/CCPets/CCPetsCodexRateLimits.h +1 -0
  21. package/Sources/CCPets/CCPetsCodexRateLimits.m +7 -0
  22. package/Sources/CCPets/CCPetsEvents.m +1 -1
  23. package/Sources/CCPets/CCPetsGlassMenu.h +10 -0
  24. package/Sources/CCPets/CCPetsGlassMenu.m +196 -0
  25. package/Sources/CCPets/CCPetsGlassView.h +31 -0
  26. package/Sources/CCPets/CCPetsGlassView.m +246 -0
  27. package/Sources/CCPets/CCPetsPaths.h +7 -1
  28. package/Sources/CCPets/CCPetsPaths.m +14 -1
  29. package/Sources/CCPets/CCPetsTerminalFocus.h +15 -0
  30. package/Sources/CCPets/CCPetsTerminalFocus.m +306 -15
  31. package/Sources/CCPets/CCPetsUsage.h +2 -1
  32. package/Sources/CCPets/CCPetsUsage.m +69 -21
  33. package/Sources/CCPets/CCPetsUsageMonitor.m +43 -8
  34. package/Sources/CCPets/CCPetsVersion.h +7 -0
  35. package/Sources/CCPets/CCPetsVersion.m +82 -0
  36. package/Sources/CCPets/MenuChoiceRow.h +19 -0
  37. package/Sources/CCPets/MenuChoiceRow.m +96 -0
  38. package/Sources/CCPets/MenuHintView.h +15 -0
  39. package/Sources/CCPets/MenuHintView.m +128 -0
  40. package/Sources/CCPets/PetView.h +2 -0
  41. package/Sources/CCPets/PetView.m +121 -53
  42. package/Sources/CCPets/QuotaDashboardView.h +3 -4
  43. package/Sources/CCPets/QuotaDashboardView.m +222 -146
  44. package/Sources/CCPets/main.m +29 -0
  45. package/bin/cc-pets +39 -1
  46. package/bin/codex-with-pet +2 -0
  47. package/package.json +3 -2
  48. package/scripts/bridge/cli.mjs +9 -2
  49. package/scripts/bridge/core.mjs +1 -1
  50. package/scripts/bridge/install.mjs +23 -1
  51. package/scripts/bridge/process.mjs +22 -0
  52. package/scripts/doctor.mjs +456 -0
  53. package/scripts/install-claude-hooks.mjs +12 -18
  54. package/scripts/install-codex-hooks.mjs +3 -9
  55. package/scripts/integration-markers.mjs +51 -0
  56. package/scripts/pet-store.mjs +2 -1
  57. package/scripts/uninstall-integrations.mjs +16 -44
  58. package/scripts/uninstall-shell-integration.sh +3 -3
@@ -47,7 +47,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
47
47
  - (instancetype)initWithFrame:(NSRect)frame {
48
48
  if ((self = [super initWithFrame:frame])) {
49
49
  NSTrackingArea *tracking = [[NSTrackingArea alloc] initWithRect:NSZeroRect
50
- options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
50
+ options:NSTrackingMouseEnteredAndExited |
51
51
  NSTrackingActiveAlways | NSTrackingInVisibleRect
52
52
  owner:self userInfo:nil];
53
53
  [self addTrackingArea:tracking];
@@ -57,13 +57,8 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
57
57
  - (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
58
58
  - (void)mouseEntered:(NSEvent *)event {
59
59
  if (self.hoverChanged) self.hoverChanged(YES);
60
- [self mouseMoved:event];
61
60
  }
62
61
  - (void)mouseExited:(NSEvent *)event {
63
- self.refreshHovered = NO;
64
- self.refreshPressed = NO;
65
- [NSCursor.arrowCursor set];
66
- self.needsDisplay = YES;
67
62
  if (self.hoverChanged) self.hoverChanged(NO);
68
63
  }
69
64
  // detectedProviders 未赋值时按"两家都有"渲染。这是刻意的兜底:探测是 App 侧的额外信号,
@@ -80,12 +75,6 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
80
75
  - (CGFloat)logicalHeight {
81
76
  return QuotaLogicalHeightForProviderCount([self visibleProviders].count);
82
77
  }
83
- - (NSRect)logicalRefreshRect { return NSMakeRect(QuotaLogicalWidth - 54, [self logicalHeight] - 52, 34, 32); }
84
- - (NSRect)refreshRect {
85
- NSRect logical = [self logicalRefreshRect];
86
- return NSMakeRect(logical.origin.x * QuotaScale, logical.origin.y * QuotaScale,
87
- logical.size.width * QuotaScale, logical.size.height * QuotaScale);
88
- }
89
78
  - (NSRect)logicalSummaryRect {
90
79
  return NSMakeRect(20, [self logicalHeight] - QuotaHeaderHeight - QuotaSummaryHeight,
91
80
  QuotaLogicalWidth - 40, QuotaSummaryHeight);
@@ -98,40 +87,6 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
98
87
  ? NSMakeRect(NSMinX(summary) + index * width, NSMinY(summary), width, NSHeight(summary))
99
88
  : NSZeroRect;
100
89
  }
101
- - (void)mouseMoved:(NSEvent *)event {
102
- NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
103
- BOOL hovering = NSPointInRect(point, [self refreshRect]);
104
- if (hovering != self.refreshHovered) {
105
- self.refreshHovered = hovering;
106
- self.needsDisplay = YES;
107
- }
108
- if (hovering) [NSCursor.pointingHandCursor set];
109
- else [NSCursor.arrowCursor set];
110
- }
111
- - (void)mouseDown:(NSEvent *)event {
112
- NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
113
- if (NSPointInRect(point, [self refreshRect])) {
114
- self.refreshPressed = YES;
115
- self.needsDisplay = YES;
116
- }
117
- }
118
- - (void)mouseUp:(NSEvent *)event {
119
- NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
120
- BOOL shouldRefresh = self.refreshPressed && NSPointInRect(point, [self refreshRect]);
121
- self.refreshPressed = NO;
122
- if (shouldRefresh) {
123
- if (self.refreshRequested) self.refreshRequested();
124
- self.refreshedUntil = NSDate.date.timeIntervalSince1970 + 1.2;
125
- [[NSHapticFeedbackManager defaultPerformer] performFeedbackPattern:NSHapticFeedbackPatternAlignment
126
- performanceTime:NSHapticFeedbackPerformanceTimeNow];
127
- [self performSelector:@selector(clearRefreshConfirmation) withObject:nil afterDelay:1.2];
128
- }
129
- self.needsDisplay = YES;
130
- }
131
- - (void)clearRefreshConfirmation {
132
- self.refreshedUntil = 0;
133
- self.needsDisplay = YES;
134
- }
135
90
  - (NSDictionary *)quota:(NSDictionary *)usage key:(NSString *)key {
136
91
  id value = usage[key];
137
92
  return [value isKindOfClass:NSDictionary.class] ? value : nil;
@@ -219,9 +174,11 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
219
174
  NSDateFormatter *formatter = [NSDateFormatter new];
220
175
  formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
221
176
  formatter.timeZone = NSTimeZone.localTimeZone;
222
- formatter.dateFormat = @"yyyy-MM-dd";
223
- return [NSString stringWithFormat:@"近 7 天累计用量(%@ 至今·滚动记录)",
224
- [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:start.doubleValue]]];
177
+ // 原生玻璃下字号更大,完整说明在单元格里放不下,只留起始日期。
178
+ formatter.dateFormat = self.usesLiquidGlass ? @"M/d" : @"yyyy-MM-dd";
179
+ NSString *date = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:start.doubleValue]];
180
+ return self.usesLiquidGlass ? [NSString stringWithFormat:@"近 7 天累计用量(%@ 起)", date]
181
+ : [NSString stringWithFormat:@"近 7 天累计用量(%@ 至今·滚动记录)", date];
225
182
  }
226
183
  // 在线 = 这一家还有活着的客户端,和有没有额度数据无关:额度会一直缓存着,
227
184
  // 拿它当在线信号会恒亮。身份不明的老客户端无法归属到某一家,保守地都算在线。
@@ -229,7 +186,15 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
229
186
  return [self.liveProviders containsObject:name] || self.hasUnlabeledClient;
230
187
  }
231
188
  - (NSColor *)primaryColor { return [NSColor colorWithWhite:0.97 alpha:1]; }
232
- - (NSColor *)secondaryColor { return [NSColor colorWithWhite:0.68 alpha:1]; }
189
+ - (NSColor *)secondaryColor {
190
+ // 没有深色底托着时,0.68 的灰在亮壁纸上会发虚。
191
+ return [NSColor colorWithWhite:self.usesLiquidGlass ? 0.84 : 0.68 alpha:1];
192
+ }
193
+ // 原生玻璃背后只有一层压暗,原来的紫在上面偏暗,提亮到和青色相近的明度。
194
+ - (NSColor *)claudeColor {
195
+ return self.usesLiquidGlass ? [NSColor colorWithRed:0.80 green:0.66 blue:1.00 alpha:1]
196
+ : [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1];
197
+ }
233
198
  - (NSColor *)accentColor { return [NSColor colorWithRed:0.30 green:0.82 blue:0.90 alpha:1]; }
234
199
  // 有 Agent 在线才用绿色,否则整块转灰,避免"暂无 Agent 在线"配一个绿点。
235
200
  - (NSColor *)agentStatusColor {
@@ -268,7 +233,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
268
233
  NSString *label = metric[@"label"];
269
234
  NSColor *color = metric[@"color"];
270
235
  NSDictionary *attributes = @{NSFontAttributeName: font,
271
- NSForegroundColorAttributeName: color};
236
+ NSForegroundColorAttributeName: [self textColor:color]};
272
237
  NSImage *icon = [NSImage imageWithSystemSymbolName:metric[@"symbol"]
273
238
  accessibilityDescription:label];
274
239
  NSImageSymbolConfiguration *sizeConfiguration =
@@ -301,9 +266,6 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
301
266
  CGFloat width = ceil(statusLine.size.width);
302
267
  [statusLine drawInRect:NSMakeRect(rightEdge - width, y, width + 1, 20)];
303
268
  }
304
- - (NSString *)formattedTokenCountForUsage:(NSDictionary *)usage key:(NSString *)key {
305
- return [self formattedTokenCount:[self tokenTotals:usage key:key] ?: @{}];
306
- }
307
269
  - (NSString *)formattedTokenSplitForUsage:(NSDictionary *)usage key:(NSString *)key
308
270
  wantsOutput:(BOOL)wantsOutput {
309
271
  return [self formattedTokenSplit:[self tokenTotals:usage key:key] ?: @{}
@@ -321,23 +283,90 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
321
283
  if (age < 3600) return [NSString stringWithFormat:@"%.0f 分钟前", floor(age / 60)];
322
284
  return [NSString stringWithFormat:@"%.0f 小时前", floor(age / 3600)];
323
285
  }
286
+ // 原生玻璃下背景可以是任意壁纸,面板按 0.58 缩放后小字只有 6–7pt,细笔画很容易被
287
+ // 背后的纹理吃掉。所以 liquid 模式统一收紧文字:小字放大一点、加粗一级;灰字不低于
288
+ // 0.84;彩色字改成白字。
289
+ // 经典主题有深色实底托着,保持原样。
290
+ // 小字统一抬到逻辑 14(屏幕约 8.1pt),这是 440pt 宽面板在不改版式的前提下放得下的上限;
291
+ // 再往上要放大面板或删行。数字用等宽字形,跳动时不左右晃;汉字不受影响。
292
+ - (NSFont *)fontWithSize:(CGFloat)size weight:(NSFontWeight)weight {
293
+ if (!self.usesLiquidGlass) return [NSFont systemFontOfSize:size weight:weight];
294
+ if (size < 14) size = 14;
295
+ else if (size <= 16) size += 1;
296
+ if (weight < NSFontWeightMedium) weight = NSFontWeightMedium;
297
+ else if (weight < NSFontWeightSemibold) weight = NSFontWeightSemibold;
298
+ else if (weight < NSFontWeightBold) weight = NSFontWeightBold;
299
+ return [NSFont monospacedDigitSystemFontOfSize:size weight:weight];
300
+ }
301
+ // 局部衬底:只垫在卡片和汇总区下面,面板边缘和卡片间隙保持通透。衬底本身不能带
302
+ // 文字投影,否则卡片边缘会多一圈黑晕。
303
+ // 原生玻璃下在文字前画一个彩色小圆点,替代原来的彩色字;经典主题照旧画彩色字。
304
+ - (void)drawText:(NSString *)text inRect:(NSRect)rect size:(CGFloat)size
305
+ weight:(NSFontWeight)weight color:(NSColor *)color dotColor:(NSColor *)dotColor {
306
+ if (!self.usesLiquidGlass) {
307
+ [text drawInRect:rect withAttributes:[self textAttributesWithSize:size color:color weight:weight]];
308
+ return;
309
+ }
310
+ NSMutableDictionary *attributes = [[self textAttributesWithSize:size color:color
311
+ weight:weight] mutableCopy];
312
+ NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
313
+ style.lineBreakMode = NSLineBreakByTruncatingTail;
314
+ attributes[NSParagraphStyleAttributeName] = style;
315
+ NSFont *font = attributes[NSFontAttributeName];
316
+ CGFloat diameter = 9;
317
+ // drawInRect: 从矩形顶部开始排版,圆点对齐到首行小写字母的中线。
318
+ CGFloat baselineMid = NSMaxY(rect) - font.ascender + font.xHeight / 2.0;
319
+ [NSGraphicsContext saveGraphicsState];
320
+ [[NSShadow new] set];
321
+ [dotColor setFill];
322
+ [[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(NSMinX(rect), baselineMid - diameter / 2.0,
323
+ diameter, diameter)] fill];
324
+ [NSGraphicsContext restoreGraphicsState];
325
+ NSRect textRect = rect;
326
+ textRect.origin.x += diameter + 6;
327
+ textRect.size.width -= diameter + 6;
328
+ [text drawInRect:textRect withAttributes:attributes];
329
+ }
330
+ // 风险提示:原生玻璃下是圆点 + 白字;经典主题照旧画彩色字。
331
+ - (void)drawTip:(NSString *)text inRect:(NSRect)rect color:(NSColor *)color {
332
+ [self drawText:text inRect:rect size:11 weight:NSFontWeightMedium color:color dotColor:color];
333
+ }
334
+ - (void)fillLiquidScrim:(NSBezierPath *)path {
335
+ [NSGraphicsContext saveGraphicsState];
336
+ [[NSShadow new] set];
337
+ [[NSColor colorWithWhite:0 alpha:self.cardScrimAlpha] setFill];
338
+ [path fill];
339
+ [NSGraphicsContext restoreGraphicsState];
340
+ }
341
+ - (NSColor *)textColor:(NSColor *)color {
342
+ if (!self.usesLiquidGlass) return color;
343
+ NSColor *rgb = [color colorUsingColorSpace:NSColorSpace.sRGBColorSpace];
344
+ if (!rgb) return color;
345
+ CGFloat r, g, b, a;
346
+ [rgb getRed:&r green:&g blue:&b alpha:&a];
347
+ CGFloat saturation = MAX(r, MAX(g, b)) - MIN(r, MIN(g, b));
348
+ if (saturation < 0.05) return [NSColor colorWithWhite:MAX(MAX(r, MAX(g, b)), 0.84) alpha:a];
349
+ // 彩色字在任意亮度的背景上对比都不稳定,原生玻璃下文字一律用白色;颜色的语义改由
350
+ // 字前的小圆点、图标和曲线承担(见 drawText:inRect:size:weight:color:dotColor:)。
351
+ return [NSColor colorWithWhite:0.96 alpha:a];
352
+ }
324
353
  - (NSDictionary *)textAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
325
- return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
326
- NSForegroundColorAttributeName: color};
354
+ return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
355
+ NSForegroundColorAttributeName: [self textColor:color]};
327
356
  }
328
357
  - (NSDictionary *)rightAlignedTextAttributesWithSize:(CGFloat)size color:(NSColor *)color
329
358
  weight:(NSFontWeight)weight {
330
359
  NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
331
360
  style.alignment = NSTextAlignmentRight;
332
- return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
333
- NSForegroundColorAttributeName: color,
361
+ return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
362
+ NSForegroundColorAttributeName: [self textColor:color],
334
363
  NSParagraphStyleAttributeName: style};
335
364
  }
336
365
  - (NSDictionary *)centeredTextAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
337
366
  NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
338
367
  style.alignment = NSTextAlignmentCenter;
339
- return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
340
- NSForegroundColorAttributeName: color,
368
+ return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
369
+ NSForegroundColorAttributeName: [self textColor:color],
341
370
  NSParagraphStyleAttributeName: style};
342
371
  }
343
372
  - (void)fillRoundedRect:(NSRect)rect radius:(CGFloat)radius color:(NSColor *)color {
@@ -560,11 +589,16 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
560
589
  BOOL online = [self isProviderOnline:name];
561
590
 
562
591
  NSBezierPath *cardPath = [NSBezierPath bezierPathWithRoundedRect:card xRadius:18 yRadius:18];
563
- NSGradient *cardGlass = [[NSGradient alloc]
564
- initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.085]
565
- endingColor:[color colorWithAlphaComponent:0.025]];
566
- [cardGlass drawInBezierPath:cardPath angle:-25];
567
- [[NSColor colorWithWhite:1 alpha:0.18] setStroke];
592
+ // 经典主题的浅色渐变放到玻璃上会变成磨砂;原生玻璃下改垫一层深色衬底托住文字。
593
+ if (self.usesLiquidGlass) {
594
+ [self fillLiquidScrim:cardPath];
595
+ } else {
596
+ NSGradient *cardGlass = [[NSGradient alloc]
597
+ initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.085]
598
+ endingColor:[color colorWithAlphaComponent:0.025]];
599
+ [cardGlass drawInBezierPath:cardPath angle:-25];
600
+ }
601
+ [[NSColor colorWithWhite:1 alpha:self.usesLiquidGlass ? 0.10 : 0.18] setStroke];
568
602
  cardPath.lineWidth = 1;
569
603
  [cardPath stroke];
570
604
 
@@ -597,12 +631,19 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
597
631
  : (!hasData ? @"等待数据" : (online ? @"● 在线" : @"离线"));
598
632
  NSColor *statusColor = (!apiMode && exhausted) ? NSColor.systemOrangeColor
599
633
  : (online && hasData ? NSColor.systemGreenColor : secondary);
600
- NSDictionary *statusAttributes = [self textAttributesWithSize:11 color:statusColor
601
- weight:NSFontWeightMedium];
602
- CGFloat statusWidth = ceil([statusText sizeWithAttributes:statusAttributes].width) + 18;
603
- NSRect status = NSMakeRect(NSMinX(card) + 94, NSMinY(card) + 55, statusWidth, 24);
604
- [self fillRoundedRect:status radius:12 color:[statusColor colorWithAlphaComponent:0.13]];
605
- [statusText drawInRect:NSInsetRect(status, 9, 4) withAttributes:statusAttributes];
634
+ if (self.usesLiquidGlass) {
635
+ // 原生玻璃下不画彩色底标签,状态色交给字前的圆点;文字里自带的"●"去掉,免得两个点。
636
+ NSString *plain = [statusText stringByReplacingOccurrencesOfString:@"● " withString:@""];
637
+ [self drawText:plain inRect:NSMakeRect(NSMinX(card) + 96, NSMinY(card) + 57, 120, 20)
638
+ size:11 weight:NSFontWeightMedium color:statusColor dotColor:statusColor];
639
+ } else {
640
+ NSDictionary *statusAttributes = [self textAttributesWithSize:11 color:statusColor
641
+ weight:NSFontWeightMedium];
642
+ CGFloat statusWidth = ceil([statusText sizeWithAttributes:statusAttributes].width) + 18;
643
+ NSRect status = NSMakeRect(NSMinX(card) + 94, NSMinY(card) + 55, statusWidth, 24);
644
+ [self fillRoundedRect:status radius:12 color:[statusColor colorWithAlphaComponent:0.13]];
645
+ [statusText drawInRect:NSInsetRect(status, 9, 4) withAttributes:statusAttributes];
646
+ }
606
647
 
607
648
  if (apiMode) {
608
649
  CGFloat callX = NSMinX(card) + 214;
@@ -655,26 +696,31 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
655
696
  NSDictionary *requestComparison = [self comparisonForCurrent:
656
697
  [monthComparable[@"request_count"] doubleValue]
657
698
  previous:[previousMonthTokens[@"request_count"] doubleValue] color:color];
658
- [requestComparison[@"text"] drawInRect:NSMakeRect(callX, NSMinY(card) + 22, 158, 18)
659
- withAttributes:[self textAttributesWithSize:11 color:requestComparison[@"color"]
660
- weight:NSFontWeightMedium]];
699
+ [self drawText:requestComparison[@"text"] inRect:NSMakeRect(callX, NSMinY(card) + 22, 158, 18)
700
+ size:11 weight:NSFontWeightMedium color:requestComparison[@"color"]
701
+ dotColor:requestComparison[@"color"]];
661
702
  NSDictionary *tokenComparison = [self comparisonForCurrent:
662
703
  [monthComparable[@"total_tokens"] doubleValue]
663
704
  previous:[previousMonthTokens[@"total_tokens"] doubleValue] color:color];
664
- [tokenComparison[@"text"] drawInRect:NSMakeRect(tokenX, NSMinY(card) + 22, 158, 18)
665
- withAttributes:[self textAttributesWithSize:11 color:tokenComparison[@"color"]
666
- weight:NSFontWeightMedium]];
705
+ [self drawText:tokenComparison[@"text"] inRect:NSMakeRect(tokenX, NSMinY(card) + 22, 158, 18)
706
+ size:11 weight:NSFontWeightMedium color:tokenComparison[@"color"]
707
+ dotColor:tokenComparison[@"color"]];
667
708
 
668
709
  CGFloat trendX = NSMinX(card) + 564;
669
710
  // 「按日 Token」跟在标题后面,与标题同一行:它是标题的限定语,单独占一行既浪费
670
711
  // 竖向空间,也把曲线和脚注挤得没法与左边两列对齐。
671
712
  [@"本月趋势" drawInRect:NSMakeRect(trendX, NSMinY(card) + 114, 60, 20)
672
713
  withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
673
- NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:color
674
- weight:NSFontWeightSemibold];
675
- NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, 76, 22);
676
- [self fillRoundedRect:pill radius:11 color:[color colorWithAlphaComponent:0.14]];
677
- [@"按日 Token" drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
714
+ if (self.usesLiquidGlass) {
715
+ [self drawText:@"按日 Token" inRect:NSMakeRect(trendX + 62, NSMinY(card) + 114, 96, 20)
716
+ size:11 weight:NSFontWeightSemibold color:color dotColor:color];
717
+ } else {
718
+ NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:color
719
+ weight:NSFontWeightSemibold];
720
+ NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, 76, 22);
721
+ [self fillRoundedRect:pill radius:11 color:[color colorWithAlphaComponent:0.14]];
722
+ [@"按日 Token" drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
723
+ }
678
724
  NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 62, 135, 38);
679
725
  [self drawMonthlyTokenCurve:monthDaily inRect:curveRect color:color];
680
726
  double peak = 0;
@@ -744,10 +790,13 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
744
790
  ? window[@"rolling"] : [NSString stringWithFormat:@"重置时间 %@", resetValue];
745
791
  [reset drawInRect:NSMakeRect(x, NSMinY(card) + 46, 150, 18)
746
792
  withAttributes:[self textAttributesWithSize:11 color:secondary weight:NSFontWeightRegular]];
747
- NSString *tokenText = [NSString stringWithFormat:@"已用 Token %@",
793
+ // 原生玻璃下字更大、前面还有圆点,这一栏放不下"Token"一词;脚注里已说明
794
+ // Token 即本机统计的已用量。
795
+ NSString *tokenText = [NSString stringWithFormat:
796
+ self.usesLiquidGlass ? @"已用 %@" : @"已用 Token %@",
748
797
  [self formattedTokenCount:window[@"tokens"]]];
749
- [tokenText drawInRect:NSMakeRect(x, NSMinY(card) + 22, 150, 22)
750
- withAttributes:[self textAttributesWithSize:14 color:color weight:NSFontWeightSemibold]];
798
+ [self drawText:tokenText inRect:NSMakeRect(x, NSMinY(card) + 22, 150, 22) size:14
799
+ weight:NSFontWeightSemibold color:color dotColor:color];
751
800
  }
752
801
 
753
802
  CGFloat trendX = NSMinX(card) + 564;
@@ -776,14 +825,19 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
776
825
  paceTip = @"官方额度受限,等待重置";
777
826
  tipColor = NSColor.systemOrangeColor;
778
827
  }
779
- NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:paceColor
780
- weight:NSFontWeightSemibold];
781
- // 档位标签跟在标题后面。宽度仍按文字算:四个档位不一样长,最宽的"数据不足"到
782
- // trendX + 131,列宽 145 放得下。
783
- CGFloat pillWidth = ceil([pace[@"label"] sizeWithAttributes:pillAttributes].width) + 18;
784
- NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, pillWidth, 22);
785
- [self fillRoundedRect:pill radius:11 color:[paceColor colorWithAlphaComponent:0.14]];
786
- [pace[@"label"] drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
828
+ if (self.usesLiquidGlass) {
829
+ [self drawText:pace[@"label"] inRect:NSMakeRect(trendX + 62, NSMinY(card) + 114, 96, 20)
830
+ size:11 weight:NSFontWeightSemibold color:paceColor dotColor:paceColor];
831
+ } else {
832
+ NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:paceColor
833
+ weight:NSFontWeightSemibold];
834
+ // 档位标签跟在标题后面。宽度仍按文字算:四个档位不一样长,最宽的"数据不足"到
835
+ // trendX + 131,列宽 145 放得下。
836
+ CGFloat pillWidth = ceil([pace[@"label"] sizeWithAttributes:pillAttributes].width) + 18;
837
+ NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, pillWidth, 22);
838
+ [self fillRoundedRect:pill radius:11 color:[paceColor colorWithAlphaComponent:0.14]];
839
+ [pace[@"label"] drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
840
+ }
787
841
 
788
842
  NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 62, 135, 38);
789
843
  [self drawUsageCurve:points inRect:curveRect color:color];
@@ -799,8 +853,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
799
853
  withAttributes:[self rightAlignedTextAttributesWithSize:10 color:secondary
800
854
  weight:NSFontWeightRegular]];
801
855
  // 与左边两列的"已用 Token"同一条基线(+22),也和 API 卡的脚注行对齐。
802
- [paceTip drawInRect:NSMakeRect(trendX, NSMinY(card) + 22, 145, 18)
803
- withAttributes:[self textAttributesWithSize:11 color:tipColor weight:NSFontWeightMedium]];
856
+ [self drawTip:paceTip inRect:NSMakeRect(trendX, NSMinY(card) + 22, 145, 18) color:tipColor];
804
857
  }
805
858
  - (void)drawRect:(NSRect)dirtyRect {
806
859
  [NSGraphicsContext saveGraphicsState];
@@ -812,44 +865,65 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
812
865
  NSRect logicalBounds = NSMakeRect(0, 0, QuotaLogicalWidth, height);
813
866
  NSRect outer = NSInsetRect(logicalBounds, 1, 1);
814
867
  NSBezierPath *background = [NSBezierPath bezierPathWithRoundedRect:outer xRadius:24 yRadius:24];
815
- NSGradient *gradient = [[NSGradient alloc]
816
- initWithStartingColor:[NSColor colorWithRed:0.025 green:0.055 blue:0.095 alpha:0.88]
817
- endingColor:[NSColor colorWithRed:0.07 green:0.12 blue:0.19 alpha:0.80]];
818
- [gradient drawInBezierPath:background angle:-20];
868
+ // 原生玻璃按 13pt 圆角裁切整个面板;底色也铺满到同一圆角,否则玻璃边缘和
869
+ // 底色之间会露出一圈细缝。
870
+ if (self.usesLiquidGlass) {
871
+ CGFloat radius = 13 / QuotaScale;
872
+ background = [NSBezierPath bezierPathWithRoundedRect:logicalBounds
873
+ xRadius:radius yRadius:radius];
874
+ }
875
+ // 原生玻璃不铺底色:任何一层深色都会把 Clear 玻璃压回磨砂感。
876
+ if (!self.usesLiquidGlass) {
877
+ NSGradient *gradient = [[NSGradient alloc]
878
+ initWithStartingColor:[NSColor colorWithRed:0.025 green:0.055 blue:0.095 alpha:0.88]
879
+ endingColor:[NSColor colorWithRed:0.07 green:0.12 blue:0.19 alpha:0.80]];
880
+ [gradient drawInBezierPath:background angle:-20];
881
+ }
819
882
 
820
- [NSGraphicsContext saveGraphicsState];
821
- [background addClip];
822
- NSGradient *topGlow = [[NSGradient alloc]
823
- initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.34]
824
- endingColor:[NSColor colorWithWhite:1 alpha:0.0]];
825
- // 两处光晕原本是按 H=590 定的绝对点。面板会变矮,改成跟着高度走:顶部光源始终悬在
826
- // 面板上沿之外,冷色光晕落在内容区中段。
827
- NSPoint topGlowCenter = NSMakePoint(700, height + 60);
828
- [topGlow drawFromCenter:topGlowCenter radius:0
829
- toCenter:topGlowCenter radius:250 options:0];
830
- NSGradient *cyanGlow = [[NSGradient alloc]
831
- initWithStartingColor:[NSColor colorWithRed:0.18 green:0.72 blue:1 alpha:0.11]
832
- endingColor:[NSColor colorWithRed:0.18 green:0.88 blue:1 alpha:0.0]];
833
- NSPoint cyanGlowCenter = NSMakePoint(660, height * 0.42);
834
- [cyanGlow drawFromCenter:cyanGlowCenter radius:0
835
- toCenter:cyanGlowCenter radius:260 options:0];
836
- [NSGraphicsContext restoreGraphicsState];
883
+ // 原生玻璃自己绘制高光和边缘,不叠加经典主题的模拟反光。
884
+ if (!self.usesLiquidGlass) {
885
+ [NSGraphicsContext saveGraphicsState];
886
+ [background addClip];
887
+ NSGradient *topGlow = [[NSGradient alloc]
888
+ initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.34]
889
+ endingColor:[NSColor colorWithWhite:1 alpha:0.0]];
890
+ // 两处光晕原本是按 H=590 定的绝对点。面板会变矮,改成跟着高度走:顶部光源始终悬在
891
+ // 面板上沿之外,冷色光晕落在内容区中段。
892
+ NSPoint topGlowCenter = NSMakePoint(700, height + 60);
893
+ [topGlow drawFromCenter:topGlowCenter radius:0
894
+ toCenter:topGlowCenter radius:250 options:0];
895
+ NSGradient *cyanGlow = [[NSGradient alloc]
896
+ initWithStartingColor:[NSColor colorWithRed:0.18 green:0.72 blue:1 alpha:0.11]
897
+ endingColor:[NSColor colorWithRed:0.18 green:0.88 blue:1 alpha:0.0]];
898
+ NSPoint cyanGlowCenter = NSMakePoint(660, height * 0.42);
899
+ [cyanGlow drawFromCenter:cyanGlowCenter radius:0
900
+ toCenter:cyanGlowCenter radius:260 options:0];
901
+ [NSGraphicsContext restoreGraphicsState];
837
902
 
838
- [[NSColor colorWithWhite:1 alpha:0.34] setStroke];
839
- background.lineWidth = 1.5;
840
- [background stroke];
841
- NSBezierPath *innerGlassBorder = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(outer, 2, 2)
842
- xRadius:22 yRadius:22];
843
- [[NSColor colorWithRed:0.58 green:0.82 blue:1 alpha:0.22] setStroke];
844
- innerGlassBorder.lineWidth = 0.8;
845
- [innerGlassBorder stroke];
903
+ [[NSColor colorWithWhite:1 alpha:0.34] setStroke];
904
+ background.lineWidth = 1.5;
905
+ [background stroke];
906
+ NSBezierPath *innerGlassBorder = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(outer, 2, 2)
907
+ xRadius:22 yRadius:22];
908
+ [[NSColor colorWithRed:0.58 green:0.82 blue:1 alpha:0.22] setStroke];
909
+ innerGlassBorder.lineWidth = 0.8;
910
+ [innerGlassBorder stroke];
911
+ }
912
+ // 玻璃底下可能是任意亮度的壁纸,除了玻璃背后的压暗层,再给白字加一层很淡的投影托底。
913
+ if (self.usesLiquidGlass) {
914
+ NSShadow *legibility = [NSShadow new];
915
+ legibility.shadowColor = [NSColor colorWithWhite:0 alpha:0.4];
916
+ legibility.shadowBlurRadius = 2;
917
+ legibility.shadowOffset = NSMakeSize(0, -0.5);
918
+ [legibility set];
919
+ }
846
920
  NSColor *primary = self.primaryColor;
847
921
  NSColor *secondary = self.secondaryColor;
848
922
  NSColor *cyan = self.accentColor;
849
923
  NSColor *agentColor = self.agentStatusColor;
850
924
  [@"Agent Usage" drawInRect:NSMakeRect(28, height - 65, 260, 42)
851
925
  withAttributes:[self textAttributesWithSize:30 color:primary weight:NSFontWeightBold]];
852
- [@"实时状态与滚动用量" drawInRect:NSMakeRect(30, height - 94, 130, 22)
926
+ [@"实时状态与滚动用量" drawInRect:NSMakeRect(30, height - 94, self.usesLiquidGlass ? 142 : 130, 22)
853
927
  withAttributes:[self textAttributesWithSize:14 color:secondary weight:NSFontWeightRegular]];
854
928
  [agentColor setFill];
855
929
  [[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(174, height - 88, 9, 9)] fill];
@@ -860,17 +934,10 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
860
934
  withAttributes:[self textAttributesWithSize:14 color:agentColor weight:NSFontWeightMedium]];
861
935
  [self drawSystemMetricsEndingAtX:QuotaLogicalWidth - 28 y:height - 95];
862
936
 
863
- BOOL recentlyRefreshed = self.refreshedUntil > NSDate.date.timeIntervalSince1970;
864
- CGFloat buttonAlpha = self.refreshPressed ? 0.18 : (self.refreshHovered ? 0.12 : 0.06);
865
- NSRect logicalRefreshRect = [self logicalRefreshRect];
866
- NSRect refreshRect = self.refreshPressed ? NSInsetRect(logicalRefreshRect, 1.5, 1.5) : logicalRefreshRect;
867
- [self fillRoundedRect:refreshRect radius:10 color:[NSColor colorWithWhite:1 alpha:buttonAlpha]];
868
- [recentlyRefreshed ? @"✓" : @"↻" drawInRect:NSInsetRect(refreshRect, 8, 4)
869
- withAttributes:[self textAttributesWithSize:19 color:[NSColor colorWithWhite:0.9 alpha:1] weight:NSFontWeightRegular]];
870
- // 贴着刷新按钮左侧右对齐:它说明的正是这个按钮上次生效的时间,挨着放才不用再标一遍
871
- // "数据刷新"是什么意思。放回汇总条里会挤掉一整格 Provider 数据。
937
+ // 用量由定时器自动刷新,面板不再提供手动刷新按钮;右上角只留上次刷新的时间,
938
+ // 与下一行的系统指标右边对齐。放回汇总条里会挤掉一整格 Provider 数据。
872
939
  [[NSString stringWithFormat:@"数据刷新 %@", [self refreshAgeText]]
873
- drawInRect:NSMakeRect(NSMinX(logicalRefreshRect) - 206, NSMinY(logicalRefreshRect) + 7, 200, 18)
940
+ drawInRect:NSMakeRect(QuotaLogicalWidth - 28 - 200, height - 45, 200, 18)
874
941
  withAttributes:[self rightAlignedTextAttributesWithSize:11 color:secondary
875
942
  weight:NSFontWeightRegular]];
876
943
 
@@ -882,7 +949,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
882
949
  @"Codex": @{@"usage": self.codexUsage ?: @{}, @"usedKey": @"used_percent",
883
950
  @"color": cyan},
884
951
  @"Claude": @{@"usage": self.claudeUsage ?: @{}, @"usedKey": @"used_percentage",
885
- @"color": [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1]}
952
+ @"color": self.claudeColor}
886
953
  };
887
954
  // 卡片从汇总条下方依次向下排。少一家就少一张卡,脚注跟着上移;这里的分段账必须和
888
955
  // QuotaLogicalHeightForProviderCount 完全一致,否则面板会多出或少掉一段空白。
@@ -919,11 +986,15 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
919
986
  ? @"ⓘ 桌宠与系统状态不受影响;额度卡只在检测到对应 CLI 时显示"
920
987
  : (hasAPICard
921
988
  ? @"ⓘ API 用量 = 本机会话统计(输入含缓存读写);环比按上月相同时间进度计算"
922
- : @"ⓘ 百分比 = 官方订阅额度的剩余比例;Token = 本机统计的已用量(输入含缓存读写),两者口径不同");
989
+ : (self.usesLiquidGlass
990
+ ? @"ⓘ 百分比 = 官方额度剩余;Token = 本机统计已用量(含缓存读写)"
991
+ : @"ⓘ 百分比 = 官方订阅额度的剩余比例;Token = 本机统计的已用量(输入含缓存读写),两者口径不同"));
923
992
  // 最后一块的底边距面板底 QuotaFooterHeight:脚注与其留约 8pt,底部留白 16pt,
924
993
  // 和顶部标题的留白大致对称。
925
994
  [footer drawInRect:NSMakeRect(28, 16, 650, 20)
926
- withAttributes:[self textAttributesWithSize:11 color:[NSColor colorWithWhite:0.58 alpha:1] weight:NSFontWeightRegular]];
995
+ withAttributes:[self textAttributesWithSize:11
996
+ color:self.usesLiquidGlass ? self.secondaryColor : [NSColor colorWithWhite:0.58 alpha:1]
997
+ weight:NSFontWeightRegular]];
927
998
  [NSGraphicsContext restoreGraphicsState];
928
999
  }
929
1000
 
@@ -935,9 +1006,13 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
935
1006
  secondary:(NSColor *)secondary accent:(NSColor *)cyan {
936
1007
  NSRect summary = [self logicalSummaryRect];
937
1008
  NSBezierPath *summaryPath = [NSBezierPath bezierPathWithRoundedRect:summary xRadius:18 yRadius:18];
938
- [[NSColor colorWithWhite:1 alpha:0.065] setFill];
939
- [summaryPath fill];
940
- [[NSColor colorWithWhite:1 alpha:0.16] setStroke];
1009
+ if (self.usesLiquidGlass) {
1010
+ [self fillLiquidScrim:summaryPath];
1011
+ } else {
1012
+ [[NSColor colorWithWhite:1 alpha:0.065] setFill];
1013
+ [summaryPath fill];
1014
+ }
1015
+ [[NSColor colorWithWhite:1 alpha:self.usesLiquidGlass ? 0.10 : 0.16] setStroke];
941
1016
  [summaryPath stroke];
942
1017
 
943
1018
  NSArray<NSDictionary *> *cells = @[
@@ -949,7 +1024,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
949
1024
  NSDictionary *rowSpecs = @{
950
1025
  @"Codex": @{@"usage": self.codexUsage ?: @{}, @"color": cyan},
951
1026
  @"Claude": @{@"usage": self.claudeUsage ?: @{},
952
- @"color": [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1]}
1027
+ @"color": self.claudeColor}
953
1028
  };
954
1029
  // 两行版的槽位是写死的。只装了一家时改用居中的单行槽位,否则汇总条会空出半格,
955
1030
  // 看着像数据没加载出来。
@@ -977,9 +1052,9 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
977
1052
  CGFloat x = NSMinX([self logicalSummaryCellRectAtIndex:index]);
978
1053
  const CGFloat inputX = x + 176;
979
1054
  const CGFloat outputX = x + 276;
980
- NSFont *headerFont = [NSFont systemFontOfSize:11 weight:NSFontWeightRegular];
1055
+ NSFont *headerFont = [self fontWithSize:11 weight:NSFontWeightRegular];
981
1056
  NSDictionary *headerAttributes = @{NSFontAttributeName: headerFont,
982
- NSForegroundColorAttributeName: secondary};
1057
+ NSForegroundColorAttributeName: [self textColor:secondary]};
983
1058
  NSImage *headerIcon = [NSImage imageWithSystemSymbolName:cell[@"headerSymbol"]
984
1059
  accessibilityDescription:cell[@"label"]];
985
1060
  NSImageSymbolConfiguration *headerIconConfiguration =
@@ -1009,9 +1084,10 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
1009
1084
  CGFloat nameY = NSMinY(summary) + [row[@"nameY"] doubleValue];
1010
1085
  CGFloat labelY = NSMinY(summary) + [row[@"labelY"] doubleValue];
1011
1086
  CGFloat valueY = NSMinY(summary) + [row[@"valueY"] doubleValue];
1087
+ // 这是图标字形不是文字,原生玻璃下也保留颜色:它负责标出这一行是哪一家。
1012
1088
  [cell[@"icon"] drawInRect:NSMakeRect(x + 20, iconY, 42, 42)
1013
- withAttributes:[self textAttributesWithSize:30 color:rowColor
1014
- weight:NSFontWeightRegular]];
1089
+ withAttributes:@{NSFontAttributeName: [NSFont systemFontOfSize:30
1090
+ weight:NSFontWeightRegular], NSForegroundColorAttributeName: rowColor}];
1015
1091
  [row[@"name"] drawInRect:NSMakeRect(x + 66, nameY, 76, 22)
1016
1092
  withAttributes:[self textAttributesWithSize:14 color:rowColor
1017
1093
  weight:NSFontWeightMedium]];
@@ -2,6 +2,7 @@
2
2
  #import "CCPetsAppDelegate.h"
3
3
  #import "CCPetsEvents.h"
4
4
  #import "CCPetsPaths.h"
5
+ #import "CCPetsPhrases.h"
5
6
  #import "CCPetsPreviews.h"
6
7
  #import "CCPetsQuotaHistory.h"
7
8
  #import "CCPetsUsage.h"
@@ -45,8 +46,21 @@ int main(int argc, const char *argv[]) {
45
46
  if (argc > 1 && (strcmp(argv[1], "--provider-event") == 0 ||
46
47
  strcmp(argv[1], "provider-event") == 0)) return RecordProviderEvent();
47
48
  if (argc > 1 && strcmp(argv[1], "--claude-usage") == 0) return RecordClaudeUsage();
49
+ if (argc > 1 && strcmp(argv[1], "--codex-launch") == 0) return RegisterCodexLaunch();
48
50
  if (argc > 1 && strcmp(argv[1], "--clean") == 0) return CleanCCPetsData(NO);
49
51
  if (argc > 1 && strcmp(argv[1], "--purge-data") == 0) return CleanCCPetsData(YES);
52
+ if (argc > 1 && strcmp(argv[1], "--paths") == 0) {
53
+ NSMutableDictionary *paths = [CCPetsDataPaths() mutableCopy];
54
+ paths[@"phrases"] = PetPhrasesFilePath();
55
+ paths[@"petPhrases"] = PetPhrasesPetDirectory();
56
+ NSData *json = [NSJSONSerialization dataWithJSONObject:paths
57
+ options:NSJSONWritingPrettyPrinted | NSJSONWritingSortedKeys | NSJSONWritingWithoutEscapingSlashes
58
+ error:nil];
59
+ if (!json) return EXIT_FAILURE;
60
+ fwrite(json.bytes, 1, json.length, stdout);
61
+ fputc('\n', stdout);
62
+ return EXIT_SUCCESS;
63
+ }
50
64
  if (argc > 1 && strcmp(argv[1], "--history") == 0) {
51
65
  NSData *json = [NSJSONSerialization dataWithJSONObject:QuotaHistoryDocument()
52
66
  options:NSJSONWritingPrettyPrinted error:nil];
@@ -84,6 +98,21 @@ int main(int argc, const char *argv[]) {
84
98
  return EXIT_SUCCESS;
85
99
  }
86
100
 
101
+ // 走到这里就要启动桌宠了。拼错的 `--xxx` 原先会被当成"启动":桌宠已在运行时静默退出,
102
+ // 否则在前台拉起一个桌宠占住终端,两种都让人看不出哪里错了。只拦双横线参数:
103
+ // 单横线的 -psn_* / -NS* / -Apple* 是系统和 Xcode 启动 App 时自己加的。
104
+ for (int index = 1; index < argc; index++) {
105
+ if (strncmp(argv[index], "--", 2) != 0) continue;
106
+ static const char *launchFlags[] = {"--managed", "--standalone", "--preview-dashboard"};
107
+ BOOL known = NO;
108
+ for (size_t flag = 0; flag < sizeof(launchFlags) / sizeof(launchFlags[0]); flag++) {
109
+ if (strcmp(argv[index], launchFlags[flag]) == 0) known = YES;
110
+ }
111
+ if (known) continue;
112
+ fprintf(stderr, "未知参数:%s\n运行 cc-pets --help 查看用法。\n", argv[index]);
113
+ return 2;
114
+ }
115
+
87
116
  NSString *lockName = [NSString stringWithFormat:@"cc-pets-%u.lock", getuid()];
88
117
  NSString *lockPath = [PetStateDirectory() stringByAppendingPathComponent:lockName];
89
118
  int lock = open(lockPath.fileSystemRepresentation, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);