cc-pets 1.0.1 → 1.0.4
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/CHANGELOG.md +5 -0
- package/README.md +12 -2
- package/Sources/CCPets/CCPetsAppDelegate.h +54 -0
- package/Sources/CCPets/CCPetsAppDelegate.m +1158 -0
- package/Sources/CCPets/CCPetsCleanup.h +7 -0
- package/Sources/CCPets/CCPetsCleanup.m +126 -0
- package/Sources/CCPets/CCPetsEvents.h +10 -0
- package/Sources/CCPets/CCPetsEvents.m +232 -0
- package/Sources/CCPets/CCPetsImageLoader.h +4 -0
- package/Sources/CCPets/CCPetsImageLoader.m +36 -0
- package/Sources/CCPets/CCPetsPaths.h +23 -0
- package/Sources/CCPets/CCPetsPaths.m +48 -0
- package/Sources/CCPets/CCPetsPreviews.h +6 -0
- package/Sources/CCPets/CCPetsPreviews.m +159 -0
- package/Sources/CCPets/CCPetsQuotaHistory.h +7 -0
- package/Sources/CCPets/CCPetsQuotaHistory.m +83 -0
- package/Sources/CCPets/CCPetsUsage.h +19 -0
- package/Sources/CCPets/CCPetsUsage.m +289 -0
- package/Sources/CCPets/CCPetsUsageMonitor.h +10 -0
- package/Sources/CCPets/CCPetsUsageMonitor.m +163 -0
- package/Sources/CCPets/CCPetsVersion.h +10 -0
- package/Sources/CCPets/CCPetsVersion.m +62 -0
- package/Sources/CCPets/MenuToggleSwitch.h +5 -0
- package/Sources/CCPets/MenuToggleSwitch.m +47 -0
- package/Sources/CCPets/PetView.h +35 -0
- package/Sources/CCPets/PetView.m +511 -0
- package/Sources/CCPets/QuotaDashboardView.h +23 -0
- package/Sources/CCPets/QuotaDashboardView.m +318 -0
- package/Sources/CCPets/main.m +11 -2528
- package/bin/cc-pets +5 -0
- package/bin/claude-with-pet +2 -1
- package/bin/codex-with-pet +3 -1
- package/package.json +2 -3
- package/scripts/build.sh +20 -1
- package/scripts/install-git-hooks.sh +47 -0
- package/scripts/uninstall-app.sh +9 -0
- package/scripts/uninstall-shell-integration.sh +50 -2
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
#import "QuotaDashboardView.h"
|
|
2
|
+
|
|
3
|
+
const CGFloat QuotaLogicalWidth = 600;
|
|
4
|
+
const CGFloat QuotaLogicalHeight = 360;
|
|
5
|
+
const CGFloat QuotaScale = 0.6;
|
|
6
|
+
|
|
7
|
+
NSImage *OfficialAppIcon(NSString *bundleIdentifier, NSString *resourceName) {
|
|
8
|
+
NSURL *appURL = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:bundleIdentifier];
|
|
9
|
+
NSMutableArray<NSString *> *paths = [NSMutableArray array];
|
|
10
|
+
if (appURL) {
|
|
11
|
+
NSBundle *bundle = [NSBundle bundleWithURL:appURL];
|
|
12
|
+
NSString *resourcePath = [bundle pathForResource:resourceName.stringByDeletingPathExtension
|
|
13
|
+
ofType:resourceName.pathExtension];
|
|
14
|
+
if (resourcePath.length > 0) [paths addObject:resourcePath];
|
|
15
|
+
}
|
|
16
|
+
NSString *applicationName = [bundleIdentifier containsString:@"anthropic"] ? @"Claude.app" : @"ChatGPT.app";
|
|
17
|
+
[paths addObject:[@"/Applications" stringByAppendingPathComponent:
|
|
18
|
+
[applicationName stringByAppendingPathComponent:[@"Contents/Resources" stringByAppendingPathComponent:resourceName]]]];
|
|
19
|
+
[paths addObject:[[NSHomeDirectory() stringByAppendingPathComponent:@"Applications"] stringByAppendingPathComponent:
|
|
20
|
+
[applicationName stringByAppendingPathComponent:[@"Contents/Resources" stringByAppendingPathComponent:resourceName]]]];
|
|
21
|
+
for (NSString *path in paths) {
|
|
22
|
+
NSImage *image = [[NSImage alloc] initWithContentsOfFile:path];
|
|
23
|
+
if (image) return image;
|
|
24
|
+
}
|
|
25
|
+
return appURL ? [NSWorkspace.sharedWorkspace iconForFile:appURL.path] : nil;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@implementation QuotaDashboardView
|
|
29
|
+
- (instancetype)initWithFrame:(NSRect)frame {
|
|
30
|
+
if ((self = [super initWithFrame:frame])) {
|
|
31
|
+
NSTrackingArea *tracking = [[NSTrackingArea alloc] initWithRect:NSZeroRect
|
|
32
|
+
options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
|
|
33
|
+
NSTrackingActiveAlways | NSTrackingInVisibleRect
|
|
34
|
+
owner:self userInfo:nil];
|
|
35
|
+
[self addTrackingArea:tracking];
|
|
36
|
+
}
|
|
37
|
+
return self;
|
|
38
|
+
}
|
|
39
|
+
- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
|
|
40
|
+
- (void)mouseEntered:(NSEvent *)event {
|
|
41
|
+
if (self.hoverChanged) self.hoverChanged(YES);
|
|
42
|
+
[self mouseMoved:event];
|
|
43
|
+
}
|
|
44
|
+
- (void)mouseExited:(NSEvent *)event {
|
|
45
|
+
self.refreshHovered = NO;
|
|
46
|
+
self.refreshPressed = NO;
|
|
47
|
+
[NSCursor.arrowCursor set];
|
|
48
|
+
self.needsDisplay = YES;
|
|
49
|
+
if (self.hoverChanged) self.hoverChanged(NO);
|
|
50
|
+
}
|
|
51
|
+
- (NSRect)logicalRefreshRect { return NSMakeRect(QuotaLogicalWidth - 54, QuotaLogicalHeight - 52, 34, 32); }
|
|
52
|
+
- (NSRect)refreshRect {
|
|
53
|
+
NSRect logical = [self logicalRefreshRect];
|
|
54
|
+
return NSMakeRect(logical.origin.x * QuotaScale, logical.origin.y * QuotaScale,
|
|
55
|
+
logical.size.width * QuotaScale, logical.size.height * QuotaScale);
|
|
56
|
+
}
|
|
57
|
+
- (void)mouseMoved:(NSEvent *)event {
|
|
58
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
59
|
+
BOOL hovering = NSPointInRect(point, [self refreshRect]);
|
|
60
|
+
if (hovering != self.refreshHovered) {
|
|
61
|
+
self.refreshHovered = hovering;
|
|
62
|
+
self.needsDisplay = YES;
|
|
63
|
+
}
|
|
64
|
+
if (hovering) [NSCursor.pointingHandCursor set];
|
|
65
|
+
else [NSCursor.arrowCursor set];
|
|
66
|
+
}
|
|
67
|
+
- (void)mouseDown:(NSEvent *)event {
|
|
68
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
69
|
+
if (NSPointInRect(point, [self refreshRect])) {
|
|
70
|
+
self.refreshPressed = YES;
|
|
71
|
+
self.needsDisplay = YES;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
- (void)mouseUp:(NSEvent *)event {
|
|
75
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
76
|
+
BOOL shouldRefresh = self.refreshPressed && NSPointInRect(point, [self refreshRect]);
|
|
77
|
+
self.refreshPressed = NO;
|
|
78
|
+
if (shouldRefresh) {
|
|
79
|
+
if (self.refreshRequested) self.refreshRequested();
|
|
80
|
+
self.refreshedUntil = NSDate.date.timeIntervalSince1970 + 1.2;
|
|
81
|
+
[[NSHapticFeedbackManager defaultPerformer] performFeedbackPattern:NSHapticFeedbackPatternAlignment
|
|
82
|
+
performanceTime:NSHapticFeedbackPerformanceTimeNow];
|
|
83
|
+
[self performSelector:@selector(clearRefreshConfirmation) withObject:nil afterDelay:1.2];
|
|
84
|
+
}
|
|
85
|
+
self.needsDisplay = YES;
|
|
86
|
+
}
|
|
87
|
+
- (void)clearRefreshConfirmation {
|
|
88
|
+
self.refreshedUntil = 0;
|
|
89
|
+
self.needsDisplay = YES;
|
|
90
|
+
}
|
|
91
|
+
- (NSDictionary *)quota:(NSDictionary *)usage key:(NSString *)key {
|
|
92
|
+
id value = usage[key];
|
|
93
|
+
return [value isKindOfClass:NSDictionary.class] ? value : nil;
|
|
94
|
+
}
|
|
95
|
+
- (NSNumber *)remainingForQuota:(NSDictionary *)quota usedKey:(NSString *)usedKey {
|
|
96
|
+
NSNumber *used = quota[usedKey];
|
|
97
|
+
if (![used isKindOfClass:NSNumber.class]) return nil;
|
|
98
|
+
return @(fmax(0, fmin(100, 100.0 - used.doubleValue)));
|
|
99
|
+
}
|
|
100
|
+
- (NSString *)weeklyReset:(NSDictionary *)week {
|
|
101
|
+
NSNumber *weekReset = week[@"resets_at"];
|
|
102
|
+
if (!weekReset) return @"--";
|
|
103
|
+
NSDateFormatter *formatter = [NSDateFormatter new];
|
|
104
|
+
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
|
|
105
|
+
formatter.timeZone = NSTimeZone.localTimeZone;
|
|
106
|
+
formatter.dateFormat = @"M/d HH:mm:ss";
|
|
107
|
+
return [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:weekReset.doubleValue]];
|
|
108
|
+
}
|
|
109
|
+
- (NSDictionary *)textAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
|
|
110
|
+
return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
|
|
111
|
+
NSForegroundColorAttributeName: color};
|
|
112
|
+
}
|
|
113
|
+
- (NSDictionary *)centeredTextAttributesWithSize:(CGFloat)size color:(NSColor *)color weight:(NSFontWeight)weight {
|
|
114
|
+
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
|
|
115
|
+
style.alignment = NSTextAlignmentCenter;
|
|
116
|
+
return @{NSFontAttributeName: [NSFont systemFontOfSize:size weight:weight],
|
|
117
|
+
NSForegroundColorAttributeName: color,
|
|
118
|
+
NSParagraphStyleAttributeName: style};
|
|
119
|
+
}
|
|
120
|
+
- (void)fillRoundedRect:(NSRect)rect radius:(CGFloat)radius color:(NSColor *)color {
|
|
121
|
+
[color setFill];
|
|
122
|
+
[[NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius] fill];
|
|
123
|
+
}
|
|
124
|
+
- (void)drawHistorySeries:(NSArray<NSNumber *> *)series inRect:(NSRect)rect color:(NSColor *)color {
|
|
125
|
+
if (!self.historyEnabled || series.count == 0) return;
|
|
126
|
+
[[color colorWithAlphaComponent:0.10] setFill];
|
|
127
|
+
[[NSBezierPath bezierPathWithRoundedRect:rect xRadius:4 yRadius:4] fill];
|
|
128
|
+
CGFloat step = series.count > 1 ? NSWidth(rect) / (series.count - 1) : 0;
|
|
129
|
+
NSBezierPath *line = [NSBezierPath bezierPath];
|
|
130
|
+
for (NSUInteger index = 0; index < series.count; index++) {
|
|
131
|
+
CGFloat value = fmax(0, fmin(100, series[index].doubleValue));
|
|
132
|
+
NSPoint point = NSMakePoint(NSMinX(rect) + index * step,
|
|
133
|
+
NSMinY(rect) + 2 + (NSHeight(rect) - 4) * value / 100.0);
|
|
134
|
+
if (index == 0) [line moveToPoint:point];
|
|
135
|
+
else [line lineToPoint:point];
|
|
136
|
+
if (series.count == 1) {
|
|
137
|
+
[[color colorWithAlphaComponent:0.9] setFill];
|
|
138
|
+
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(point.x - 2, point.y - 2, 4, 4)] fill];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
line.lineWidth = 2;
|
|
142
|
+
line.lineJoinStyle = NSLineJoinStyleRound;
|
|
143
|
+
line.lineCapStyle = NSLineCapStyleRound;
|
|
144
|
+
[[color colorWithAlphaComponent:0.9] setStroke];
|
|
145
|
+
[line stroke];
|
|
146
|
+
}
|
|
147
|
+
- (void)drawProvider:(NSString *)name usage:(NSDictionary *)usage usedKey:(NSString *)usedKey
|
|
148
|
+
color:(NSColor *)color cardRect:(NSRect)card {
|
|
149
|
+
NSColor *primary = [NSColor colorWithWhite:0.96 alpha:1];
|
|
150
|
+
NSColor *secondary = [NSColor colorWithWhite:0.68 alpha:1];
|
|
151
|
+
NSColor *track = [NSColor colorWithWhite:0.28 alpha:0.55];
|
|
152
|
+
NSDictionary *five = [self quota:usage key:@"fiveHour"];
|
|
153
|
+
NSDictionary *week = [self quota:usage key:@"week"];
|
|
154
|
+
NSNumber *fiveRemaining = [self remainingForQuota:five usedKey:usedKey];
|
|
155
|
+
NSNumber *weekRemaining = [self remainingForQuota:week usedKey:usedKey];
|
|
156
|
+
BOOL available = fiveRemaining || weekRemaining;
|
|
157
|
+
|
|
158
|
+
NSBezierPath *cardPath = [NSBezierPath bezierPathWithRoundedRect:card xRadius:16 yRadius:16];
|
|
159
|
+
NSGradient *cardGlass = [[NSGradient alloc]
|
|
160
|
+
initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.13]
|
|
161
|
+
endingColor:[NSColor colorWithRed:0.30 green:0.42 blue:0.62 alpha:0.06]];
|
|
162
|
+
[cardGlass drawInBezierPath:cardPath angle:-30];
|
|
163
|
+
NSBezierPath *border = cardPath;
|
|
164
|
+
[[NSColor colorWithWhite:1 alpha:0.38] setStroke];
|
|
165
|
+
border.lineWidth = 1;
|
|
166
|
+
[border stroke];
|
|
167
|
+
NSBezierPath *innerBorder = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(card, 1.5, 1.5)
|
|
168
|
+
xRadius:14.5 yRadius:14.5];
|
|
169
|
+
[[NSColor colorWithRed:0.66 green:0.86 blue:1 alpha:0.12] setStroke];
|
|
170
|
+
innerBorder.lineWidth = 0.8;
|
|
171
|
+
[innerBorder stroke];
|
|
172
|
+
|
|
173
|
+
NSRect icon = NSMakeRect(NSMinX(card) + 18, NSMinY(card) + 37, 48, 48);
|
|
174
|
+
NSImage *logo = [name isEqualToString:@"Codex"] ? self.codexLogo : self.claudeLogo;
|
|
175
|
+
if (logo) {
|
|
176
|
+
[NSGraphicsContext saveGraphicsState];
|
|
177
|
+
[[NSBezierPath bezierPathWithRoundedRect:icon xRadius:13 yRadius:13] addClip];
|
|
178
|
+
[logo drawInRect:icon fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1.0
|
|
179
|
+
respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}];
|
|
180
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
181
|
+
} else {
|
|
182
|
+
[self fillRoundedRect:icon radius:13 color:[color colorWithAlphaComponent:0.7]];
|
|
183
|
+
NSString *iconText = [name isEqualToString:@"Codex"] ? @"C" : @"AI";
|
|
184
|
+
[iconText drawInRect:NSInsetRect(icon, 0, 10)
|
|
185
|
+
withAttributes:[self centeredTextAttributesWithSize:20 color:NSColor.whiteColor weight:NSFontWeightBold]];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
[name drawInRect:NSMakeRect(NSMinX(card) + 78, NSMinY(card) + 64, 70, 24)
|
|
189
|
+
withAttributes:[self textAttributesWithSize:18 color:primary weight:NSFontWeightSemibold]];
|
|
190
|
+
NSRect status = NSMakeRect(NSMinX(card) + 78, NSMinY(card) + 37, available ? 44 : 68, 22);
|
|
191
|
+
[self fillRoundedRect:status radius:9 color:[available ? NSColor.systemGreenColor : secondary colorWithAlphaComponent:0.15]];
|
|
192
|
+
NSString *statusText = available ? @"在线" : @"等待数据";
|
|
193
|
+
[statusText drawInRect:NSInsetRect(status, 8, 3)
|
|
194
|
+
withAttributes:[self textAttributesWithSize:11 color:available ? NSColor.systemGreenColor : secondary weight:NSFontWeightMedium]];
|
|
195
|
+
|
|
196
|
+
CGFloat firstX = NSMinX(card) + 160;
|
|
197
|
+
[@"5 小时剩余" drawInRect:NSMakeRect(firstX, NSMinY(card) + 68, 100, 20)
|
|
198
|
+
withAttributes:[self textAttributesWithSize:12 color:secondary weight:NSFontWeightRegular]];
|
|
199
|
+
NSString *fiveText = fiveRemaining ? [NSString stringWithFormat:@"%.0f%%", fiveRemaining.doubleValue] : @"--";
|
|
200
|
+
[fiveText drawInRect:NSMakeRect(firstX, NSMinY(card) + 40, 90, 26)
|
|
201
|
+
withAttributes:[self textAttributesWithSize:20 color:primary weight:NSFontWeightSemibold]];
|
|
202
|
+
NSRect bar = NSMakeRect(firstX, NSMinY(card) + 24, 112, 8);
|
|
203
|
+
[self fillRoundedRect:bar radius:4 color:track];
|
|
204
|
+
if (fiveRemaining) {
|
|
205
|
+
NSRect fill = bar;
|
|
206
|
+
fill.size.width *= fiveRemaining.doubleValue / 100.0;
|
|
207
|
+
[self fillRoundedRect:fill radius:4 color:color];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
CGFloat separatorOne = NSMinX(card) + 290;
|
|
211
|
+
[[NSColor colorWithWhite:1 alpha:0.12] setStroke];
|
|
212
|
+
[NSBezierPath strokeLineFromPoint:NSMakePoint(separatorOne, NSMinY(card) + 20)
|
|
213
|
+
toPoint:NSMakePoint(separatorOne, NSMaxY(card) - 20)];
|
|
214
|
+
CGFloat ringX = separatorOne + 38;
|
|
215
|
+
NSPoint center = NSMakePoint(ringX, NSMinY(card) + 51);
|
|
216
|
+
NSBezierPath *ringTrack = [NSBezierPath bezierPath];
|
|
217
|
+
[ringTrack appendBezierPathWithArcWithCenter:center radius:24 startAngle:0 endAngle:360];
|
|
218
|
+
ringTrack.lineWidth = 7;
|
|
219
|
+
[track setStroke];
|
|
220
|
+
[ringTrack stroke];
|
|
221
|
+
if (weekRemaining) {
|
|
222
|
+
NSBezierPath *ring = [NSBezierPath bezierPath];
|
|
223
|
+
[ring appendBezierPathWithArcWithCenter:center radius:24 startAngle:90
|
|
224
|
+
endAngle:90 - 360 * weekRemaining.doubleValue / 100.0 clockwise:YES];
|
|
225
|
+
ring.lineWidth = 7;
|
|
226
|
+
ring.lineCapStyle = NSLineCapStyleRound;
|
|
227
|
+
[color setStroke];
|
|
228
|
+
[ring stroke];
|
|
229
|
+
}
|
|
230
|
+
NSString *weekText = weekRemaining ? [NSString stringWithFormat:@"%.0f%%", weekRemaining.doubleValue] : @"--";
|
|
231
|
+
[weekText drawInRect:NSMakeRect(ringX - 19, NSMinY(card) + 42, 38, 18)
|
|
232
|
+
withAttributes:[self centeredTextAttributesWithSize:13 color:primary weight:NSFontWeightSemibold]];
|
|
233
|
+
[@"周剩余" drawInRect:NSMakeRect(separatorOne + 68, NSMinY(card) + 66, 55, 20)
|
|
234
|
+
withAttributes:[self textAttributesWithSize:12 color:secondary weight:NSFontWeightRegular]];
|
|
235
|
+
|
|
236
|
+
CGFloat separatorTwo = NSMinX(card) + 414;
|
|
237
|
+
[[NSColor colorWithWhite:1 alpha:0.12] setStroke];
|
|
238
|
+
[NSBezierPath strokeLineFromPoint:NSMakePoint(separatorTwo, NSMinY(card) + 20)
|
|
239
|
+
toPoint:NSMakePoint(separatorTwo, NSMaxY(card) - 20)];
|
|
240
|
+
[@"周重置" drawInRect:NSMakeRect(separatorTwo + 16, NSMinY(card) + 66, 80, 20)
|
|
241
|
+
withAttributes:[self textAttributesWithSize:12 color:secondary weight:NSFontWeightRegular]];
|
|
242
|
+
[[self weeklyReset:week] drawInRect:NSMakeRect(separatorTwo + 16, NSMinY(card) + 39,
|
|
243
|
+
NSMaxX(card) - separatorTwo - 28, 24)
|
|
244
|
+
withAttributes:[self textAttributesWithSize:15 color:primary weight:NSFontWeightMedium]];
|
|
245
|
+
NSArray<NSNumber *> *history = [name isEqualToString:@"Codex"] ? self.codexHistory : self.claudeHistory;
|
|
246
|
+
[self drawHistorySeries:history
|
|
247
|
+
inRect:NSMakeRect(separatorTwo + 16, NSMinY(card) + 14, NSMaxX(card) - separatorTwo - 28, 17)
|
|
248
|
+
color:color];
|
|
249
|
+
}
|
|
250
|
+
- (void)drawRect:(NSRect)dirtyRect {
|
|
251
|
+
[NSGraphicsContext saveGraphicsState];
|
|
252
|
+
NSAffineTransform *scale = [NSAffineTransform transform];
|
|
253
|
+
[scale scaleBy:QuotaScale];
|
|
254
|
+
[scale concat];
|
|
255
|
+
NSRect logicalBounds = NSMakeRect(0, 0, QuotaLogicalWidth, QuotaLogicalHeight);
|
|
256
|
+
NSRect outer = NSInsetRect(logicalBounds, 1, 1);
|
|
257
|
+
NSBezierPath *background = [NSBezierPath bezierPathWithRoundedRect:outer xRadius:22 yRadius:22];
|
|
258
|
+
NSGradient *gradient = [[NSGradient alloc]
|
|
259
|
+
initWithStartingColor:[NSColor colorWithRed:0.035 green:0.075 blue:0.14 alpha:0.68]
|
|
260
|
+
endingColor:[NSColor colorWithRed:0.15 green:0.20 blue:0.31 alpha:0.46]];
|
|
261
|
+
[gradient drawInBezierPath:background angle:-20];
|
|
262
|
+
|
|
263
|
+
[NSGraphicsContext saveGraphicsState];
|
|
264
|
+
[background addClip];
|
|
265
|
+
NSGradient *topGlow = [[NSGradient alloc]
|
|
266
|
+
initWithStartingColor:[NSColor colorWithWhite:1 alpha:0.34]
|
|
267
|
+
endingColor:[NSColor colorWithWhite:1 alpha:0.0]];
|
|
268
|
+
[topGlow drawFromCenter:NSMakePoint(555, 348) radius:0
|
|
269
|
+
toCenter:NSMakePoint(555, 348) radius:180 options:0];
|
|
270
|
+
NSGradient *cyanGlow = [[NSGradient alloc]
|
|
271
|
+
initWithStartingColor:[NSColor colorWithRed:0.18 green:0.72 blue:1 alpha:0.11]
|
|
272
|
+
endingColor:[NSColor colorWithRed:0.18 green:0.88 blue:1 alpha:0.0]];
|
|
273
|
+
[cyanGlow drawFromCenter:NSMakePoint(560, 85) radius:0
|
|
274
|
+
toCenter:NSMakePoint(560, 85) radius:170 options:0];
|
|
275
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
276
|
+
|
|
277
|
+
[[NSColor colorWithWhite:1 alpha:0.62] setStroke];
|
|
278
|
+
background.lineWidth = 1.5;
|
|
279
|
+
[background stroke];
|
|
280
|
+
NSBezierPath *innerGlassBorder = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(outer, 2, 2)
|
|
281
|
+
xRadius:20 yRadius:20];
|
|
282
|
+
[[NSColor colorWithRed:0.58 green:0.82 blue:1 alpha:0.22] setStroke];
|
|
283
|
+
innerGlassBorder.lineWidth = 0.8;
|
|
284
|
+
[innerGlassBorder stroke];
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
[@"Agent 余量" drawInRect:NSMakeRect(24, QuotaLogicalHeight - 53, 180, 30)
|
|
288
|
+
withAttributes:[self textAttributesWithSize:23 color:[NSColor colorWithWhite:0.97 alpha:1] weight:NSFontWeightBold]];
|
|
289
|
+
[@"实时配额状态" drawInRect:NSMakeRect(25, QuotaLogicalHeight - 76, 130, 20)
|
|
290
|
+
withAttributes:[self textAttributesWithSize:12 color:[NSColor colorWithWhite:0.63 alpha:1] weight:NSFontWeightRegular]];
|
|
291
|
+
BOOL recentlyRefreshed = self.refreshedUntil > NSDate.date.timeIntervalSince1970;
|
|
292
|
+
NSRect live = NSMakeRect(QuotaLogicalWidth - 145, QuotaLogicalHeight - 51, 78, 28);
|
|
293
|
+
[self fillRoundedRect:live radius:14 color:[NSColor colorWithWhite:1 alpha:0.055]];
|
|
294
|
+
[[NSColor systemGreenColor] setFill];
|
|
295
|
+
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(NSMinX(live) + 12, NSMinY(live) + 10, 8, 8)] fill];
|
|
296
|
+
[recentlyRefreshed ? @"已刷新" : @"实时更新" drawInRect:NSMakeRect(NSMinX(live) + 26, NSMinY(live) + 6, 50, 18)
|
|
297
|
+
withAttributes:[self textAttributesWithSize:11 color:[NSColor colorWithWhite:0.87 alpha:1] weight:NSFontWeightMedium]];
|
|
298
|
+
CGFloat buttonAlpha = self.refreshPressed ? 0.18 : (self.refreshHovered ? 0.12 : 0.06);
|
|
299
|
+
NSRect logicalRefreshRect = [self logicalRefreshRect];
|
|
300
|
+
NSRect refreshRect = self.refreshPressed ? NSInsetRect(logicalRefreshRect, 1.5, 1.5) : logicalRefreshRect;
|
|
301
|
+
[self fillRoundedRect:refreshRect radius:10 color:[NSColor colorWithWhite:1 alpha:buttonAlpha]];
|
|
302
|
+
[recentlyRefreshed ? @"✓" : @"↻" drawInRect:NSInsetRect(refreshRect, 8, 4)
|
|
303
|
+
withAttributes:[self textAttributesWithSize:19 color:[NSColor colorWithWhite:0.9 alpha:1] weight:NSFontWeightRegular]];
|
|
304
|
+
|
|
305
|
+
[self drawProvider:@"Codex" usage:self.codexUsage usedKey:@"used_percent"
|
|
306
|
+
color:[NSColor colorWithRed:0.30 green:0.82 blue:0.86 alpha:1]
|
|
307
|
+
cardRect:NSMakeRect(18, 174, QuotaLogicalWidth - 36, 104)];
|
|
308
|
+
[self drawProvider:@"Claude" usage:self.claudeUsage usedKey:@"used_percentage"
|
|
309
|
+
color:[NSColor colorWithRed:0.66 green:0.43 blue:0.94 alpha:1]
|
|
310
|
+
cardRect:NSMakeRect(18, 58, QuotaLogicalWidth - 36, 104)];
|
|
311
|
+
NSString *footer = self.historyEnabled
|
|
312
|
+
? @"ⓘ 曲线为本机近 7 天周剩余额度 · 15 分钟采样"
|
|
313
|
+
: @"ⓘ 额度随 CLI 响应自动更新 · 本地历史已关闭";
|
|
314
|
+
[footer drawInRect:NSMakeRect(24, 23, 430, 20)
|
|
315
|
+
withAttributes:[self textAttributesWithSize:11 color:[NSColor colorWithWhite:0.58 alpha:1] weight:NSFontWeightRegular]];
|
|
316
|
+
[NSGraphicsContext restoreGraphicsState];
|
|
317
|
+
}
|
|
318
|
+
@end
|