cc-pets 1.1.2 → 1.1.31

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.
@@ -650,6 +650,7 @@ static NSDictionary *UsageByAddingTokenTotals(NSDictionary *usage, NSURL *sessio
650
650
  @"week": weekTokens ?: NSNull.null,
651
651
  @"today": todayTokens ?: NSNull.null,
652
652
  @"recentWeek": recentTokens ?: NSNull.null,
653
+ @"recentWeekStartsAt": @(rollingWeekStart),
653
654
  @"source": @"local"
654
655
  };
655
656
  return result;
@@ -1064,6 +1065,7 @@ static NSDictionary *ClaudeTokenTotals(NSArray<NSData *> *recordSets, NSTimeInte
1064
1065
  @"week": ClaudeTokenTotals(recordSets, weekStart, weekEnd),
1065
1066
  @"today": ClaudeTokenTotals(recordSets, todayStart, rollingEnd),
1066
1067
  @"recentWeek": ClaudeTokenTotals(recordSets, rollingWeekStart, rollingEnd),
1068
+ @"recentWeekStartsAt": @(rollingWeekStart),
1067
1069
  @"source": @"local"
1068
1070
  };
1069
1071
  }
@@ -205,6 +205,13 @@ static const CGFloat PetDragThreshold = 3.0;
205
205
  }
206
206
  - (void)nextFrame:(NSTimer *)timer {
207
207
  if (self.lookDirection >= 0) return;
208
+ // performWindowDragWithEvent: 会立即返回,且窗口服务器可能吞掉 mouseUp。
209
+ // 动画时钟同时作为释放兜底,避免拖动状态永久停留在 running 行。
210
+ if (self.draggingPet &&
211
+ !CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft)) {
212
+ [self endPetDrag];
213
+ return;
214
+ }
208
215
  self.sequenceIndex += 1;
209
216
  if (self.sequenceIndex >= self.frames.count) {
210
217
  if (self.oneShot) {
@@ -286,9 +293,9 @@ static const CGFloat PetDragThreshold = 3.0;
286
293
  if (hypot(horizontal, vertical) < PetDragThreshold) return;
287
294
  [self runWindowDragWithEvent:event movingRight:horizontal >= 0];
288
295
  }
289
- // 拖动整段交给窗口服务器:它不依赖应用事件流,所以掠过其他窗口、拖出屏幕、
290
- // 应用非活跃都不会中断,也不可能丢 mouseUp。函数阻塞到用户松手才返回,
291
- // 前后两段状态因此天然配对,不存在"开始了但没结束"。
296
+ // 拖动交给窗口服务器:它不依赖应用事件流,所以掠过其他窗口、拖出屏幕、
297
+ // 应用非活跃都不会中断。这个 API 会立即返回,且 mouseUp 可能不会发回应用,
298
+ // 因此不能在调用后立刻恢复 idle;释放兜底由 nextFrame: 检查物理按键状态。
292
299
  - (void)runWindowDragWithEvent:(NSEvent *)event movingRight:(BOOL)movingRight {
293
300
  self.draggingPet = YES;
294
301
  if (self.pocketHoverChanged) self.pocketHoverChanged(NO);
@@ -296,14 +303,18 @@ static const CGFloat PetDragThreshold = 3.0;
296
303
  [self playRow:movingRight ? 1 : 2 throughFrame:7 oneShot:NO];
297
304
 
298
305
  [self.window performWindowDragWithEvent:event];
299
-
306
+ }
307
+ - (void)endPetDrag {
308
+ if (!self.draggingPet) return;
300
309
  self.draggingPet = NO;
301
310
  if (self.dragStateChanged) self.dragStateChanged(NO);
302
311
  [self playRow:0 throughFrame:5 oneShot:NO];
303
312
  }
304
- // 拖动会话(含 mouseUp)已被 performWindowDragWithEvent: 消费,所以能走到这里
305
- // 就说明本次按下没有拖动过,不需要额外的标志来区分。
306
313
  - (void)mouseUp:(NSEvent *)event {
314
+ if (self.draggingPet) {
315
+ [self endPetDrag];
316
+ return;
317
+ }
307
318
  [self playRow:7 throughFrame:5 oneShot:YES];
308
319
  }
309
320
  - (void)drawRect:(NSRect)dirtyRect {
@@ -55,7 +55,7 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
55
55
  logical.size.width * QuotaScale, logical.size.height * QuotaScale);
56
56
  }
