cc-pets 2.2.1 → 2.3.0
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 +5 -2
- package/CC_BRIDGE.zh-CN.md +4 -2
- package/CHANGELOG.md +60 -0
- package/CHANGELOG.zh-CN.md +60 -0
- package/CONTRIBUTING.md +13 -10
- package/CONTRIBUTING.zh-CN.md +11 -10
- package/README.md +113 -24
- package/README.zh-CN.md +89 -28
- package/Resources/zh-Hans.lproj/Localizable.strings +568 -17
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +82 -23
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +70 -22
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +86 -98
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +8 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +15 -0
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +68 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
- package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +10 -2
- package/bin/codex-with-pet +13 -5
- package/package.json +1 -1
- package/scripts/build.sh +7 -3
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1839
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -1,1145 +0,0 @@
|
|
|
1
|
-
#import "QuotaDashboardView.h"
|
|
2
|
-
#import "CCPetsL10n.h"
|
|
3
|
-
|
|
4
|
-
const CGFloat QuotaLogicalWidth = 760;
|
|
5
|
-
const CGFloat QuotaLogicalHeight = 590;
|
|
6
|
-
const CGFloat QuotaScale = 0.58;
|
|
7
|
-
|
|
8
|
-
// 面板高度按"检测到几家 CLI"变化,所以纵向布局不再是一堆绝对坐标,而是自上而下的分段:
|
|
9
|
-
// 标题区 → 汇总条 → N × 额度卡 → 脚注区,块之间统一留 QuotaBlockGap。
|
|
10
|
-
// QuotaLogicalHeight 保留为两家都装时的高度(590),既是历史默认值,也是预览图尺寸。
|
|
11
|
-
static const CGFloat QuotaHeaderHeight = 106;
|
|
12
|
-
static const CGFloat QuotaSummaryHeight = 112;
|
|
13
|
-
static const CGFloat QuotaCardHeight = 152;
|
|
14
|
-
static const CGFloat QuotaBlockGap = 12;
|
|
15
|
-
static const CGFloat QuotaFooterHeight = 44;
|
|
16
|
-
// 两家都没装时的精简态:只留标题区、三行说明和脚注,汇总条和额度卡整块去掉——
|
|
17
|
-
// 没有 provider 的"今日用量/近 7 天"是两行 0,比不显示更让人以为是坏了。
|
|
18
|
-
static const CGFloat QuotaEmptyNoticeHeight = 76;
|
|
19
|
-
|
|
20
|
-
CGFloat QuotaLogicalHeightForProviderCount(NSUInteger count) {
|
|
21
|
-
if (count == 0) return QuotaHeaderHeight + QuotaEmptyNoticeHeight + QuotaFooterHeight;
|
|
22
|
-
return QuotaHeaderHeight + QuotaSummaryHeight +
|
|
23
|
-
count * (QuotaBlockGap + QuotaCardHeight) + QuotaFooterHeight;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
27
|
-
NSURL *appURL = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:bundleIdentifier];
|
|
28
|
-
NSMutableArray<NSString *> *paths = [NSMutableArray array];
|
|
29
|
-
if (appURL) {
|
|
30
|
-
NSBundle *bundle = [NSBundle bundleWithURL:appURL];
|
|
31
|
-
NSString *resourcePath = [bundle pathForResource:resourceName.stringByDeletingPathExtension
|
|
32
|
-
ofType:resourceName.pathExtension];
|
|
33
|
-
if (resourcePath.length > 0) [paths addObject:resourcePath];
|
|
34
|
-
}
|
|
35
|
-
NSString *applicationName = [bundleIdentifier containsString:@"anthropic"] ? @"Claude.app" : @"ChatGPT.app";
|
|
36
|
-
[paths addObject:[@"/Applications" stringByAppendingPathComponent:
|
|
37
|
-
[applicationName stringByAppendingPathComponent:[@"Contents/Resources" stringByAppendingPathComponent:resourceName]]]];
|
|
38
|
-
[paths addObject:[[NSHomeDirectory() stringByAppendingPathComponent:@"Applications"] stringByAppendingPathComponent:
|
|
39
|
-
[applicationName stringByAppendingPathComponent:[@"Contents/Resources" stringByAppendingPathComponent:resourceName]]]];
|
|
40
|
-
for (NSString *path in paths) {
|
|
41
|
-
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
42
|
-
if (image) return image;
|
|
43
|
-
}
|
|
44
|
-
return appURL ? [NSWorkspace.sharedWorkspace iconForFile:appURL.path] : nil;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@implementation QuotaDashboardView
|
|
48
|
-
- (instancetype)initWithFrame:(NSRect)frame {
|
|
49
|
-
if ((self = [super initWithFrame:frame])) {
|
|
50
|
-
NSTrackingArea *tracking = [[NSTrackingArea alloc] initWithRect:NSZeroRect
|
|
51
|
-
options:NSTrackingMouseEnteredAndExited |
|
|
52
|
-
NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
53
|
-
owner:self userInfo:nil];
|
|
54
|
-
[self addTrackingArea:tracking];
|
|
55
|
-
}
|
|
56
|
-
return self;
|
|
57
|
-
}
|
|
58
|
-
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
59
|
-
- (void)mouseEntered:(NSEvent *)event {
|
|
60
|
-
if (self.hoverChanged) self.hoverChanged(YES);
|
|
61
|
-
}
|
|
62
|
-
- (void)mouseExited:(NSEvent *)event {
|
|
63
|
-
if (self.hoverChanged) self.hoverChanged(NO);
|
|
64
|
-
}
|
|
65
|
-
// detectedProviders 未赋值时按"两家都有"渲染。这是刻意的兜底:探测是 App 侧的额外信号,
|
|
66
|
-
// 拿不到时宁可多画一张卡,也不要让有额度的用户看不到自己的卡片。
|
|
67
|
-
- (NSArray<NSString *> *)visibleProviders {
|
|
68
|
-
NSArray<NSString *> *order = @[@"Codex", @"Claude"];
|
|
69
|
-
if (!self.detectedProviders) return order;
|
|
70
|
-
NSMutableArray<NSString *> *visible = [NSMutableArray array];
|
|
71
|
-
for (NSString *name in order) {
|
|
72
|
-
if ([self.detectedProviders containsObject:name]) [visible addObject:name];
|
|
73
|
-
}
|
|
74
|
-
return visible;
|
|
75
|
-
}
|
|
76
|
-
- (CGFloat)logicalHeight {
|
|
77
|
-
return QuotaLogicalHeightForProviderCount([self visibleProviders].count);
|
|
78
|
-
}
|
|
79
|
-
- (NSRect)logicalSummaryRect {
|
|
80
|
-
return NSMakeRect(20, [self logicalHeight] - QuotaHeaderHeight - QuotaSummaryHeight,
|
|
81
|
-
QuotaLogicalWidth - 40, QuotaSummaryHeight + 1 / QuotaScale);
|
|
82
|
-
}
|
|
83
|
-
// 刷新时间挪去了右上角,这一版块整宽留给两个统计格,各占一半。
|
|
84
|
-
- (NSRect)logicalSummaryCellRectAtIndex:(NSUInteger)index {
|
|
85
|
-
NSRect summary = [self logicalSummaryRect];
|
|
86
|
-
CGFloat width = NSWidth(summary) / 2;
|
|
87
|
-
return index < 2
|
|
88
|
-
? NSMakeRect(NSMinX(summary) + index * width, NSMinY(summary), width, NSHeight(summary))
|
|
89
|
-
: NSZeroRect;
|
|
90
|
-
}
|
|
91
|
-
- (NSDictionary *)quota:(NSDictionary *)usage key:(NSString *)key {
|
|
92
|
-
id value = usage[key];
|
|
93
|
-
return [value isKindOfClass:NSDictionary.class] ? value : nil;
|
|
94
|
-
}
|
|
95
|
-
- (NSDictionary *)tokenTotals:(NSDictionary *)usage key:(NSString *)key {
|
|
96
|
-
NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
|
|
97
|
-
? usage[@"tokenUsage"] : nil;
|
|
98
|
-
return [tokenUsage[key] isKindOfClass:NSDictionary.class] ? tokenUsage[key] : nil;
|
|
99
|
-
}
|
|
100
|
-
- (NSString *)formattedTokenValue:(double)value {
|
|
101
|
-
if (value >= 1000000000) return [NSString stringWithFormat:@"%.2fB", value / 1000000000.0];
|
|
102
|
-
if (value >= 1000000) return [NSString stringWithFormat:@"%.2fM", value / 1000000.0];
|
|
103
|
-
if (value >= 1000) return [NSString stringWithFormat:@"%.1fK", value / 1000.0];
|
|
104
|
-
return [NSString stringWithFormat:@"%.0f", value];
|
|
105
|
-
}
|
|
106
|
-
- (NSString *)formattedTokenCount:(NSDictionary *)totals {
|
|
107
|
-
NSNumber *number = [totals[@"total_tokens"] isKindOfClass:NSNumber.class]
|
|
108
|
-
? totals[@"total_tokens"] : nil;
|
|
109
|
-
return number ? [self formattedTokenValue:number.doubleValue] : @"--";
|
|
110
|
-
}
|
|
111
|
-
- (NSString *)formattedRequestCount:(NSDictionary *)totals {
|
|
112
|
-
NSNumber *number = [totals[@"request_count"] isKindOfClass:NSNumber.class]
|
|
113
|
-
? totals[@"request_count"] : nil;
|
|
114
|
-
return number ? [NSNumberFormatter localizedStringFromNumber:number
|
|
115
|
-
numberStyle:NSNumberFormatterDecimalStyle] : @"--";
|
|
116
|
-
}
|
|
117
|
-
- (NSDictionary *)comparisonForCurrent:(double)current previous:(double)previous
|
|
118
|
-
color:(NSColor *)color {
|
|
119
|
-
if (previous <= 0) {
|
|
120
|
-
return @{ @"text": current > 0 ? L(@"vs last month: new") : L(@"vs last month: flat"),
|
|
121
|
-
@"color": current > 0 ? color : self.secondaryColor };
|
|
122
|
-
}
|
|
123
|
-
double change = (current - previous) * 100.0 / previous;
|
|
124
|
-
if (fabs(change) < 0.05) {
|
|
125
|
-
return @{ @"text": L(@"vs last month: flat"), @"color": self.secondaryColor };
|
|
126
|
-
}
|
|
127
|
-
return @{ @"text": [NSString stringWithFormat:L(@"vs last month %@%.1f%%"),
|
|
128
|
-
change > 0 ? @"↑" : @"↓", fabs(change)], @"color": color };
|
|
129
|
-
}
|
|
130
|
-
// 输入取 total - output,而不是把几个 input_* 字段加起来:两家的包含关系是相反的。
|
|
131
|
-
// Codex 的 cached_input_tokens 是 input_tokens 的子集(实测 input+output == total),
|
|
132
|
-
// 相加会把缓存部分算两遍;Claude 的 input_tokens 不含缓存读写,两者是并列项,不加又会漏。
|
|
133
|
-
// total - output 对两家都成立,也保证"输入 + 输出"正好等于卡片上那个已用 Token。
|
|
134
|
-
- (NSString *)formattedTokenSplit:(NSDictionary *)totals wantsOutput:(BOOL)wantsOutput {
|
|
135
|
-
NSNumber *total = [totals[@"total_tokens"] isKindOfClass:NSNumber.class]
|
|
136
|
-
? totals[@"total_tokens"] : nil;
|
|
137
|
-
if (!total) return @"--";
|
|
138
|
-
NSNumber *output = [totals[@"output_tokens"] isKindOfClass:NSNumber.class]
|
|
139
|
-
? totals[@"output_tokens"] : nil;
|
|
140
|
-
double outputValue = output ? output.doubleValue : 0;
|
|
141
|
-
return [self formattedTokenValue:
|
|
142
|
-
wantsOutput ? outputValue : fmax(0, total.doubleValue - outputValue)];
|
|
143
|
-
}
|
|
144
|
-
// 两个窗口共用。resets_at 是整分对齐的,带秒只会多占宽度。
|
|
145
|
-
- (NSString *)clockText:(NSTimeInterval)value {
|
|
146
|
-
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
147
|
-
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
|
|
148
|
-
formatter.timeZone = NSTimeZone.localTimeZone;
|
|
149
|
-
formatter.dateFormat = @"M/d HH:mm";
|
|
150
|
-
return [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:value]];
|
|
151
|
-
}
|
|
152
|
-
- (NSString *)resetText:(NSDictionary *)quota {
|
|
153
|
-
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class] ? quota[@"resets_at"] : nil;
|
|
154
|
-
return reset ? [self clockText:reset.doubleValue] : @"--";
|
|
155
|
-
}
|
|
156
|
-
// 汇总条的最近 7 天是共享的自然日口径。优先显示聚合结果携带的真实边界;兼容旧缓存时,
|
|
157
|
-
// 再按同一规则(含今天在内的 7 个自然日)现场计算,避免界面暂时退回到没有起期。
|
|
158
|
-
- (NSString *)recentWeekUsageLabel {
|
|
159
|
-
NSNumber *start = nil;
|
|
160
|
-
for (NSDictionary *usage in @[self.codexUsage ?: @{}, self.claudeUsage ?: @{}]) {
|
|
161
|
-
NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
|
|
162
|
-
? usage[@"tokenUsage"] : nil;
|
|
163
|
-
if ([tokenUsage[@"recentWeekStartsAt"] isKindOfClass:NSNumber.class]) {
|
|
164
|
-
start = tokenUsage[@"recentWeekStartsAt"];
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (!start) {
|
|
169
|
-
NSCalendar *calendar = NSCalendar.currentCalendar;
|
|
170
|
-
NSDate *midnight = [calendar startOfDayForDate:NSDate.date];
|
|
171
|
-
NSDate *date = [calendar dateByAddingUnit:NSCalendarUnitDay value:-6 toDate:midnight
|
|
172
|
-
options:0];
|
|
173
|
-
start = @((date ?: midnight).timeIntervalSince1970);
|
|
174
|
-
}
|
|
175
|
-
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
176
|
-
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
|
|
177
|
-
formatter.timeZone = NSTimeZone.localTimeZone;
|
|
178
|
-
// 原生玻璃下字号更大,完整说明在单元格里放不下,只留起始日期。
|
|
179
|
-
formatter.dateFormat = self.usesLiquidGlass ? @"M/d" : @"yyyy-MM-dd";
|
|
180
|
-
NSString *date = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:start.doubleValue]];
|
|
181
|
-
return self.usesLiquidGlass ? [NSString stringWithFormat:L(@"Last 7 days (since %@)"), date]
|
|
182
|
-
: [NSString stringWithFormat:L(@"Last 7 days (since %@, rolling)"), date];
|
|
183
|
-
}
|
|
184
|
-
// 在线 = 这一家还有活着的客户端,和有没有额度数据无关:额度会一直缓存着,
|
|
185
|
-
// 拿它当在线信号会恒亮。身份不明的老客户端无法归属到某一家,保守地都算在线。
|
|
186
|
-
- (BOOL)isProviderOnline:(NSString *)name {
|
|
187
|
-
return [self.liveProviders containsObject:name] || self.hasUnlabeledClient;
|
|
188
|
-
}
|
|
189
|
-
- (NSColor *)primaryColor { return [NSColor colorWithWhite:0.97 alpha:1]; }
|
|
190
|
-
- (NSColor *)secondaryColor {
|
|
191
|
-
// 没有深色底托着时,0.68 的灰在亮壁纸上会发虚。
|
|
192
|
-
return [NSColor colorWithWhite:self.usesLiquidGlass ? 0.84 : 0.68 alpha:1];
|
|
193
|
-
}
|
|
194
|
-
// 原生玻璃背后只有一层压暗,原来的紫在上面偏暗,提亮到和青色相近的明度。
|
|
195
|
-
- (NSColor *)claudeColor {
|
|
196
|
-
return self.usesLiquidGlass ? [NSColor colorWithRed:0.80 green:0.66 blue:1.00 alpha:1]
|
|
197
|
-
: [NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1];
|
|
198
|
-
}
|
|
199
|
-
- (NSColor *)accentColor { return [NSColor colorWithRed:0.30 green:0.82 blue:0.90 alpha:1]; }
|
|
200
|
-
// 有 Agent 在线才用绿色,否则整块转灰,避免"暂无 Agent 在线"配一个绿点。
|
|
201
|
-
- (NSColor *)agentStatusColor {
|
|
202
|
-
return self.activeAgentCount > 0 ? NSColor.systemGreenColor : self.secondaryColor;
|
|
203
|
-
}
|
|
204
|
-
- (void)drawSystemMetricsEndingAtX:(CGFloat)rightEdge y:(CGFloat)y {
|
|
205
|
-
NSMutableArray<NSDictionary *> *metrics = [NSMutableArray array];
|
|
206
|
-
if (self.systemCPUEnabled) {
|
|
207
|
-
NSString *value = self.systemCPUPercent
|
|
208
|
-
? [NSString stringWithFormat:@"%.0f%%", self.systemCPUPercent.doubleValue] : @"--";
|
|
209
|
-
[metrics addObject:@{@"symbol": @"cpu", @"label": [NSString stringWithFormat:@"CPU %@", value],
|
|
210
|
-
@"color": [NSColor colorWithRed:245.0 / 255.0 green:166.0 / 255.0
|
|
211
|
-
blue:35.0 / 255.0 alpha:1]}];
|
|
212
|
-
}
|
|
213
|
-
if (self.systemTemperatureEnabled) {
|
|
214
|
-
NSString *value = self.systemTemperatureCelsius
|
|
215
|
-
? [NSString stringWithFormat:@"%.0f°C", self.systemTemperatureCelsius.doubleValue] : @"--°C";
|
|
216
|
-
double temperature = self.systemTemperatureCelsius.doubleValue;
|
|
217
|
-
NSColor *color = temperature >= 90 ? NSColor.systemRedColor :
|
|
218
|
-
(temperature >= 80 ? [NSColor colorWithRed:1.00 green:0.35 blue:0.16 alpha:1] :
|
|
219
|
-
[NSColor colorWithRed:1.00 green:107.0 / 255.0 blue:74.0 / 255.0 alpha:1]);
|
|
220
|
-
[metrics addObject:@{@"symbol": @"thermometer.medium", @"label": value,
|
|
221
|
-
@"color": color}];
|
|
222
|
-
}
|
|
223
|
-
if (self.systemMemoryEnabled) {
|
|
224
|
-
NSString *value = self.systemMemoryPercent
|
|
225
|
-
? [NSString stringWithFormat:@"%.0f%%", self.systemMemoryPercent.doubleValue] : @"--";
|
|
226
|
-
[metrics addObject:@{@"symbol": @"memorychip", @"label": [NSString stringWithFormat:@"MEM %@", value],
|
|
227
|
-
@"color": [NSColor colorWithRed:32.0 / 255.0 green:214.0 / 255.0
|
|
228
|
-
blue:165.0 / 255.0 alpha:1]}];
|
|
229
|
-
}
|
|
230
|
-
NSFont *font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
|
|
231
|
-
NSMutableAttributedString *statusLine = [NSMutableAttributedString new];
|
|
232
|
-
for (NSUInteger index = 0; index < metrics.count; index++) {
|
|
233
|
-
NSDictionary *metric = metrics[index];
|
|
234
|
-
NSString *label = metric[@"label"];
|
|
235
|
-
NSColor *color = metric[@"color"];
|
|
236
|
-
NSDictionary *attributes = @{NSFontAttributeName: font,
|
|
237
|
-
NSForegroundColorAttributeName: [self textColor:color]};
|
|
238
|
-
NSImage *icon = [NSImage imageWithSystemSymbolName:metric[@"symbol"]
|
|
239
|
-
accessibilityDescription:label];
|
|
240
|
-
NSImageSymbolConfiguration *sizeConfiguration =
|
|
241
|
-
[NSImageSymbolConfiguration configurationWithPointSize:
|
|
242
|
-
[metric[@"symbol"] isEqualToString:@"thermometer.medium"] ? 16 : 14
|
|
243
|
-
weight:NSFontWeightSemibold];
|
|
244
|
-
NSImageSymbolConfiguration *colorConfiguration =
|
|
245
|
-
[NSImageSymbolConfiguration configurationWithHierarchicalColor:metric[@"color"]];
|
|
246
|
-
icon = [icon imageWithSymbolConfiguration:
|
|
247
|
-
[sizeConfiguration configurationByApplyingConfiguration:colorConfiguration]];
|
|
248
|
-
NSTextAttachment *attachment = [NSTextAttachment new];
|
|
249
|
-
attachment.image = icon;
|
|
250
|
-
CGFloat iconSize = [metric[@"symbol"] isEqualToString:@"thermometer.medium"] ? 18 : 16;
|
|
251
|
-
attachment.bounds = NSMakeRect(0, (font.capHeight - iconSize) / 2.0,
|
|
252
|
-
iconSize, iconSize);
|
|
253
|
-
[statusLine appendAttributedString:[NSAttributedString
|
|
254
|
-
attributedStringWithAttachment:attachment]];
|
|
255
|
-
[statusLine appendAttributedString:[[NSAttributedString alloc]
|
|
256
|
-
initWithString:@" " attributes:attributes]];
|
|
257
|
-
[statusLine appendAttributedString:[[NSAttributedString alloc]
|
|
258
|
-
initWithString:label attributes:attributes]];
|
|
259
|
-
if (index + 1 < metrics.count) {
|
|
260
|
-
NSDictionary *separatorAttributes = @{NSFontAttributeName:
|
|
261
|
-
[NSFont systemFontOfSize:12 weight:NSFontWeightRegular],
|
|
262
|
-
NSForegroundColorAttributeName: [NSColor colorWithWhite:0.42 alpha:0.7]};
|
|
263
|
-
[statusLine appendAttributedString:[[NSAttributedString alloc]
|
|
264
|
-
initWithString:@" │ " attributes:separatorAttributes]];
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
CGFloat width = ceil(statusLine.size.width);
|
|
268
|
-
[statusLine drawInRect:NSMakeRect(rightEdge - width, y, width + 1, 20)];
|
|
269
|
-
}
|
|
270
|
-
- (NSString *)formattedTokenSplitForUsage:(NSDictionary *)usage key:(NSString *)key
|
|
271
|
-
wantsOutput:(BOOL)wantsOutput {
|
|
272
|
-
return [self formattedTokenSplit:[self tokenTotals:usage key:key] ?: @{}
|
|
273
|
-
wantsOutput:wantsOutput];
|
|
274
|
-
}
|
|
275
|
-
- (NSNumber *)usedForQuota:(NSDictionary *)quota usedKey:(NSString *)usedKey {
|
|
276
|
-
NSNumber *used = [quota[usedKey] isKindOfClass:NSNumber.class] ? quota[usedKey] : nil;
|
|
277
|
-
return used ? @(fmax(0, fmin(100, used.doubleValue))) : nil;
|
|
278
|
-
}
|
|
279
|
-
- (NSString *)refreshAgeText {
|
|
280
|
-
if (self.lastUpdatedAt <= 0) return L(@"Waiting for data");
|
|
281
|
-
NSTimeInterval age = fmax(0, NSDate.date.timeIntervalSince1970 - self.lastUpdatedAt);
|
|
282
|
-
if (age < 5) return L(@"just now");
|
|
283
|
-
if (age < 60) return [NSString stringWithFormat:L(@"%.0fs ago"), age];
|
|
284
|
-
if (age < 3600) return [NSString stringWithFormat:L(@"%.0fm ago"), floor(age / 60)];
|
|
285
|
-
return [NSString stringWithFormat:L(@"%.0fh ago"), floor(age / 3600)];
|
|
286
|
-
}
|
|
287
|
-
// 原生玻璃下背景可以是任意壁纸,面板按 0.58 缩放后小字只有 6–7pt,细笔画很容易被
|
|
288
|
-
// 背后的纹理吃掉。所以 liquid 模式统一收紧文字:小字放大一点、加粗一级;灰字不低于
|
|
289
|
-
// 0.84;彩色字改成白字。
|
|
290
|
-
// 经典主题有深色实底托着,保持原样。
|
|
291
|
-
// 小字统一抬到逻辑 14(屏幕约 8.1pt),这是 440pt 宽面板在不改版式的前提下放得下的上限;
|
|
292
|
-
// 再往上要放大面板或删行。数字用等宽字形,跳动时不左右晃;汉字不受影响。
|
|
293
|
-
- (NSFont *)fontWithSize:(CGFloat)size weight:(NSFontWeight)weight {
|
|
294
|
-
if (!self.usesLiquidGlass) return [NSFont systemFontOfSize:size weight:weight];
|
|
295
|
-
if (size < 14) size = 14;
|
|
296
|
-
else if (size <= 16) size += 1;
|
|
297
|
-
if (weight < NSFontWeightMedium) weight = NSFontWeightMedium;
|
|
298
|
-
else if (weight < NSFontWeightSemibold) weight = NSFontWeightSemibold;
|
|
299
|
-
else if (weight < NSFontWeightBold) weight = NSFontWeightBold;
|
|
300
|
-
return [NSFont monospacedDigitSystemFontOfSize:size weight:weight];
|
|
301
|
-
}
|
|
302
|
-
// 局部衬底:只垫在卡片和汇总区下面,面板边缘和卡片间隙保持通透。衬底本身不能带
|
|
303
|
-
// 文字投影,否则卡片边缘会多一圈黑晕。
|
|
304
|
-
// 原生玻璃下在文字前画一个彩色小圆点,替代原来的彩色字;经典主题照旧画彩色字。
|
|
305
|
-
- (void)drawText:(NSString *)text inRect:(NSRect)rect size:(CGFloat)size
|
|
306
|
-
weight:(NSFontWeight)weight color:(NSColor *)color dotColor:(NSColor *)dotColor {
|
|
307
|
-
if (!self.usesLiquidGlass) {
|
|
308
|
-
NSMutableDictionary *attributes = [[self textAttributesWithSize:size color:color
|
|
309
|
-
weight:weight] mutableCopy];
|
|
310
|
-
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
311
|
-
style.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
312
|
-
attributes[NSParagraphStyleAttributeName] = style;
|
|
313
|
-
[text drawInRect:rect withAttributes:[self attributes:attributes fittingText:text
|
|
314
|
-
inWidth:NSWidth(rect)]];
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
NSMutableDictionary *attributes = [[self textAttributesWithSize:size color:color
|
|
318
|
-
weight:weight] mutableCopy];
|
|
319
|
-
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
320
|
-
style.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
321
|
-
attributes[NSParagraphStyleAttributeName] = style;
|
|
322
|
-
NSFont *font = attributes[NSFontAttributeName];
|
|
323
|
-
NSRect textRect = rect;
|
|
324
|
-
if (dotColor) {
|
|
325
|
-
CGFloat diameter = 9;
|
|
326
|
-
// drawInRect: 从矩形顶部开始排版,圆点对齐到首行小写字母的中线。
|
|
327
|
-
CGFloat baselineMid = NSMaxY(rect) - font.ascender + font.xHeight / 2.0;
|
|
328
|
-
[NSGraphicsContext saveGraphicsState];
|
|
329
|
-
[[NSShadow new] set];
|
|
330
|
-
[dotColor setFill];
|
|
331
|
-
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(NSMinX(rect), baselineMid - diameter / 2.0,
|
|
332
|
-
diameter, diameter)] fill];
|
|
333
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
334
|
-
textRect.origin.x += diameter + 6;
|
|
335
|
-
textRect.size.width -= diameter + 6;
|
|
336
|
-
}
|
|
337
|
-
[text drawInRect:textRect withAttributes:[self attributes:attributes fittingText:text
|
|
338
|
-
inWidth:NSWidth(textRect)]];
|
|
339
|
-
}
|
|
340
|
-
// 译文长短差得多,固定宽度的格子迟早有放不下的语言。放不下时先把字号往下收,最多收 2pt
|
|
341
|
-
// (liquid 下即从 14 收到 12)——比截成"…"好认;还放不下才交给截断。放得下就原样返回,
|
|
342
|
-
// 中文和多数英文不受影响。
|
|
343
|
-
- (NSDictionary *)attributes:(NSDictionary *)attributes fittingText:(NSString *)text
|
|
344
|
-
inWidth:(CGFloat)width {
|
|
345
|
-
NSFont *font = attributes[NSFontAttributeName];
|
|
346
|
-
if (!font || text.length == 0 || [text sizeWithAttributes:attributes].width <= width) {
|
|
347
|
-
return attributes;
|
|
348
|
-
}
|
|
349
|
-
NSMutableDictionary *fitted = [attributes mutableCopy];
|
|
350
|
-
for (CGFloat size = font.pointSize - 0.5; size >= font.pointSize - 2; size -= 0.5) {
|
|
351
|
-
fitted[NSFontAttributeName] = [NSFont fontWithDescriptor:font.fontDescriptor size:size];
|
|
352
|
-
if ([text sizeWithAttributes:fitted].width <= width) break;
|
|
353
|
-
}
|
|
354
|
-
return fitted;
|
|
355
|
-
}
|
|
356
|
-
// 风险提示只保留文字,和 Max / Now 使用同一条左边界。
|
|
357
|
-
- (void)drawTip:(NSString *)text inRect:(NSRect)rect color:(NSColor *)color {
|
|
358
|
-
if (text.length == 0) return;
|
|
359
|
-
[self drawText:text inRect:rect size:11 weight:NSFontWeightMedium color:color dotColor:nil];
|
|
360
|
-
}
|
|
361
|
-
- (void)fillLiquidScrim:(NSBezierPath *)path {
|
|
362
|
-
[NSGraphicsContext saveGraphicsState];
|
|
363
|
-
[[NSShadow new] set];
|
|
364
|
-
[[NSColor colorWithWhite:0 alpha:self.cardScrimAlpha] setFill];
|
|
365
|
-
[path fill];
|
|
366
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
367
|
-
}
|
|
368
|
-
- (NSColor *)textColor:(NSColor *)color {
|
|
369
|
-
if (!self.usesLiquidGlass) return color;
|
|
370
|
-
NSColor *rgb = [color colorUsingColorSpace:NSColorSpace.sRGBColorSpace];
|
|
371
|
-
if (!rgb) return color;
|
|
372
|
-
CGFloat r, g, b, a;
|
|
373
|
-
[rgb getRed:&r green:&g blue:&b alpha:&a];
|
|
374
|
-
CGFloat saturation = MAX(r, MAX(g, b)) - MIN(r, MIN(g, b));
|
|
375
|
-
if (saturation < 0.05) return [NSColor colorWithWhite:MAX(MAX(r, MAX(g, b)), 0.84) alpha:a];
|
|
376
|
-
// 彩色字在任意亮度的背景上对比都不稳定,原生玻璃下文字一律用白色;颜色的语义改由
|
|
377
|
-
// 字前的小圆点、图标和曲线承担(见 drawText:inRect:size:weight:color:dotColor:)。
|
|
378
|
-
return [NSColor colorWithWhite:0.96 alpha:a];
|
|
379
|
-
}
|
|
380
|
-
- (NSDictionary *)textAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
|
|
381
|
-
return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
|
|
382
|
-
NSForegroundColorAttributeName: [self textColor:color]};
|
|
383
|
-
}
|
|
384
|
-
- (NSDictionary *)rightAlignedTextAttributesWithSize:(CGFloat)size color:(NSColor *)color
|
|
385
|
-
weight:(NSFontWeight)weight {
|
|
386
|
-
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
387
|
-
style.alignment = NSTextAlignmentRight;
|
|
388
|
-
return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
|
|
389
|
-
NSForegroundColorAttributeName: [self textColor:color],
|
|
390
|
-
NSParagraphStyleAttributeName: style};
|
|
391
|
-
}
|
|
392
|
-
- (NSDictionary *)centeredTextAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
|
|
393
|
-
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
394
|
-
style.alignment = NSTextAlignmentCenter;
|
|
395
|
-
return @{NSFontAttributeName: [self fontWithSize:size weight:weight],
|
|
396
|
-
NSForegroundColorAttributeName: [self textColor:color],
|
|
397
|
-
NSParagraphStyleAttributeName: style};
|
|
398
|
-
}
|
|
399
|
-
- (void)fillRoundedRect:(NSRect)rect radius:(CGFloat)radius color:(NSColor *)color {
|
|
400
|
-
[color setFill];
|
|
401
|
-
[[NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius] fill];
|
|
402
|
-
}
|
|
403
|
-
- (NSArray<NSDictionary *> *)curvePointsFromHistory:(NSArray<NSDictionary *> *)history
|
|
404
|
-
currentUsed:(NSNumber *)currentUsed {
|
|
405
|
-
// 历史只能补充当前快照,不能替代当前快照。当前窗口还没有采集到额度时继续画旧历史,
|
|
406
|
-
// 会让“等待数据”的卡片同时出现一条悬在中间的曲线;此时只保留图表底部基线。
|
|
407
|
-
if (!currentUsed) return @[];
|
|
408
|
-
|
|
409
|
-
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
410
|
-
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
411
|
-
NSMutableArray<NSDictionary *> *points = [NSMutableArray array];
|
|
412
|
-
for (NSDictionary *sample in history) {
|
|
413
|
-
if (![sample isKindOfClass:NSDictionary.class]) continue;
|
|
414
|
-
NSNumber *timestamp = [sample[@"timestamp"] isKindOfClass:NSNumber.class]
|
|
415
|
-
? sample[@"timestamp"] : nil;
|
|
416
|
-
NSNumber *remaining = [sample[@"remaining"] isKindOfClass:NSNumber.class]
|
|
417
|
-
? sample[@"remaining"] : nil;
|
|
418
|
-
if (!timestamp || !remaining || timestamp.doubleValue < cutoff) continue;
|
|
419
|
-
double used = 100.0 - fmax(0, fmin(100, remaining.doubleValue));
|
|
420
|
-
[points addObject:@{@"timestamp": timestamp, @"used": @(used)}];
|
|
421
|
-
}
|
|
422
|
-
// 终点必须和卡片上的当前官方额度同源;历史落盘最多会慢 15 分钟,不能直接拿它
|
|
423
|
-
// 冒充“当前”,否则同一张卡里会出现两个不同百分比。
|
|
424
|
-
[points addObject:@{@"timestamp": @(now), @"used": currentUsed}];
|
|
425
|
-
return points;
|
|
426
|
-
}
|
|
427
|
-
- (void)appendCurveFromPoint:(NSPoint)from toPoint:(NSPoint)to path:(NSBezierPath *)path {
|
|
428
|
-
CGFloat controlOffset = (to.x - from.x) / 3.0;
|
|
429
|
-
[path curveToPoint:to
|
|
430
|
-
controlPoint1:NSMakePoint(from.x + controlOffset, from.y)
|
|
431
|
-
controlPoint2:NSMakePoint(to.x - controlOffset, to.y)];
|
|
432
|
-
}
|
|
433
|
-
- (void)drawCurveSegment:(NSArray<NSValue *> *)segment inRect:(NSRect)rect color:(NSColor *)color {
|
|
434
|
-
if (segment.count == 0) return;
|
|
435
|
-
NSBezierPath *line = [NSBezierPath bezierPath];
|
|
436
|
-
NSPoint first = segment.firstObject.pointValue;
|
|
437
|
-
[line moveToPoint:first];
|
|
438
|
-
NSPoint previous = first;
|
|
439
|
-
for (NSUInteger index = 1; index < segment.count; index++) {
|
|
440
|
-
NSPoint point = segment[index].pointValue;
|
|
441
|
-
[self appendCurveFromPoint:previous toPoint:point path:line];
|
|
442
|
-
previous = point;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
NSBezierPath *fill = [line copy];
|
|
446
|
-
[fill lineToPoint:NSMakePoint(previous.x, NSMinY(rect))];
|
|
447
|
-
[fill lineToPoint:NSMakePoint(first.x, NSMinY(rect))];
|
|
448
|
-
[fill closePath];
|
|
449
|
-
[NSGraphicsContext saveGraphicsState];
|
|
450
|
-
[fill addClip];
|
|
451
|
-
NSGradient *area = [[NSGradient alloc]
|
|
452
|
-
initWithStartingColor:[color colorWithAlphaComponent:0.34]
|
|
453
|
-
endingColor:[color colorWithAlphaComponent:0.025]];
|
|
454
|
-
[area drawFromPoint:NSMakePoint(NSMidX(rect), NSMaxY(rect))
|
|
455
|
-
toPoint:NSMakePoint(NSMidX(rect), NSMinY(rect)) options:0];
|
|
456
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
457
|
-
|
|
458
|
-
[[color colorWithAlphaComponent:0.95] setStroke];
|
|
459
|
-
line.lineWidth = 2;
|
|
460
|
-
[line stroke];
|
|
461
|
-
}
|
|
462
|
-
- (void)drawUsageCurve:(NSArray<NSDictionary *> *)points inRect:(NSRect)rect
|
|
463
|
-
color:(NSColor *)color {
|
|
464
|
-
[[NSColor colorWithWhite:1 alpha:0.08] setStroke];
|
|
465
|
-
[NSBezierPath strokeLineFromPoint:NSMakePoint(NSMinX(rect), NSMinY(rect))
|
|
466
|
-
toPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect))];
|
|
467
|
-
if (points.count == 0) return;
|
|
468
|
-
|
|
469
|
-
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
470
|
-
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
471
|
-
// 曲线始终连成一段:采样缺口只代表桌宠当时没在运行,不代表没有消耗,
|
|
472
|
-
// 缺口两端直接插值比断开更接近真实轨迹;窗口重置带来的回落本身也是真实变化。
|
|
473
|
-
NSMutableArray<NSValue *> *allPoints = [NSMutableArray arrayWithCapacity:points.count];
|
|
474
|
-
for (NSDictionary *sample in points) {
|
|
475
|
-
NSTimeInterval timestamp = [sample[@"timestamp"] doubleValue];
|
|
476
|
-
double used = fmax(0, fmin(100, [sample[@"used"] doubleValue]));
|
|
477
|
-
CGFloat x = NSMinX(rect) + NSWidth(rect) * (timestamp - cutoff) / (now - cutoff);
|
|
478
|
-
CGFloat y = NSMinY(rect) + NSHeight(rect) * used / 100.0;
|
|
479
|
-
[allPoints addObject:[NSValue valueWithPoint:NSMakePoint(
|
|
480
|
-
fmax(NSMinX(rect), fmin(NSMaxX(rect), x)), y)]];
|
|
481
|
-
}
|
|
482
|
-
[self drawCurveSegment:allPoints inRect:rect color:color];
|
|
483
|
-
}
|
|
484
|
-
- (void)drawMonthlyTokenCurve:(NSArray<NSDictionary *> *)series inRect:(NSRect)rect
|
|
485
|
-
color:(NSColor *)color {
|
|
486
|
-
[[NSColor colorWithWhite:1 alpha:0.08] setStroke];
|
|
487
|
-
[NSBezierPath strokeLineFromPoint:NSMakePoint(NSMinX(rect), NSMinY(rect))
|
|
488
|
-
toPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect))];
|
|
489
|
-
if (series.count == 0) return;
|
|
490
|
-
// 横轴铺满整个自然月,曲线只画到今天:把月末还没到的日子当成 0 画出去,看起来会像
|
|
491
|
-
// 用量突然归零。留白本身就是"这个月还剩多少天"的刻度。
|
|
492
|
-
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
493
|
-
double peak = 0;
|
|
494
|
-
NSUInteger elapsed = 0;
|
|
495
|
-
for (NSDictionary *day in series) {
|
|
496
|
-
if ([day[@"timestamp"] doubleValue] > now) break;
|
|
497
|
-
NSDictionary *totals = [day[@"totals"] isKindOfClass:NSDictionary.class]
|
|
498
|
-
? day[@"totals"] : nil;
|
|
499
|
-
peak = fmax(peak, [totals[@"total_tokens"] doubleValue]);
|
|
500
|
-
elapsed += 1;
|
|
501
|
-
}
|
|
502
|
-
if (peak <= 0 || elapsed == 0) return;
|
|
503
|
-
NSMutableArray<NSValue *> *points = [NSMutableArray arrayWithCapacity:elapsed];
|
|
504
|
-
for (NSUInteger index = 0; index < elapsed; index++) {
|
|
505
|
-
NSDictionary *totals = [series[index][@"totals"] isKindOfClass:NSDictionary.class]
|
|
506
|
-
? series[index][@"totals"] : nil;
|
|
507
|
-
double value = [totals[@"total_tokens"] doubleValue];
|
|
508
|
-
CGFloat progress = series.count > 1 ? (CGFloat)index / (series.count - 1) : 1;
|
|
509
|
-
[points addObject:[NSValue valueWithPoint:NSMakePoint(
|
|
510
|
-
NSMinX(rect) + NSWidth(rect) * progress,
|
|
511
|
-
NSMinY(rect) + NSHeight(rect) * value / peak)]];
|
|
512
|
-
}
|
|
513
|
-
[self drawCurveSegment:points inRect:rect color:color];
|
|
514
|
-
}
|
|
515
|
-
- (NSDictionary *)paceStatusForQuota:(NSDictionary *)quota currentUsed:(NSNumber *)currentUsed
|
|
516
|
-
color:(NSColor *)providerColor {
|
|
517
|
-
if (!currentUsed) {
|
|
518
|
-
return @{@"label": L(@"Not enough data"), @"tip": L(@"Waiting for data"),
|
|
519
|
-
@"color": self.secondaryColor};
|
|
520
|
-
}
|
|
521
|
-
NSNumber *reset = [quota[@"resets_at"] isKindOfClass:NSNumber.class]
|
|
522
|
-
? quota[@"resets_at"] : nil;
|
|
523
|
-
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
524
|
-
const NSTimeInterval sevenDaySeconds = 7 * 24 * 60 * 60;
|
|
525
|
-
NSTimeInterval start = reset ? reset.doubleValue - sevenDaySeconds : 0;
|
|
526
|
-
NSTimeInterval elapsed = now - start;
|
|
527
|
-
double projectedRemaining = NAN;
|
|
528
|
-
const NSTimeInterval paceObservationSeconds = 24 * 60 * 60;
|
|
529
|
-
// 满 24 小时就全额外推的话,放大倍数还有 7 倍:窗口第 25 小时,任何已用超过 14.3%
|
|
530
|
-
// 的用户都会被判成"重置前用尽"。更糟的是两家的窗口起点差几个小时,就会出现一家
|
|
531
|
-
// 已外推、另一家还没到门槛的断层——剩 80% 的报高风险,剩 61% 的却显示平稳。
|
|
532
|
-
// 因此在 24 小时到窗口 1/3(56 小时)之间按观测时长加权,从"按当前已用"平滑过渡
|
|
533
|
-
// 到"完全信任外推",门槛处不再有跳变。
|
|
534
|
-
const NSTimeInterval paceFullTrustSeconds = sevenDaySeconds / 3.0;
|
|
535
|
-
if (reset && reset.doubleValue > now && elapsed >= paceObservationSeconds) {
|
|
536
|
-
double linearUsed = currentUsed.doubleValue * sevenDaySeconds / elapsed;
|
|
537
|
-
double confidence = fmin(1.0, (elapsed - paceObservationSeconds) /
|
|
538
|
-
(paceFullTrustSeconds - paceObservationSeconds));
|
|
539
|
-
double projectedUsed = currentUsed.doubleValue +
|
|
540
|
-
(linearUsed - currentUsed.doubleValue) * confidence;
|
|
541
|
-
projectedRemaining = 100.0 - projectedUsed;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// 四个档位从轻到重排成阶梯,后面的仲裁只在这上面挪档位,不再各写一套 label/tip/color。
|
|
545
|
-
double remaining = 100.0 - currentUsed.doubleValue;
|
|
546
|
-
NSArray<NSArray *> *ladder = @[
|
|
547
|
-
@[L(@"Plenty"), CCPetsLanguageIsSource() ? @"" : L(@"Plenty of quota left"), NSColor.systemGreenColor],
|
|
548
|
-
@[L(@"Steady"), CCPetsLanguageIsSource() ? @"" : L(@"Quota is holding steady"), providerColor],
|
|
549
|
-
@[L(@"Watch"), L(@"Watch usage"), NSColor.systemOrangeColor],
|
|
550
|
-
@[L(@"At risk"), L(@"Quota low"), NSColor.systemRedColor]
|
|
551
|
-
];
|
|
552
|
-
NSUInteger baseRank = remaining >= 70 ? 0
|
|
553
|
-
: (remaining >= 40 ? 1 : (remaining >= 15 ? 2 : 3));
|
|
554
|
-
|
|
555
|
-
// 当前窗口开始满 24 小时后才按消耗节奏预测;此前 projectedRemaining 是 NAN,只看事实。
|
|
556
|
-
NSInteger projectedRank = -1;
|
|
557
|
-
NSString *projectedTip = nil;
|
|
558
|
-
if (!isnan(projectedRemaining)) {
|
|
559
|
-
if (remaining <= 5 || projectedRemaining < 0) {
|
|
560
|
-
projectedRank = 3;
|
|
561
|
-
projectedTip = L(@"Runs out early");
|
|
562
|
-
} else if (projectedRemaining < 10) {
|
|
563
|
-
projectedRank = 2;
|
|
564
|
-
projectedTip = L(@"Ease off a bit");
|
|
565
|
-
} else if (projectedRemaining >= 30) {
|
|
566
|
-
projectedRank = 0;
|
|
567
|
-
projectedTip = L(@"Plenty to spare");
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// 仲裁:有预测就以预测为准,但事实划两条不可逾越的线。预测是关于未来的猜测,
|
|
572
|
-
// 剩余额度是此刻的事实;让猜测把事实盖掉,两个方向都会出错——
|
|
573
|
-
// 剩 80% 被外推成"高风险"是虚惊,剩 10% 被外推成"需关注"是漏报,后者更危险。
|
|
574
|
-
NSUInteger rank = projectedRank >= 0 ? (NSUInteger)projectedRank : baseRank;
|
|
575
|
-
BOOL demotedByFact = NO;
|
|
576
|
-
if (remaining < 15) rank = 3; // 只剩一成,再乐观的预测也压不下来
|
|
577
|
-
else if (remaining < 40 && rank < 1) rank = 1; // 不到四成就别标"充足"
|
|
578
|
-
if (remaining >= 70 && rank > 2) { // 还有七成,再难看的预测也不报"高风险"
|
|
579
|
-
rank = 2;
|
|
580
|
-
demotedByFact = YES;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
NSString *label = ladder[rank][0];
|
|
584
|
-
NSString *tip = ladder[rank][1];
|
|
585
|
-
if (demotedByFact) tip = L(@"Burning fast");
|
|
586
|
-
else if (projectedRank >= 0 && rank == (NSUInteger)projectedRank) tip = projectedTip;
|
|
587
|
-
return @{@"label": label, @"tip": tip, @"color": ladder[rank][2]};
|
|
588
|
-
}
|
|
589
|
-
- (void)drawProvider:(NSString *)name usage:(NSDictionary *)usage usedKey:(NSString *)usedKey
|
|
590
|
-
color:(NSColor *)color cardRect:(NSRect)card {
|
|
591
|
-
NSColor *primary = self.primaryColor;
|
|
592
|
-
NSColor *secondary = self.secondaryColor;
|
|
593
|
-
NSDictionary *five = [self quota:usage key:@"fiveHour"];
|
|
594
|
-
NSDictionary *week = [self quota:usage key:@"week"];
|
|
595
|
-
NSDictionary *fiveTokens = [self tokenTotals:usage key:@"fiveHour"];
|
|
596
|
-
NSDictionary *weekTokens = [self tokenTotals:usage key:@"week"];
|
|
597
|
-
NSDictionary *monthTokens = [self tokenTotals:usage key:@"month"];
|
|
598
|
-
// 同比两侧都只数到最后一个完整自然日(见 CalendarMonthWindows),因此不能拿含今天的
|
|
599
|
-
// monthTokens 去比不含同日的上月——那样每天都会凭空多出小半天的增量。
|
|
600
|
-
NSDictionary *monthComparable = [self tokenTotals:usage key:@"monthComparable"];
|
|
601
|
-
NSDictionary *previousMonthTokens = [self tokenTotals:usage key:@"previousMonthToDate"];
|
|
602
|
-
NSDictionary *tokenUsage = [usage[@"tokenUsage"] isKindOfClass:NSDictionary.class]
|
|
603
|
-
? usage[@"tokenUsage"] : nil;
|
|
604
|
-
NSArray<NSDictionary *> *monthDaily = [tokenUsage[@"monthDaily"] isKindOfClass:NSArray.class]
|
|
605
|
-
? tokenUsage[@"monthDaily"] : @[];
|
|
606
|
-
BOOL apiMode = [name isEqualToString:@"Codex"]
|
|
607
|
-
? self.codexShowsAPIUsage : self.claudeShowsAPIUsage;
|
|
608
|
-
NSNumber *fiveUsed = [self usedForQuota:five usedKey:usedKey];
|
|
609
|
-
NSNumber *weekUsed = [self usedForQuota:week usedKey:usedKey];
|
|
610
|
-
// usage_limit_exceeded 只能说明某次请求被额度限制,不能说明耗尽的是 5 小时还是
|
|
611
|
-
// 7 天窗口;切到 credits 后请求还能继续成功,但 rate_limits 可能一直为空。因此把它
|
|
612
|
-
// 作为独立的“额度受限”状态,不再拿一个无窗口归属的事件覆盖两个官方百分比。
|
|
613
|
-
BOOL exhausted = [usage[@"exhaustedAt"] isKindOfClass:NSNumber.class];
|
|
614
|
-
BOOL hasData = apiMode ? (monthTokens != nil)
|
|
615
|
-
: (fiveUsed || weekUsed || fiveTokens || weekTokens || exhausted);
|
|
616
|
-
BOOL online = [self isProviderOnline:name];
|
|
617
|
-
|
|
618
|
-
NSBezierPath *cardPath = [NSBezierPath bezierPathWithRoundedRect:card xRadius:18 yRadius:18];
|
|
619
|
-
// 经典主题的浅色渐变放到玻璃上会变成磨砂;原生玻璃下改垫一层深色衬底托住文字。
|
|
620
|
-
if (self.usesLiquidGlass) {
|
|
621
|
-
[self fillLiquidScrim:cardPath];
|
|
622
|
-
} else {
|
|
623
|
-
NSGradient *cardGlass = [[NSGradient alloc]
|
|
624
|
-
initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.085]
|
|
625
|
-
endingColor:[color colorWithAlphaComponent:0.025]];
|
|
626
|
-
[cardGlass drawInBezierPath:cardPath angle:-25];
|
|
627
|
-
}
|
|
628
|
-
[[NSColor colorWithWhite:1 alpha:self.usesLiquidGlass ? 0.10 : 0.18] setStroke];
|
|
629
|
-
cardPath.lineWidth = 1;
|
|
630
|
-
[cardPath stroke];
|
|
631
|
-
|
|
632
|
-
NSArray<NSNumber *> *separators = @[@(NSMinX(card) + 190), @(NSMinX(card) + 370),
|
|
633
|
-
@(NSMinX(card) + 540)];
|
|
634
|
-
[[NSColor colorWithWhite:1 alpha:0.10] setStroke];
|
|
635
|
-
for (NSNumber *value in separators) {
|
|
636
|
-
[NSBezierPath strokeLineFromPoint:NSMakePoint(value.doubleValue, NSMinY(card) + 14)
|
|
637
|
-
toPoint:NSMakePoint(value.doubleValue, NSMaxY(card) - 14)];
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
NSRect icon = NSMakeRect(NSMinX(card) + 28, NSMinY(card) + 53, 54, 54);
|
|
641
|
-
NSImage *logo = [name isEqualToString:@"Codex"] ? self.codexLogo : self.claudeLogo;
|
|
642
|
-
if (logo) {
|
|
643
|
-
[NSGraphicsContext saveGraphicsState];
|
|
644
|
-
[[NSBezierPath bezierPathWithRoundedRect:icon xRadius:14 yRadius:14] addClip];
|
|
645
|
-
[logo drawInRect:icon fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
|
646
|
-
respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}];
|
|
647
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
648
|
-
} else {
|
|
649
|
-
[self fillRoundedRect:icon radius:14 color:[color colorWithAlphaComponent:0.7]];
|
|
650
|
-
[name drawInRect:NSInsetRect(icon, 4, 17)
|
|
651
|
-
withAttributes:[self centeredTextAttributesWithSize:13 color:NSColor.whiteColor weight:NSFontWeightBold]];
|
|
652
|
-
}
|
|
653
|
-
[name drawInRect:NSMakeRect(NSMinX(card) + 94, NSMinY(card) + 84, 88, 30)
|
|
654
|
-
withAttributes:[self textAttributesWithSize:22 color:primary weight:NSFontWeightBold]];
|
|
655
|
-
// 四态:额度被拒 → 额度受限(百分比仍是上次官方快照);没有任何额度数据 → 等待数据;
|
|
656
|
-
// 有数据但客户端已退出 → 离线;两者都有 → 在线。
|
|
657
|
-
NSString *statusText = (!apiMode && exhausted) ? L(@"Rate limited")
|
|
658
|
-
: (!hasData ? L(@"Waiting for data") : (online ? L(@"● Online") : L(@"Offline")));
|
|
659
|
-
NSColor *statusColor = (!apiMode && exhausted) ? NSColor.systemOrangeColor
|
|
660
|
-
: (online && hasData ? NSColor.systemGreenColor : secondary);
|
|
661
|
-
if (self.usesLiquidGlass) {
|
|
662
|
-
// 原生玻璃下不画彩色底标签,状态色交给字前的圆点;文字里自带的"●"去掉,免得两个点。
|
|
663
|
-
NSString *plain = [statusText stringByReplacingOccurrencesOfString:@"● " withString:@""];
|
|
664
|
-
[self drawText:plain inRect:NSMakeRect(NSMinX(card) + 96, NSMinY(card) + 57, 120, 20)
|
|
665
|
-
size:11 weight:NSFontWeightMedium color:statusColor dotColor:statusColor];
|
|
666
|
-
} else {
|
|
667
|
-
NSDictionary *statusAttributes = [self textAttributesWithSize:11 color:statusColor
|
|
668
|
-
weight:NSFontWeightMedium];
|
|
669
|
-
CGFloat statusWidth = ceil([statusText sizeWithAttributes:statusAttributes].width) + 18;
|
|
670
|
-
NSRect status = NSMakeRect(NSMinX(card) + 94, NSMinY(card) + 55, statusWidth, 24);
|
|
671
|
-
[self fillRoundedRect:status radius:12 color:[statusColor colorWithAlphaComponent:0.13]];
|
|
672
|
-
[statusText drawInRect:NSInsetRect(status, 9, 4) withAttributes:statusAttributes];
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
if (apiMode) {
|
|
676
|
-
CGFloat callX = NSMinX(card) + 214;
|
|
677
|
-
CGFloat tokenX = NSMinX(card) + 394;
|
|
678
|
-
[L(@"Calls this month") drawInRect:NSMakeRect(callX, NSMinY(card) + 114, 130, 20)
|
|
679
|
-
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
680
|
-
[L(@"Tokens this month") drawInRect:NSMakeRect(tokenX, NSMinY(card) + 114, 130, 20)
|
|
681
|
-
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
682
|
-
|
|
683
|
-
NSString *requests = [NSString stringWithFormat:L(@"%@ calls"),
|
|
684
|
-
[self formattedRequestCount:monthTokens ?: @{}]];
|
|
685
|
-
[requests drawInRect:NSMakeRect(callX, NSMinY(card) + 75, 150, 34)
|
|
686
|
-
withAttributes:[self textAttributesWithSize:24 color:primary weight:NSFontWeightBold]];
|
|
687
|
-
// 曲线铺满整个自然月,月末那些还没到的日子不能算进"已过天数",否则日均会被稀释。
|
|
688
|
-
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
689
|
-
NSUInteger recordedDays = 0;
|
|
690
|
-
for (NSDictionary *day in monthDaily) {
|
|
691
|
-
if ([day[@"timestamp"] doubleValue] <= now) recordedDays += 1;
|
|
692
|
-
}
|
|
693
|
-
NSUInteger elapsedDays = MAX((NSUInteger)1, recordedDays);
|
|
694
|
-
NSNumber *requestCount = [monthTokens[@"request_count"] isKindOfClass:NSNumber.class]
|
|
695
|
-
? monthTokens[@"request_count"] : nil;
|
|
696
|
-
NSString *average = requestCount
|
|
697
|
-
? [NSString stringWithFormat:L(@"%@/day avg"),
|
|
698
|
-
[NSNumberFormatter localizedStringFromNumber:
|
|
699
|
-
@(llround(requestCount.doubleValue / elapsedDays))
|
|
700
|
-
numberStyle:NSNumberFormatterDecimalStyle]]
|
|
701
|
-
: L(@"--/day avg");
|
|
702
|
-
[average drawInRect:NSMakeRect(callX, NSMinY(card) + 48, 150, 20)
|
|
703
|
-
withAttributes:[self textAttributesWithSize:12 color:secondary weight:NSFontWeightRegular]];
|
|
704
|
-
|
|
705
|
-
// 这里不再重复"本月消耗"的合计:输入与输出各自的量级才是按量计费时要看的东西,
|
|
706
|
-
// 合计随时可以由这两个数得到,而它原先占掉了最显眼的一行。
|
|
707
|
-
NSArray<NSDictionary *> *splits = @[
|
|
708
|
-
@{@"label": L(@"Input"), @"value": [self formattedTokenSplit:monthTokens ?: @{}
|
|
709
|
-
wantsOutput:NO], @"y": @(NSMinY(card) + 76)},
|
|
710
|
-
@{@"label": L(@"Output"), @"value": [self formattedTokenSplit:monthTokens ?: @{}
|
|
711
|
-
wantsOutput:YES], @"y": @(NSMinY(card) + 48)}
|
|
712
|
-
];
|
|
713
|
-
for (NSDictionary *split in splits) {
|
|
714
|
-
CGFloat y = [split[@"y"] doubleValue];
|
|
715
|
-
[split[@"label"] drawInRect:NSMakeRect(tokenX, y + 4, 28, 16)
|
|
716
|
-
withAttributes:[self textAttributesWithSize:11 color:secondary
|
|
717
|
-
weight:NSFontWeightRegular]];
|
|
718
|
-
[split[@"value"] drawInRect:NSMakeRect(tokenX + 32, y, 122, 26)
|
|
719
|
-
withAttributes:[self textAttributesWithSize:18 color:primary
|
|
720
|
-
weight:NSFontWeightBold]];
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
NSDictionary *requestComparison = [self comparisonForCurrent:
|
|
724
|
-
[monthComparable[@"request_count"] doubleValue]
|
|
725
|
-
previous:[previousMonthTokens[@"request_count"] doubleValue] color:color];
|
|
726
|
-
[self drawText:requestComparison[@"text"] inRect:NSMakeRect(callX, NSMinY(card) + 22, 158, 18)
|
|
727
|
-
size:11 weight:NSFontWeightMedium color:requestComparison[@"color"]
|
|
728
|
-
dotColor:requestComparison[@"color"]];
|
|
729
|
-
NSDictionary *tokenComparison = [self comparisonForCurrent:
|
|
730
|
-
[monthComparable[@"total_tokens"] doubleValue]
|
|
731
|
-
previous:[previousMonthTokens[@"total_tokens"] doubleValue] color:color];
|
|
732
|
-
[self drawText:tokenComparison[@"text"] inRect:NSMakeRect(tokenX, NSMinY(card) + 22, 158, 18)
|
|
733
|
-
size:11 weight:NSFontWeightMedium color:tokenComparison[@"color"]
|
|
734
|
-
dotColor:tokenComparison[@"color"]];
|
|
735
|
-
|
|
736
|
-
CGFloat trendX = NSMinX(card) + 564;
|
|
737
|
-
// 「按日 Token」跟在标题后面,与标题同一行:它是标题的限定语,单独占一行既浪费
|
|
738
|
-
// 竖向空间,也把曲线和脚注挤得没法与左边两列对齐。
|
|
739
|
-
[L(@"Month") drawInRect:NSMakeRect(trendX, NSMinY(card) + 114, 60, 20)
|
|
740
|
-
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
741
|
-
if (self.usesLiquidGlass) {
|
|
742
|
-
[self drawText:L(@"Daily tokens") inRect:NSMakeRect(trendX + 62, NSMinY(card) + 114, 96, 20)
|
|
743
|
-
size:11 weight:NSFontWeightSemibold color:color dotColor:color];
|
|
744
|
-
} else {
|
|
745
|
-
NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:color
|
|
746
|
-
weight:NSFontWeightSemibold];
|
|
747
|
-
NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, 76, 22);
|
|
748
|
-
[self fillRoundedRect:pill radius:11 color:[color colorWithAlphaComponent:0.14]];
|
|
749
|
-
[L(@"Daily tokens") drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
|
|
750
|
-
}
|
|
751
|
-
NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 62, 135, 38);
|
|
752
|
-
[self drawMonthlyTokenCurve:monthDaily inRect:curveRect color:color];
|
|
753
|
-
double peak = 0;
|
|
754
|
-
NSDictionary *todayTotals = nil;
|
|
755
|
-
for (NSDictionary *day in monthDaily) {
|
|
756
|
-
if ([day[@"timestamp"] doubleValue] > now) break;
|
|
757
|
-
NSDictionary *totals = [day[@"totals"] isKindOfClass:NSDictionary.class]
|
|
758
|
-
? day[@"totals"] : nil;
|
|
759
|
-
peak = fmax(peak, [totals[@"total_tokens"] doubleValue]);
|
|
760
|
-
todayTotals = totals;
|
|
761
|
-
}
|
|
762
|
-
NSString *peakText = recordedDays > 0
|
|
763
|
-
? [NSString stringWithFormat:L(@"Peak %@"), [self formattedTokenValue:peak]] : L(@"Peak --");
|
|
764
|
-
NSString *todayText = todayTotals
|
|
765
|
-
? [NSString stringWithFormat:L(@"Today %@"),
|
|
766
|
-
[self formattedTokenValue:[todayTotals[@"total_tokens"] doubleValue]]] : L(@"Today --");
|
|
767
|
-
[peakText drawInRect:NSMakeRect(trendX, NSMinY(card) + 42, 74, 16)
|
|
768
|
-
withAttributes:[self textAttributesWithSize:10 color:secondary weight:NSFontWeightRegular]];
|
|
769
|
-
[todayText drawInRect:NSMakeRect(trendX + 61, NSMinY(card) + 42, 74, 16)
|
|
770
|
-
withAttributes:[self rightAlignedTextAttributesWithSize:10 color:secondary
|
|
771
|
-
weight:NSFontWeightRegular]];
|
|
772
|
-
// 与左边两列的"较上月同期"同一条基线(+22),三列脚注才在一条水平线上。
|
|
773
|
-
[[NSString stringWithFormat:L(@"%lu / %lu days recorded"),
|
|
774
|
-
(unsigned long)recordedDays, (unsigned long)monthDaily.count]
|
|
775
|
-
drawInRect:NSMakeRect(trendX, NSMinY(card) + 22, 145, 18)
|
|
776
|
-
withAttributes:[self textAttributesWithSize:11 color:color weight:NSFontWeightMedium]];
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
// 层级:官方剩余额度是订阅限额的权威值,占主位;本机 Token 是参考量,降一级并用
|
|
781
|
-
// 强调色区分;重置时间最小。反过来会让最抢眼的数字恰好是最不该照着做决定的那个。
|
|
782
|
-
NSArray<NSDictionary *> *windows = @[
|
|
783
|
-
@{@"x": @(NSMinX(card) + 214), @"title": L(@"5h window"), @"quota": five ?: @{},
|
|
784
|
-
@"tokens": fiveTokens ?: @{}, @"used": fiveUsed ?: NSNull.null,
|
|
785
|
-
@"rolling": L(@"Waiting for refresh")},
|
|
786
|
-
@{@"x": @(NSMinX(card) + 394), @"title": L(@"7d window"), @"quota": week ?: @{},
|
|
787
|
-
@"tokens": weekTokens ?: @{}, @"used": weekUsed ?: NSNull.null,
|
|
788
|
-
@"rolling": L(@"Waiting for refresh")}
|
|
789
|
-
];
|
|
790
|
-
for (NSDictionary *window in windows) {
|
|
791
|
-
CGFloat x = [window[@"x"] doubleValue];
|
|
792
|
-
[window[@"title"] drawInRect:NSMakeRect(x, NSMinY(card) + 114, 130, 20)
|
|
793
|
-
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
794
|
-
NSNumber *used = [window[@"used"] isKindOfClass:NSNumber.class] ? window[@"used"] : nil;
|
|
795
|
-
double remaining = used ? 100.0 - used.doubleValue : 0;
|
|
796
|
-
NSString *official = used ? [NSString stringWithFormat:@"%.0f%%", remaining] : @"--";
|
|
797
|
-
// 百分比是"剩余"、Token 是"已用",方向相反。后缀直接贴在数字右侧、
|
|
798
|
-
// 前缀写进 Token 行,否则两个数字并排看会被当成同一口径。
|
|
799
|
-
NSDictionary *valueAttributes = [self textAttributesWithSize:25
|
|
800
|
-
color:exhausted ? NSColor.systemOrangeColor : primary
|
|
801
|
-
weight:NSFontWeightBold];
|
|
802
|
-
CGFloat valueWidth = ceil([official sizeWithAttributes:valueAttributes].width);
|
|
803
|
-
[official drawInRect:NSMakeRect(x, NSMinY(card) + 74, valueWidth + 4, 34)
|
|
804
|
-
withAttributes:valueAttributes];
|
|
805
|
-
// 没有数字可标时不给口径标签:"-- 剩余"看起来像一个真实的 0 值,而实际上是
|
|
806
|
-
// 官方快照待刷新。下方的状态文字会说明它为何不可用。
|
|
807
|
-
NSString *valueLabel = !used ? @"" : (exhausted ? L(@"Snapshot") : L(@"Left"));
|
|
808
|
-
if (valueLabel.length > 0) {
|
|
809
|
-
[valueLabel drawInRect:NSMakeRect(x + valueWidth + 7, NSMinY(card) + 78, 60, 20)
|
|
810
|
-
withAttributes:[self textAttributesWithSize:12 color:secondary
|
|
811
|
-
weight:NSFontWeightRegular]];
|
|
812
|
-
}
|
|
813
|
-
// 官方窗口拿不到时(账号没有这个窗口、或响应里没带),Token 走的是本机滚动窗口。
|
|
814
|
-
// 说清楚这一行的口径,比留一个 `--` 让人以为是渲染坏了要好。
|
|
815
|
-
NSString *resetValue = [self resetText:window[@"quota"]];
|
|
816
|
-
NSString *reset = [resetValue isEqualToString:@"--"]
|
|
817
|
-
? window[@"rolling"] : [NSString stringWithFormat:L(@"Resets %@"), resetValue];
|
|
818
|
-
[reset drawInRect:NSMakeRect(x, NSMinY(card) + 46, 150, 18)
|
|
819
|
-
withAttributes:[self textAttributesWithSize:11 color:secondary weight:NSFontWeightRegular]];
|
|
820
|
-
// 原生玻璃下字更大、前面还有圆点,这一栏放不下"Token"一词;脚注里已说明
|
|
821
|
-
// Token 即本机统计的已用量。
|
|
822
|
-
NSString *tokenText = [NSString stringWithFormat:
|
|
823
|
-
self.usesLiquidGlass ? L(@"Used %@") : L(@"Used tokens %@"),
|
|
824
|
-
[self formattedTokenCount:window[@"tokens"]]];
|
|
825
|
-
[self drawText:tokenText inRect:NSMakeRect(x, NSMinY(card) + 22, 150, 22) size:14
|
|
826
|
-
weight:NSFontWeightSemibold color:color dotColor:color];
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
CGFloat trendX = NSMinX(card) + 564;
|
|
830
|
-
// 与 API 卡同一套骨架:标题行带 pill、中间曲线、脚注和左边两列齐平。
|
|
831
|
-
[L(@"Trend") drawInRect:NSMakeRect(trendX, NSMinY(card) + 114, 60, 20)
|
|
832
|
-
withAttributes:[self textAttributesWithSize:13 color:secondary weight:NSFontWeightRegular]];
|
|
833
|
-
NSArray<NSDictionary *> *history = [name isEqualToString:@"Codex"]
|
|
834
|
-
? self.codexHistory : self.claudeHistory;
|
|
835
|
-
NSNumber *currentUsed = weekUsed;
|
|
836
|
-
NSArray<NSDictionary *> *points = [self curvePointsFromHistory:history currentUsed:currentUsed];
|
|
837
|
-
// 趋势这一列算的是 7 天窗口(currentUsed 取 weekUsed)。而 exhaustedAt 来自
|
|
838
|
-
// rateLimitReachedType,没有窗口归属,实际撞墙的通常是 5 小时窗口——拿它一票否决
|
|
839
|
-
// 整列,会出现左边 7 天窗口好好显示着 45% 剩余、右边却说"等待官方额度刷新"的自相
|
|
840
|
-
// 矛盾。所以只有 7 天窗口自己确实没有百分比时才退回"待刷新"。
|
|
841
|
-
BOOL weekUnknown = exhausted && currentUsed == nil;
|
|
842
|
-
NSDictionary *pace = weekUnknown
|
|
843
|
-
? @{ @"label": L(@"Stale"), @"tip": L(@"Awaiting refresh"),
|
|
844
|
-
@"color": NSColor.systemOrangeColor }
|
|
845
|
-
: [self paceStatusForQuota:week currentUsed:currentUsed color:color];
|
|
846
|
-
NSColor *paceColor = pace[@"color"];
|
|
847
|
-
// 档位讲的是 7 天趋势,脚注讲的是此刻为什么发不出请求:受限但 7 天窗口尚有余量时
|
|
848
|
-
// 两者都要说清,所以脚注单独取色,不跟着档位走。
|
|
849
|
-
NSString *paceTip = pace[@"tip"];
|
|
850
|
-
NSColor *tipColor = paceColor;
|
|
851
|
-
if (exhausted && !weekUnknown) {
|
|
852
|
-
paceTip = L(@"Limited until reset");
|
|
853
|
-
tipColor = NSColor.systemOrangeColor;
|
|
854
|
-
}
|
|
855
|
-
if (self.usesLiquidGlass) {
|
|
856
|
-
[self drawText:pace[@"label"] inRect:NSMakeRect(trendX + 62, NSMinY(card) + 114, 96, 20)
|
|
857
|
-
size:11 weight:NSFontWeightSemibold color:paceColor dotColor:paceColor];
|
|
858
|
-
} else {
|
|
859
|
-
NSDictionary *pillAttributes = [self textAttributesWithSize:11 color:paceColor
|
|
860
|
-
weight:NSFontWeightSemibold];
|
|
861
|
-
// 档位标签跟在标题后面。宽度仍按文字算:四个档位不一样长,最宽的"数据不足"到
|
|
862
|
-
// trendX + 131,列宽 145 放得下。
|
|
863
|
-
CGFloat pillWidth = ceil([pace[@"label"] sizeWithAttributes:pillAttributes].width) + 18;
|
|
864
|
-
NSRect pill = NSMakeRect(trendX + 59, NSMinY(card) + 113, pillWidth, 22);
|
|
865
|
-
[self fillRoundedRect:pill radius:11 color:[paceColor colorWithAlphaComponent:0.14]];
|
|
866
|
-
[pace[@"label"] drawInRect:NSInsetRect(pill, 9, 3) withAttributes:pillAttributes];
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
NSRect curveRect = NSMakeRect(trendX, NSMinY(card) + 62, 135, 38);
|
|
870
|
-
[self drawUsageCurve:points inRect:curveRect color:color];
|
|
871
|
-
double peak = 0;
|
|
872
|
-
for (NSDictionary *point in points) peak = fmax(peak, [point[@"used"] doubleValue]);
|
|
873
|
-
NSString *peakText = points.count > 0
|
|
874
|
-
? [NSString stringWithFormat:L(@"Max %.0f%%"), peak] : L(@"Max --");
|
|
875
|
-
NSString *currentText = currentUsed
|
|
876
|
-
? [NSString stringWithFormat:L(@"Now %.0f%%"), currentUsed.doubleValue] : L(@"Now --");
|
|
877
|
-
[peakText drawInRect:NSMakeRect(trendX, NSMinY(card) + 42 - 2 / QuotaScale, 72, 16)
|
|
878
|
-
withAttributes:[self textAttributesWithSize:10 color:secondary weight:NSFontWeightRegular]];
|
|
879
|
-
[currentText drawInRect:NSMakeRect(trendX + 66, NSMinY(card) + 42 - 2 / QuotaScale, 69, 16)
|
|
880
|
-
withAttributes:[self rightAlignedTextAttributesWithSize:10 color:secondary
|
|
881
|
-
weight:NSFontWeightRegular]];
|
|
882
|
-
// 与左边两列的"已用 Token"同一条基线(+22),也和 API 卡的脚注行对齐。
|
|
883
|
-
[self drawTip:paceTip inRect:NSMakeRect(trendX, NSMinY(card) + 22 - 2 / QuotaScale,
|
|
884
|
-
145, 18) color:tipColor];
|
|
885
|
-
}
|
|
886
|
-
- (void)drawRect:(NSRect)dirtyRect {
|
|
887
|
-
[NSGraphicsContext saveGraphicsState];
|
|
888
|
-
NSAffineTransform *scale = [NSAffineTransform transform];
|
|
889
|
-
[scale scaleBy:QuotaScale];
|
|
890
|
-
[scale concat];
|
|
891
|
-
NSArray<NSString *> *visibleProviders = [self visibleProviders];
|
|
892
|
-
const CGFloat height = [self logicalHeight];
|
|
893
|
-
NSRect logicalBounds = NSMakeRect(0, 0, QuotaLogicalWidth, height);
|
|
894
|
-
NSRect outer = NSInsetRect(logicalBounds, 1, 1);
|
|
895
|
-
NSBezierPath *background = [NSBezierPath bezierPathWithRoundedRect:outer xRadius:24 yRadius:24];
|
|
896
|
-
// 原生玻璃按 13pt 圆角裁切整个面板;底色也铺满到同一圆角,否则玻璃边缘和
|
|
897
|
-
// 底色之间会露出一圈细缝。
|
|
898
|
-
if (self.usesLiquidGlass) {
|
|
899
|
-
CGFloat radius = 13 / QuotaScale;
|
|
900
|
-
background = [NSBezierPath bezierPathWithRoundedRect:logicalBounds
|
|
901
|
-
xRadius:radius yRadius:radius];
|
|
902
|
-
}
|
|
903
|
-
// 原生玻璃不铺底色:任何一层深色都会把 Clear 玻璃压回磨砂感。
|
|
904
|
-
if (!self.usesLiquidGlass) {
|
|
905
|
-
NSGradient *gradient = [[NSGradient alloc]
|
|
906
|
-
initWithStartingColor:[NSColor colorWithRed:0.025 green:0.055 blue:0.095 alpha:0.88]
|
|
907
|
-
endingColor:[NSColor colorWithRed:0.07 green:0.12 blue:0.19 alpha:0.80]];
|
|
908
|
-
[gradient drawInBezierPath:background angle:-20];
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// 原生玻璃自己绘制高光和边缘,不叠加经典主题的模拟反光。
|
|
912
|
-
if (!self.usesLiquidGlass) {
|
|
913
|
-
[NSGraphicsContext saveGraphicsState];
|
|
914
|
-
[background addClip];
|
|
915
|
-
NSGradient *topGlow = [[NSGradient alloc]
|
|
916
|
-
initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.34]
|
|
917
|
-
endingColor:[NSColor colorWithWhite:1 alpha:0.0]];
|
|
918
|
-
// 两处光晕原本是按 H=590 定的绝对点。面板会变矮,改成跟着高度走:顶部光源始终悬在
|
|
919
|
-
// 面板上沿之外,冷色光晕落在内容区中段。
|
|
920
|
-
NSPoint topGlowCenter = NSMakePoint(700, height + 60);
|
|
921
|
-
[topGlow drawFromCenter:topGlowCenter radius:0
|
|
922
|
-
toCenter:topGlowCenter radius:250 options:0];
|
|
923
|
-
NSGradient *cyanGlow = [[NSGradient alloc]
|
|
924
|
-
initWithStartingColor:[NSColor colorWithRed:0.18 green:0.72 blue:1 alpha:0.11]
|
|
925
|
-
endingColor:[NSColor colorWithRed:0.18 green:0.88 blue:1 alpha:0.0]];
|
|
926
|
-
NSPoint cyanGlowCenter = NSMakePoint(660, height * 0.42);
|
|
927
|
-
[cyanGlow drawFromCenter:cyanGlowCenter radius:0
|
|
928
|
-
toCenter:cyanGlowCenter radius:260 options:0];
|
|
929
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
930
|
-
|
|
931
|
-
[[NSColor colorWithWhite:1 alpha:0.34] setStroke];
|
|
932
|
-
background.lineWidth = 1.5;
|
|
933
|
-
[background stroke];
|
|
934
|
-
NSBezierPath *innerGlassBorder = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(outer, 2, 2)
|
|
935
|
-
xRadius:22 yRadius:22];
|
|
936
|
-
[[NSColor colorWithRed:0.58 green:0.82 blue:1 alpha:0.22] setStroke];
|
|
937
|
-
innerGlassBorder.lineWidth = 0.8;
|
|
938
|
-
[innerGlassBorder stroke];
|
|
939
|
-
}
|
|
940
|
-
// 玻璃底下可能是任意亮度的壁纸,除了玻璃背后的压暗层,再给白字加一层很淡的投影托底。
|
|
941
|
-
if (self.usesLiquidGlass) {
|
|
942
|
-
NSShadow *legibility = [NSShadow new];
|
|
943
|
-
legibility.shadowColor = [NSColor colorWithWhite:0 alpha:0.4];
|
|
944
|
-
legibility.shadowBlurRadius = 2;
|
|
945
|
-
legibility.shadowOffset = NSMakeSize(0, -0.5);
|
|
946
|
-
[legibility set];
|
|
947
|
-
}
|
|
948
|
-
NSColor *primary = self.primaryColor;
|
|
949
|
-
NSColor *secondary = self.secondaryColor;
|
|
950
|
-
NSColor *cyan = self.accentColor;
|
|
951
|
-
NSColor *agentColor = self.agentStatusColor;
|
|
952
|
-
[@"Agent Usage" drawInRect:NSMakeRect(28, height - 65, 260, 42)
|
|
953
|
-
withAttributes:[self textAttributesWithSize:30 color:primary weight:NSFontWeightBold]];
|
|
954
|
-
NSDictionary *liveStatusAttributes = [self textAttributesWithSize:14 color:secondary
|
|
955
|
-
weight:NSFontWeightRegular];
|
|
956
|
-
NSString *liveStatusText = L(@"Live status");
|
|
957
|
-
[liveStatusText drawInRect:NSMakeRect(30, height - 94, self.usesLiquidGlass ? 142 : 130, 22)
|
|
958
|
-
withAttributes:liveStatusAttributes];
|
|
959
|
-
CGFloat agentIndicatorX = 30 + [liveStatusText sizeWithAttributes:liveStatusAttributes].width + 12;
|
|
960
|
-
[agentColor setFill];
|
|
961
|
-
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(agentIndicatorX, height - 88, 9, 9)] fill];
|
|
962
|
-
NSString *agentText = self.activeAgentCount > 0
|
|
963
|
-
? [NSString stringWithFormat:self.activeAgentCount != 1 ? L(@"%ld Agents online")
|
|
964
|
-
: L(@"%ld Agent online"), (long)self.activeAgentCount]
|
|
965
|
-
: L(@"No Agents online");
|
|
966
|
-
[agentText drawInRect:NSMakeRect(agentIndicatorX + 16, height - 95, 160, 22)
|
|
967
|
-
withAttributes:[self textAttributesWithSize:14 color:agentColor weight:NSFontWeightMedium]];
|
|
968
|
-
[self drawSystemMetricsEndingAtX:QuotaLogicalWidth - 28 y:height - 95];
|
|
969
|
-
|
|
970
|
-
// 用量由定时器自动刷新,面板不再提供手动刷新按钮;右上角只留上次刷新的时间,
|
|
971
|
-
// 与下一行的系统指标右边对齐。放回汇总条里会挤掉一整格 Provider 数据。
|
|
972
|
-
[[NSString stringWithFormat:L(@"Updated %@"), [self refreshAgeText]]
|
|
973
|
-
drawInRect:NSMakeRect(QuotaLogicalWidth - 28 - 200, height - 45, 200, 18)
|
|
974
|
-
withAttributes:[self rightAlignedTextAttributesWithSize:11 color:secondary
|
|
975
|
-
weight:NSFontWeightRegular]];
|
|
976
|
-
|
|
977
|
-
if (visibleProviders.count > 0) {
|
|
978
|
-
[self drawSummaryForProviders:visibleProviders primary:primary secondary:secondary
|
|
979
|
-
accent:cyan];
|
|
980
|
-
}
|
|
981
|
-
NSDictionary *cardSpecs = @{
|
|
982
|
-
@"Codex": @{@"usage": self.codexUsage ?: @{}, @"usedKey": @"used_percent",
|
|
983
|
-
@"color": cyan},
|
|
984
|
-
@"Claude": @{@"usage": self.claudeUsage ?: @{}, @"usedKey": @"used_percentage",
|
|
985
|
-
@"color": self.claudeColor}
|
|
986
|
-
};
|
|
987
|
-
// 卡片从汇总条下方依次向下排。少一家就少一张卡,脚注跟着上移;这里的分段账必须和
|
|
988
|
-
// QuotaLogicalHeightForProviderCount 完全一致,否则面板会多出或少掉一段空白。
|
|
989
|
-
CGFloat cardTop = height - QuotaHeaderHeight - QuotaSummaryHeight;
|
|
990
|
-
for (NSString *name in visibleProviders) {
|
|
991
|
-
NSDictionary *spec = cardSpecs[name];
|
|
992
|
-
cardTop -= QuotaBlockGap;
|
|
993
|
-
[self drawProvider:name usage:spec[@"usage"] usedKey:spec[@"usedKey"]
|
|
994
|
-
color:spec[@"color"]
|
|
995
|
-
cardRect:NSMakeRect(20, cardTop - QuotaCardHeight,
|
|
996
|
-
QuotaLogicalWidth - 40, QuotaCardHeight)];
|
|
997
|
-
cardTop -= QuotaCardHeight;
|
|
998
|
-
}
|
|
999
|
-
if (visibleProviders.count == 0) {
|
|
1000
|
-
// 精简态。说清楚是"没检测到 CLI",而不是让用户对着一片空白猜面板是不是坏了。
|
|
1001
|
-
// 两行说明刻意分开:卡片出现只取决于装没装 CLI,探测每 ClientLifecycleInterval
|
|
1002
|
-
// 跑一次,装完几秒内自己就冒出来,既不用重装也不用重启桌宠。而 cc-pets install
|
|
1003
|
-
// 解决的是另一件事——Agent 动画,以及 Claude 额度(statusline 是它唯一的来源)。
|
|
1004
|
-
// 把两者写成一句会让人以为不执行 install 卡片就不出现。
|
|
1005
|
-
CGFloat noticeTop = height - QuotaHeaderHeight;
|
|
1006
|
-
[L(@"No Codex / Claude Code CLI detected") drawInRect:NSMakeRect(28, noticeTop - 30, 460, 26)
|
|
1007
|
-
withAttributes:[self textAttributesWithSize:17 color:primary weight:NSFontWeightMedium]];
|
|
1008
|
-
[L(@"Quota cards appear once Codex or Claude Code is installed")
|
|
1009
|
-
drawInRect:NSMakeRect(28, noticeTop - 52, 560, 20)
|
|
1010
|
-
withAttributes:[self textAttributesWithSize:12 color:secondary weight:NSFontWeightRegular]];
|
|
1011
|
-
[L(@"Run cc-pets install again to enable Agent animations and Claude quota tracking")
|
|
1012
|
-
drawInRect:NSMakeRect(28, noticeTop - 72, 560, 18)
|
|
1013
|
-
withAttributes:[self textAttributesWithSize:11
|
|
1014
|
-
color:[NSColor colorWithWhite:0.52 alpha:1] weight:NSFontWeightRegular]];
|
|
1015
|
-
}
|
|
1016
|
-
BOOL hasAPICard = ([visibleProviders containsObject:@"Codex"] && self.codexShowsAPIUsage) ||
|
|
1017
|
-
([visibleProviders containsObject:@"Claude"] && self.claudeShowsAPIUsage);
|
|
1018
|
-
NSString *footer = visibleProviders.count == 0
|
|
1019
|
-
? L(@"ⓘ The pet and system status still work; quota cards only show for detected CLIs")
|
|
1020
|
-
: (hasAPICard
|
|
1021
|
-
? L(@"ⓘ API usage = local session stats (input includes cache reads/writes); compared with the same point last month")
|
|
1022
|
-
: (self.usesLiquidGlass || CCPetsLanguageIsSource()
|
|
1023
|
-
? L(@"ⓘ % = official quota left; tokens = local usage (incl. cache reads/writes)")
|
|
1024
|
-
: L(@"ⓘ % = share of official plan quota left; tokens = locally counted usage (input incl. cache reads/writes). They measure different things")));
|
|
1025
|
-
// 最后一块的底边距面板底 QuotaFooterHeight:脚注与其留约 8pt,底部留白 16pt,
|
|
1026
|
-
// 和顶部标题的留白大致对称。
|
|
1027
|
-
[footer drawInRect:NSMakeRect(28, 16, 650, 20)
|
|
1028
|
-
withAttributes:[self textAttributesWithSize:11
|
|
1029
|
-
color:self.usesLiquidGlass ? self.secondaryColor : [NSColor colorWithWhite:0.58 alpha:1]
|
|
1030
|
-
weight:NSFontWeightRegular]];
|
|
1031
|
-
[NSGraphicsContext restoreGraphicsState];
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// 今日与最近 7 天都按 Provider 分开展示。底层本来就是两套独立的自然日统计,
|
|
1035
|
-
// 不在展示层相加,避免用户无法判断 Token 来自 Codex 还是 Claude。
|
|
1036
|
-
// 每格内是一张 2×2 表:标题独占一行,每个 Provider 独占一行;输入/输出标签放在
|
|
1037
|
-
// 对应数值上方。这样既能完整展示 7 天统计起期,也不会挤乱两家的数据行。
|
|
1038
|
-
- (void)drawSummaryForProviders:(NSArray<NSString *> *)providers primary:(NSColor *)primary
|
|
1039
|
-
secondary:(NSColor *)secondary accent:(NSColor *)cyan {
|
|
1040
|
-
NSRect summary = [self logicalSummaryRect];
|
|
1041
|
-
NSBezierPath *summaryPath = [NSBezierPath bezierPathWithRoundedRect:summary xRadius:18 yRadius:18];
|
|
1042
|
-
if (self.usesLiquidGlass) {
|
|
1043
|
-
[self fillLiquidScrim:summaryPath];
|
|
1044
|
-
} else {
|
|
1045
|
-
[[NSColor colorWithWhite:1 alpha:0.065] setFill];
|
|
1046
|
-
[summaryPath fill];
|
|
1047
|
-
}
|
|
1048
|
-
[[NSColor colorWithWhite:1 alpha:self.usesLiquidGlass ? 0.10 : 0.16] setStroke];
|
|
1049
|
-
[summaryPath stroke];
|
|
1050
|
-
|
|
1051
|
-
NSArray<NSDictionary *> *cells = @[
|
|
1052
|
-
@{@"icon": @"◔", @"headerSymbol": @"calendar", @"key": @"today",
|
|
1053
|
-
@"label": L(@"Today")},
|
|
1054
|
-
@{@"icon": @"◉", @"headerSymbol": @"calendar.badge.clock", @"key": @"recentWeek",
|
|
1055
|
-
@"label": [self recentWeekUsageLabel]}
|
|
1056
|
-
];
|
|
1057
|
-
NSDictionary *rowSpecs = @{
|
|
1058
|
-
@"Codex": @{@"usage": self.codexUsage ?: @{}, @"color": cyan},
|
|
1059
|
-
@"Claude": @{@"usage": self.claudeUsage ?: @{},
|
|
1060
|
-
@"color": self.claudeColor}
|
|
1061
|
-
};
|
|
1062
|
-
// 两行版的槽位是写死的。只装了一家时改用居中的单行槽位,否则汇总条会空出半格,
|
|
1063
|
-
// 看着像数据没加载出来。
|
|
1064
|
-
NSArray<NSDictionary *> *slots = providers.count == 1
|
|
1065
|
-
? @[@{@"iconY": @24, @"nameY": @33, @"labelY": @49, @"valueY": @28}]
|
|
1066
|
-
: @[@{@"iconY": @43, @"nameY": @52, @"labelY": @68, @"valueY": @47},
|
|
1067
|
-
@{@"iconY": @5, @"nameY": @14, @"labelY": @30, @"valueY": @9}];
|
|
1068
|
-
NSMutableArray<NSDictionary *> *rows = [NSMutableArray array];
|
|
1069
|
-
for (NSUInteger index = 0; index < providers.count && index < slots.count; index++) {
|
|
1070
|
-
NSMutableDictionary *row = [slots[index] mutableCopy];
|
|
1071
|
-
[row addEntriesFromDictionary:rowSpecs[providers[index]]];
|
|
1072
|
-
row[@"name"] = providers[index];
|
|
1073
|
-
[rows addObject:row];
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
[[NSColor colorWithWhite:1 alpha:0.10] setStroke];
|
|
1077
|
-
for (NSUInteger index = 1; index < cells.count; index++) {
|
|
1078
|
-
CGFloat x = NSMinX([self logicalSummaryCellRectAtIndex:index]);
|
|
1079
|
-
[NSBezierPath strokeLineFromPoint:NSMakePoint(x, NSMinY(summary) + 16)
|
|
1080
|
-
toPoint:NSMakePoint(x, NSMaxY(summary) - 16)];
|
|
1081
|
-
}
|
|
1082
|
-
for (NSUInteger index = 0; index < cells.count; index++) {
|
|
1083
|
-
NSDictionary *cell = cells[index];
|
|
1084
|
-
NSString *key = cell[@"key"];
|
|
1085
|
-
CGFloat x = NSMinX([self logicalSummaryCellRectAtIndex:index]);
|
|
1086
|
-
const CGFloat inputX = x + 176;
|
|
1087
|
-
const CGFloat outputX = x + 276;
|
|
1088
|
-
NSFont *headerFont = [self fontWithSize:11 weight:NSFontWeightRegular];
|
|
1089
|
-
NSDictionary *headerAttributes = @{NSFontAttributeName: headerFont,
|
|
1090
|
-
NSForegroundColorAttributeName: [self textColor:secondary]};
|
|
1091
|
-
NSDictionary *titleAttributes = @{NSFontAttributeName:
|
|
1092
|
-
[self fontWithSize:11 weight:NSFontWeightBold],
|
|
1093
|
-
NSForegroundColorAttributeName: [self textColor:secondary]};
|
|
1094
|
-
NSImage *headerIcon = [NSImage imageWithSystemSymbolName:cell[@"headerSymbol"]
|
|
1095
|
-
accessibilityDescription:cell[@"label"]];
|
|
1096
|
-
NSImageSymbolConfiguration *headerIconConfiguration =
|
|
1097
|
-
[NSImageSymbolConfiguration configurationWithPointSize:11
|
|
1098
|
-
weight:NSFontWeightRegular];
|
|
1099
|
-
headerIconConfiguration = [headerIconConfiguration configurationByApplyingConfiguration:
|
|
1100
|
-
[NSImageSymbolConfiguration configurationWithHierarchicalColor:secondary]];
|
|
1101
|
-
headerIcon = [headerIcon imageWithSymbolConfiguration:headerIconConfiguration];
|
|
1102
|
-
NSTextAttachment *headerAttachment = [NSTextAttachment new];
|
|
1103
|
-
headerAttachment.image = headerIcon;
|
|
1104
|
-
const CGFloat headerIconSize = 13;
|
|
1105
|
-
headerAttachment.bounds = NSMakeRect(0,
|
|
1106
|
-
(headerFont.capHeight - headerIconSize) / 2.0, headerIconSize, headerIconSize);
|
|
1107
|
-
NSMutableAttributedString *header = [[NSMutableAttributedString alloc]
|
|
1108
|
-
initWithAttributedString:[NSAttributedString
|
|
1109
|
-
attributedStringWithAttachment:headerAttachment]];
|
|
1110
|
-
[header appendAttributedString:[[NSAttributedString alloc]
|
|
1111
|
-
initWithString:@" " attributes:headerAttributes]];
|
|
1112
|
-
[header appendAttributedString:[[NSAttributedString alloc]
|
|
1113
|
-
initWithString:cell[@"label"] attributes:titleAttributes]];
|
|
1114
|
-
[header drawInRect:NSMakeRect(x + 24, NSMinY(summary) + 89,
|
|
1115
|
-
NSWidth([self logicalSummaryCellRectAtIndex:index]) - 48, 18)];
|
|
1116
|
-
for (NSDictionary *row in rows) {
|
|
1117
|
-
NSDictionary *usage = row[@"usage"];
|
|
1118
|
-
NSColor *rowColor = row[@"color"];
|
|
1119
|
-
CGFloat iconY = NSMinY(summary) + [row[@"iconY"] doubleValue];
|
|
1120
|
-
CGFloat nameY = NSMinY(summary) + [row[@"nameY"] doubleValue];
|
|
1121
|
-
CGFloat labelY = NSMinY(summary) + [row[@"labelY"] doubleValue];
|
|
1122
|
-
if (CCPetsLanguageIsSource()) labelY += 2 / QuotaScale;
|
|
1123
|
-
CGFloat valueY = NSMinY(summary) + [row[@"valueY"] doubleValue];
|
|
1124
|
-
// 这是图标字形不是文字,原生玻璃下也保留颜色:它负责标出这一行是哪一家。
|
|
1125
|
-
[cell[@"icon"] drawInRect:NSMakeRect(x + 20, iconY, 42, 42)
|
|
1126
|
-
withAttributes:@{NSFontAttributeName: [NSFont systemFontOfSize:30
|
|
1127
|
-
weight:NSFontWeightRegular], NSForegroundColorAttributeName: rowColor}];
|
|
1128
|
-
[row[@"name"] drawInRect:NSMakeRect(x + 66, nameY, 76, 22)
|
|
1129
|
-
withAttributes:[self textAttributesWithSize:14 color:rowColor
|
|
1130
|
-
weight:NSFontWeightMedium]];
|
|
1131
|
-
[L(@"Input") drawInRect:NSMakeRect(inputX, labelY, 76, 16)
|
|
1132
|
-
withAttributes:headerAttributes];
|
|
1133
|
-
[L(@"Output") drawInRect:NSMakeRect(outputX, labelY, 76, 16)
|
|
1134
|
-
withAttributes:headerAttributes];
|
|
1135
|
-
NSDictionary *valueAttributes = [self textAttributesWithSize:16 color:primary
|
|
1136
|
-
weight:NSFontWeightBold];
|
|
1137
|
-
[[self formattedTokenSplitForUsage:usage key:key wantsOutput:NO]
|
|
1138
|
-
drawInRect:NSMakeRect(inputX, valueY, 86, 23) withAttributes:valueAttributes];
|
|
1139
|
-
[[self formattedTokenSplitForUsage:usage key:key wantsOutput:YES]
|
|
1140
|
-
drawInRect:NSMakeRect(outputX, valueY, 76, 23) withAttributes:valueAttributes];
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
}
|
|
1145
|
-
@end
|