cc-pets 1.1.3 → 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
|
}
|
|
@@ -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,
|
|
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
|
|
410
|
-
//
|
|
435
|
+
// 每格内是一张 2×2 表:标题独占一行,每个 Provider 独占一行;输入/输出标签放在
|
|
436
|
+
// 对应数值上方。这样既能完整展示 7 天统计起期,也不会挤乱两家的数据行。
|
|
411
437
|
NSArray<NSDictionary *> *cells = @[
|
|
412
|
-
@{@"icon": @"◔", @"key": @"today", @"label": @"
|
|
413
|
-
@{@"icon": @"◉", @"key": @"recentWeek", @"label":
|
|
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,
|
|
418
|
-
|
|
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 +
|
|
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 +
|
|
437
|
-
|
|
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
|
-
|
|
446
|
-
|
|
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,
|
|
485
|
+
drawInRect:NSMakeRect(inputX, valueY, 86, 23) withAttributes:valueAttributes];
|
|
452
486
|
[[self formattedTokenSplitForUsage:usage key:key wantsOutput:YES]
|
|
453
|
-
drawInRect:NSMakeRect(outputX,
|
|
487
|
+
drawInRect:NSMakeRect(outputX, valueY, 76, 23) withAttributes:valueAttributes];
|
|
454
488
|
}
|
|
455
489
|
}
|
|
456
490
|
|
package/package.json
CHANGED
|
File without changes
|