57
57
  - (NSRect)logicalSummaryRect {
58
- return NSMakeRect(20, 372, QuotaLogicalWidth - 40, 86);
58
+ return NSMakeRect(20, 372, QuotaLogicalWidth - 40, 112);
59
59
  }
60
60
  // 刷新时间挪去了右上角,这一版块整宽留给两个统计格,各占一半。
61
61
  - (NSRect)logicalSummaryCellRectAtIndex:(NSUInteger)index {
@@ -145,6 +145,32 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
145
145
  NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
146
146
  return reset ? [self clockText:reset.doubleValue] : @"--";
147
147
  }
148
+ // 汇总条的最近 7 天是共享的自然日口径。优先显示聚合结果携带的真实边界;兼容旧缓存时,
149
+ // 再按同一规则(含今天在内的 7 个自然日)现场计算,避免界面暂时退回到没有起期。
150
+ - (NSString *)recentWeekUsageLabel {
151
+ NSNumber *start = nil;
152
+ for (NSDictionary *usage in @[self.codexUsage ?: @{}, self.claudeUsage ?: @{}]) {
153
+ NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
154
+ ? usage[@"tokenUsage"] : nil;
155
+ if ([tokenUsage[@"recentWeekStartsAt"] isKindOfClass:NSNumber.class]) {
156
+ start = tokenUsage[@"recentWeekStartsAt"];
157
+ break;
158
+ }
159
+ }
160
+ if (!start) {
161
+ NSCalendar *calendar = NSCalendar.currentCalendar;
162
+ NSDate *midnight = [calendar startOfDayForDate:NSDate.date];
163
+ NSDate *date = [calendar dateByAddingUnit:NSCalendarUnitDay value:-6 toDate:midnight
164
+ options:0];
165
+ start = @((date ?: midnight).timeIntervalSince1970);
166
+ }
167
+ NSDateFormatter *formatter = [NSDateFormatter new];
168
+ formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
169
+ formatter.timeZone = NSTimeZone.localTimeZone;
170
+ formatter.dateFormat = @"yyyy-MM-dd";
171
+ return [NSString stringWithFormat:@"近 7 天(%@ 至今)",
172
+ [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:start.doubleValue]]];
173
+ }
148
174
  // 在线 = 这一家还有活着的客户端,和有没有额度数据无关:额度会一直缓存着,
149
175
  // 拿它当在线信号会恒亮。身份不明的老客户端无法归属到某一家,保守地都算在线。
150
176
  - (BOOL)isProviderOnline:(NSString *)name {
@@ -406,16 +432,18 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
406
432
 
407
433
  // 今日与最近 7 天都按 Provider 分开展示。底层本来就是两套独立的自然日统计,
408
434
  // 不在展示层相加,避免用户无法判断 Token 来自 Codex 还是 Claude。
409
- // 每格内是一张 2×2 表:行是 Provider,列是输入/输出,列头与格标题共用一行 —— 86pt
410
- // 高度只够三行,再单开一行列头就得把格子拔高,挤掉下面两张 Provider 卡片。
435
+ // 每格内是一张 2×2 表:标题独占一行,每个 Provider 独占一行;输入/输出标签放在
436
+ // 对应数值上方。这样既能完整展示 7 天统计起期,也不会挤乱两家的数据行。
411
437
  NSArray<NSDictionary *> *cells = @[
412
- @{@"icon": @"◔", @"key": @"today", @"label": @"今日已用 Token"},
413
- @{@"icon": @"◉", @"key": @"recentWeek", @"label": @"近 7 天已用 Token"}
438
+ @{@"icon": @"◔", @"key": @"today", @"label": @"▣ 今日用量"},
439
+ @{@"icon": @"◉", @"key": @"recentWeek", @"label": [self recentWeekUsageLabel]}
414
440
  ];
415
441
  NSColor *claudeColor = [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1];
416
442
  NSArray<NSDictionary *> *rows = @[
417
- @{@"name": @"Codex", @"usage": self.codexUsage ?: @{}, @"color": cyan, @"y": @35},
418
- @{@"name": @"Claude", @"usage": self.claudeUsage ?: @{}, @"color": claudeColor, @"y": @12}
443
+ @{@"name": @"Codex", @"usage": self.codexUsage ?: @{}, @"color": cyan,
444
+ @"iconY": @43, @"nameY": @52, @"labelY": @68, @"valueY": @47},
445
+ @{@"name": @"Claude", @"usage": self.claudeUsage ?: @{}, @"color": claudeColor,
446
+ @"iconY": @5, @"nameY": @14, @"labelY": @30, @"valueY": @9}
419
447
  ];
420
448
  [[NSColor colorWithWhite:1 alpha:0.10] setStroke];
421
449
  for (NSUInteger index = 1; index < cells.count; index++) {
@@ -428,29 +456,35 @@ NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
428
456
  NSString *key = cell[@"key"];
429
457
  CGFloat x = NSMinX([self logicalSummaryCellRectAtIndex:index]);
430
458
  const CGFloat inputX = x + 176;
431
- const CGFloat outputX = x + 266;
432
- [cell[@"icon"] drawInRect:NSMakeRect(x + 24, NSMinY(summary) + 23, 42, 42)
433
- withAttributes:[self textAttributesWithSize:30 color:cyan weight:NSFontWeightRegular]];
459
+ const CGFloat outputX = x + 276;
434
460
  NSDictionary *headerAttributes = [self textAttributesWithSize:11 color:secondary
435
461
  weight:NSFontWeightRegular];
436
- [cell[@"label"] drawInRect:NSMakeRect(x + 72, NSMinY(summary) + 59, 100, 18)
437
- withAttributes:headerAttributes];
438
- [@"输入" drawInRect:NSMakeRect(inputX, NSMinY(summary) + 59, 86, 18)
439
- withAttributes:headerAttributes];
440
- [@"输出" drawInRect:NSMakeRect(outputX, NSMinY(summary) + 59, 86, 18)
462
+ [cell[@"label"] drawInRect:NSMakeRect(x + 24, NSMinY(summary) + 89,
463
+ NSWidth([self logicalSummaryCellRectAtIndex:index]) - 48, 18)
441
464
  withAttributes:headerAttributes];
442
465
  for (NSDictionary *row in rows) {
443
- CGFloat y = NSMinY(summary) + [row[@"y"] doubleValue];
444
466
  NSDictionary *usage = row[@"usage"];
445
- [row[@"name"] drawInRect:NSMakeRect(x + 72, y, 60, 20)
446
- withAttributes:[self textAttributesWithSize:12 color:row[@"color"]
467
+ NSColor *rowColor = row[@"color"];
468
+ CGFloat iconY = NSMinY(summary) + [row[@"iconY"] doubleValue];
469
+ CGFloat nameY = NSMinY(summary) + [row[@"nameY"] doubleValue];
470
+ CGFloat labelY = NSMinY(summary) + [row[@"labelY"] doubleValue];
471
+ CGFloat valueY = NSMinY(summary) + [row[@"valueY"] doubleValue];
472
+ [cell[@"icon"] drawInRect:NSMakeRect(x + 20, iconY, 42, 42)
473
+ withAttributes:[self textAttributesWithSize:30 color:rowColor
474
+ weight:NSFontWeightRegular]];
475
+ [row[@"name"] drawInRect:NSMakeRect(x + 66, nameY, 76, 22)
476
+ withAttributes:[self textAttributesWithSize:14 color:rowColor
447
477
  weight:NSFontWeightMedium]];
478
+ [@"输入" drawInRect:NSMakeRect(inputX, labelY, 76, 16)
479
+ withAttributes:headerAttributes];
480
+ [@"输出" drawInRect:NSMakeRect(outputX, labelY, 76, 16)
481
+ withAttributes:headerAttributes];
448
482
  NSDictionary *valueAttributes = [self textAttributesWithSize:16 color:primary
449
483
  weight:NSFontWeightBold];
450
484
  [[self formattedTokenSplitForUsage:usage key:key wantsOutput:NO]
451
- drawInRect:NSMakeRect(inputX, y - 2, 86, 23) withAttributes:valueAttributes];
485
+ drawInRect:NSMakeRect(inputX, valueY, 86, 23) withAttributes:valueAttributes];
452
486
  [[self formattedTokenSplitForUsage:usage key:key wantsOutput:YES]
453
- drawInRect:NSMakeRect(outputX, y - 2, 86, 23) withAttributes:valueAttributes];
487
+ drawInRect:NSMakeRect(outputX, valueY, 76, 23) withAttributes:valueAttributes];
454
488
  }
455
489
  }
456
490
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "1.1.2",
3
+ "version": "1.1.31",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": "wangxinyusqn",
6
6
  "license": "MIT",