cc-pets 2.5.0 → 2.6.0-beta.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 +47 -5
- package/CC_BRIDGE.zh-CN.md +42 -5
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/README.md +48 -19
- package/README.zh-CN.md +46 -17
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +64 -15
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +7 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +11 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +16 -5
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +11 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +27 -16
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +2 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +3 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +20 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.m +14 -6
- package/Sources/CCPets/App/CCPetsVersion.h +4 -0
- package/Sources/CCPets/App/CCPetsVersion.m +34 -0
- package/Sources/CCPets/App/main.m +11 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +7 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +172 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +25 -7
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +17 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +7 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +92 -11
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +37 -7
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +5 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +163 -40
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +56 -5
- package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
- package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
- package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
- package/Sources/CCPets/Support/CCPetsPreferences.h +4 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +10 -5
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +9 -6
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +3 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +189 -8
- package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
- package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
- package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
- package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +1 -1
- package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
- package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
- package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
- package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
- package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
- package/THIRD_PARTY_NOTICES.md +5 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
- package/bin/agy-with-pet +82 -0
- package/bin/cc-pets +1 -1
- package/bin/claude-with-pet +15 -0
- package/bin/codex-with-pet +17 -2
- package/package.json +5 -3
- package/scripts/install-shell-integration.sh +5 -0
|
@@ -81,15 +81,18 @@ NSString *CCPetsMenuBarApprovalSessionID(NSArray<NSDictionary *> *sessions) {
|
|
|
81
81
|
NSNumber *CCPetsMenuBarTodayTokens(NSArray<NSDictionary *> *quotas) {
|
|
82
82
|
BOOL found = NO;
|
|
83
83
|
unsigned long long total = 0;
|
|
84
|
+
NSArray<NSString *> *tokenSources = @[@"tokenUsage", @"appTokenUsage"];
|
|
84
85
|
for (NSDictionary *quota in quotas) {
|
|
85
86
|
if (![quota isKindOfClass:NSDictionary.class]) continue;
|
|
86
87
|
NSDictionary *usage = [quota[@"usage"] isKindOfClass:NSDictionary.class] ? quota[@"usage"] : nil;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
for (NSString *source in tokenSources) {
|
|
89
|
+
NSDictionary *tokens = [usage[source] isKindOfClass:NSDictionary.class] ? usage[source] : nil;
|
|
90
|
+
NSDictionary *today = [tokens[@"today"] isKindOfClass:NSDictionary.class] ? tokens[@"today"] : nil;
|
|
91
|
+
NSNumber *value = [today[@"total_tokens"] isKindOfClass:NSNumber.class] ? today[@"total_tokens"] : nil;
|
|
92
|
+
if (!value || !isfinite(value.doubleValue) || value.doubleValue < 0) continue;
|
|
93
|
+
found = YES;
|
|
94
|
+
total += value.unsignedLongLongValue;
|
|
95
|
+
}
|
|
93
96
|
}
|
|
94
97
|
return found ? @(total) : nil;
|
|
95
98
|
}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
- (void)updateSystemMetric:(NSString *)key enabled:(BOOL)enabled;
|
|
13
13
|
- (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key;
|
|
14
14
|
- (void)updateUsageDisplayMode:(NSString *)mode forProfileID:(NSString *)profileID;
|
|
15
|
+
- (NSArray<NSString *> *)quotaCardOrderForSettings;
|
|
16
|
+
- (void)updateQuotaCardOrder:(NSArray<NSString *> *)order;
|
|
15
17
|
- (void)updateImportCodexPets:(BOOL)enabled;
|
|
16
18
|
- (void)updatePanelTheme:(NSString *)theme;
|
|
17
19
|
- (void)updateGlassDimLevel:(NSNumber *)level;
|
|
@@ -38,6 +40,7 @@
|
|
|
38
40
|
- (BOOL)deletePetWithID:(NSString *)petID;
|
|
39
41
|
- (void)addClaudeProfile:(id)sender;
|
|
40
42
|
- (void)addCodexProfile:(id)sender;
|
|
43
|
+
- (void)addAntigravityProfile:(id)sender;
|
|
41
44
|
- (void)repairAgentProfile:(NSMenuItem *)sender;
|
|
42
45
|
- (void)renameAgentProfile:(NSMenuItem *)sender;
|
|
43
46
|
- (void)relocateAgentProfile:(NSMenuItem *)sender;
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
#import "CCPetsPhrases.h"
|
|
15
15
|
#import "CCPetsPreferences.h"
|
|
16
16
|
#import "CCPetsProfiles.h"
|
|
17
|
+
#import "CCPetsProviderRegistry.h"
|
|
17
18
|
#import "CCPetsUsageMode.h"
|
|
18
19
|
#import "CCPetsUIStyle.h"
|
|
20
|
+
#import "CCPetsWorkbench.h"
|
|
19
21
|
#import <QuartzCore/QuartzCore.h>
|
|
20
22
|
#include <fcntl.h>
|
|
21
23
|
#include <unistd.h>
|
|
@@ -341,17 +343,21 @@ static void RevealFolder(NSString *path) {
|
|
|
341
343
|
__weak typeof(self) weakSelf = self;
|
|
342
344
|
[self.form setAccessoryViews:@[
|
|
343
345
|
[self smallButtonWithTitle:L(@"Add Claude Home…") action:^{ [weakSelf.actions addClaudeProfile:nil]; }],
|
|
344
|
-
[self smallButtonWithTitle:L(@"Add Codex Home…") action:^{ [weakSelf.actions addCodexProfile:nil]; }]
|
|
346
|
+
[self smallButtonWithTitle:L(@"Add Codex Home…") action:^{ [weakSelf.actions addCodexProfile:nil]; }],
|
|
347
|
+
[self smallButtonWithTitle:L(@"Add Antigravity Home…") action:^{ [weakSelf.actions addAntigravityProfile:nil]; }]
|
|
345
348
|
]];
|
|
346
349
|
self.entries = [self currentEntries];
|
|
347
350
|
if (self.entries.count == 0) {
|
|
348
351
|
[self.form addGroupWithTitle:nil rows:@[
|
|
349
352
|
[CCPetsFormBuilder rowWithTitle:L(@"No Agent accounts detected")
|
|
350
|
-
subtitle:L(@"Use the buttons above to add an existing
|
|
353
|
+
subtitle:L(@"Use the buttons above to add an existing Agent Home.") controls:@[]]
|
|
351
354
|
] footer:nil];
|
|
352
355
|
return;
|
|
353
356
|
}
|
|
354
|
-
|
|
357
|
+
NSArray<NSString *> *providers = @[CCPetsProfileProviderClaude, CCPetsProfileProviderCodex, CCPetsProfileProviderAntigravity];
|
|
358
|
+
NSDictionary<NSString *, NSString *> *titles = @{CCPetsProfileProviderClaude: @"Claude", CCPetsProfileProviderCodex: @"Codex",
|
|
359
|
+
CCPetsProfileProviderAntigravity: @"Antigravity CLI"};
|
|
360
|
+
for (NSString *provider in providers) {
|
|
355
361
|
NSMutableArray<NSView *> *rows = [NSMutableArray array];
|
|
356
362
|
for (NSDictionary *entry in self.entries) {
|
|
357
363
|
NSDictionary *profile = entry[@"profile"];
|
|
@@ -366,8 +372,7 @@ static void RevealFolder(NSString *path) {
|
|
|
366
372
|
row.toolTip = profile[@"home"];
|
|
367
373
|
[rows addObject:row];
|
|
368
374
|
}
|
|
369
|
-
if (rows.count > 0) [self.form addGroupWithTitle:
|
|
370
|
-
[provider isEqualToString:CCPetsProfileProviderClaude] ? @"Claude" : @"Codex" rows:rows footer:nil];
|
|
375
|
+
if (rows.count > 0) [self.form addGroupWithTitle:titles[provider] rows:rows footer:nil];
|
|
371
376
|
}
|
|
372
377
|
}
|
|
373
378
|
|
|
@@ -771,6 +776,151 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
771
776
|
|
|
772
777
|
#pragma mark - 通用
|
|
773
778
|
|
|
779
|
+
static NSPasteboardType const QuotaCardDragType = @"com.universewang.cc-pets.quota-card";
|
|
780
|
+
static const CGFloat QuotaCardGripWidth = 16;
|
|
781
|
+
static const CGFloat QuotaCardGripHitWidth = 20;
|
|
782
|
+
|
|
783
|
+
@interface CCPetsQuotaOrderTable : NSTableView <NSTableViewDataSource, NSTableViewDelegate>
|
|
784
|
+
@property(nonatomic, copy) NSArray<NSString *> *providerKeys;
|
|
785
|
+
@property(nonatomic, copy) void (^orderChanged)(NSArray<NSString *> *);
|
|
786
|
+
@property(nonatomic, copy) NSString *draggedProviderKey;
|
|
787
|
+
@end
|
|
788
|
+
|
|
789
|
+
@implementation CCPetsQuotaOrderTable
|
|
790
|
+
|
|
791
|
+
- (instancetype)initWithFrame:(NSRect)frame {
|
|
792
|
+
if (!(self = [super initWithFrame:frame])) return nil;
|
|
793
|
+
self.headerView = nil;
|
|
794
|
+
self.style = NSTableViewStylePlain;
|
|
795
|
+
self.backgroundColor = NSColor.clearColor;
|
|
796
|
+
self.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone;
|
|
797
|
+
self.rowHeight = 26;
|
|
798
|
+
self.intercellSpacing = NSZeroSize;
|
|
799
|
+
self.columnAutoresizingStyle = NSTableViewUniformColumnAutoresizingStyle;
|
|
800
|
+
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"provider"];
|
|
801
|
+
column.width = frame.size.width;
|
|
802
|
+
[self addTableColumn:column];
|
|
803
|
+
self.dataSource = self;
|
|
804
|
+
self.delegate = self;
|
|
805
|
+
[self registerForDraggedTypes:@[QuotaCardDragType]];
|
|
806
|
+
[self setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES];
|
|
807
|
+
[self setDraggingSourceOperationMask:NSDragOperationNone forLocal:NO];
|
|
808
|
+
[self setAccessibilityLabel:L(@"Quota Card Order")];
|
|
809
|
+
return self;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
- (void)setProviderKeys:(NSArray<NSString *> *)providerKeys {
|
|
813
|
+
if ([_providerKeys isEqualToArray:providerKeys]) return;
|
|
814
|
+
_providerKeys = [providerKeys copy];
|
|
815
|
+
[self reloadData];
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
|
|
819
|
+
return (NSInteger)self.providerKeys.count;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
- (NSView *)hitTest:(NSPoint)point {
|
|
823
|
+
// The icon and label are passive. The table owns the mouse-down that starts a drag.
|
|
824
|
+
return [super hitTest:point] ? self : nil;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
- (NSRect)gripRectForRow:(NSInteger)row {
|
|
828
|
+
NSRect cell = [self frameOfCellAtColumn:0 row:row];
|
|
829
|
+
return NSMakeRect(NSMaxX(cell) - QuotaCardGripHitWidth, NSMinY(cell), QuotaCardGripHitWidth, NSHeight(cell));
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
- (void)resetCursorRects {
|
|
833
|
+
[super resetCursorRects];
|
|
834
|
+
if (self.providerKeys.count < 2) return;
|
|
835
|
+
for (NSInteger row = 0; row < (NSInteger)self.providerKeys.count; row++) {
|
|
836
|
+
[self addCursorRect:[self gripRectForRow:row] cursor:NSCursor.openHandCursor];
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
- (void)mouseDown:(NSEvent *)event {
|
|
841
|
+
self.draggedProviderKey = nil;
|
|
842
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
843
|
+
NSInteger row = [self rowAtPoint:point];
|
|
844
|
+
if (row >= 0 && row < (NSInteger)self.providerKeys.count && NSPointInRect(point, [self gripRectForRow:row])) {
|
|
845
|
+
self.draggedProviderKey = self.providerKeys[(NSUInteger)row];
|
|
846
|
+
}
|
|
847
|
+
[super mouseDown:event];
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
- (void)mouseUp:(NSEvent *)event {
|
|
851
|
+
self.draggedProviderKey = nil;
|
|
852
|
+
[super mouseUp:event];
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)column row:(NSInteger)row {
|
|
856
|
+
NSString *key = self.providerKeys[(NSUInteger)row];
|
|
857
|
+
NSString *title = key;
|
|
858
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
859
|
+
if ([provider.key isEqualToString:key]) { title = provider.name; break; }
|
|
860
|
+
}
|
|
861
|
+
NSImage *icon = [NSImage imageWithSystemSymbolName:@"line.3.horizontal" accessibilityDescription:nil];
|
|
862
|
+
NSImageView *handle = [NSImageView imageViewWithImage:icon];
|
|
863
|
+
handle.contentTintColor = CCPetsSecondaryInkColor();
|
|
864
|
+
NSTextField *name = CCPetsLabel(title, 12, NSFontWeightRegular, CCPetsInkColor());
|
|
865
|
+
NSStackView *content = [NSStackView stackViewWithViews:@[name, handle]];
|
|
866
|
+
content.alignment = NSLayoutAttributeCenterY;
|
|
867
|
+
content.spacing = 8;
|
|
868
|
+
content.translatesAutoresizingMaskIntoConstraints = NO;
|
|
869
|
+
NSView *cell = [NSView new];
|
|
870
|
+
[cell addSubview:content];
|
|
871
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
872
|
+
[handle.widthAnchor constraintEqualToConstant:QuotaCardGripWidth],
|
|
873
|
+
[content.trailingAnchor constraintEqualToAnchor:cell.trailingAnchor],
|
|
874
|
+
[content.leadingAnchor constraintGreaterThanOrEqualToAnchor:cell.leadingAnchor constant:4],
|
|
875
|
+
[content.centerYAnchor constraintEqualToAnchor:cell.centerYAnchor]
|
|
876
|
+
]];
|
|
877
|
+
return cell;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger)row {
|
|
881
|
+
if (self.providerKeys.count < 2 || row < 0 || row >= (NSInteger)self.providerKeys.count) return nil;
|
|
882
|
+
NSString *key = self.providerKeys[(NSUInteger)row];
|
|
883
|
+
if (![key isEqualToString:self.draggedProviderKey]) return nil;
|
|
884
|
+
NSPasteboardItem *item = [NSPasteboardItem new];
|
|
885
|
+
[item setString:key forType:QuotaCardDragType];
|
|
886
|
+
return item;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
- (void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session
|
|
890
|
+
endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation {
|
|
891
|
+
self.draggedProviderKey = nil;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
- (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info
|
|
895
|
+
proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation {
|
|
896
|
+
if (info.draggingSource != self || row < 0 || row > (NSInteger)self.providerKeys.count) return NSDragOperationNone;
|
|
897
|
+
if (operation == NSTableViewDropOn && row < (NSInteger)self.providerKeys.count) {
|
|
898
|
+
NSPoint location = [self convertPoint:info.draggingLocation fromView:nil];
|
|
899
|
+
if (location.y > NSMidY([self rectOfRow:row])) row++;
|
|
900
|
+
}
|
|
901
|
+
[self setDropRow:row dropOperation:NSTableViewDropAbove];
|
|
902
|
+
return NSDragOperationMove;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row
|
|
906
|
+
dropOperation:(NSTableViewDropOperation)operation {
|
|
907
|
+
if (info.draggingSource != self || operation != NSTableViewDropAbove || row < 0 ||
|
|
908
|
+
row > (NSInteger)self.providerKeys.count) return NO;
|
|
909
|
+
NSString *key = [info.draggingPasteboard stringForType:QuotaCardDragType];
|
|
910
|
+
NSUInteger source = key ? [self.providerKeys indexOfObject:key] : NSNotFound;
|
|
911
|
+
if (source == NSNotFound) return NO;
|
|
912
|
+
NSUInteger destination = (NSUInteger)row;
|
|
913
|
+
if (destination > source) destination--;
|
|
914
|
+
if (destination == source) return YES;
|
|
915
|
+
NSMutableArray<NSString *> *order = [self.providerKeys mutableCopy];
|
|
916
|
+
[order removeObjectAtIndex:source];
|
|
917
|
+
[order insertObject:key atIndex:destination];
|
|
918
|
+
if (self.orderChanged) self.orderChanged(order);
|
|
919
|
+
return YES;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
@end
|
|
923
|
+
|
|
774
924
|
@interface CCPetsGeneralPage ()
|
|
775
925
|
@property(nonatomic) CCPetsGlassView *glassPreview;
|
|
776
926
|
@property(nonatomic, copy) NSArray<NSDictionary *> *usageProfiles;
|
|
@@ -789,6 +939,8 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
789
939
|
[super loadView];
|
|
790
940
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(preferencesDidChange:)
|
|
791
941
|
name:CCPetsProfilesDidChangeNotification object:nil];
|
|
942
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(preferencesDidChange:)
|
|
943
|
+
name:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
792
944
|
}
|
|
793
945
|
|
|
794
946
|
- (void)viewWillAppear {
|
|
@@ -1095,9 +1247,33 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
|
1095
1247
|
NSArray *registered = CCPetsProfilesForProvider(provider);
|
|
1096
1248
|
[profiles addObjectsFromArray:registered.count > 0 ? registered : @[@{@"provider": provider}]];
|
|
1097
1249
|
}
|
|
1250
|
+
[profiles addObjectsFromArray:CCPetsProfilesForProvider(CCPetsProfileProviderAntigravity)];
|
|
1098
1251
|
return profiles.copy;
|
|
1099
1252
|
}
|
|
1100
1253
|
|
|
1254
|
+
- (NSView *)quotaCardOrderRow {
|
|
1255
|
+
__weak typeof(self) weakSelf = self;
|
|
1256
|
+
CCPetsQuotaOrderTable *table = [[CCPetsQuotaOrderTable alloc] initWithFrame:NSMakeRect(0, 0, 150, 26)];
|
|
1257
|
+
table.autoresizingMask = NSViewWidthSizable;
|
|
1258
|
+
table.orderChanged = ^(NSArray<NSString *> *order) { [weakSelf.actions updateQuotaCardOrder:order]; };
|
|
1259
|
+
|
|
1260
|
+
NSScrollView *list = [NSScrollView new];
|
|
1261
|
+
list.drawsBackground = NO;
|
|
1262
|
+
list.hasVerticalScroller = NO;
|
|
1263
|
+
list.documentView = table;
|
|
1264
|
+
[list.widthAnchor constraintEqualToConstant:150].active = YES;
|
|
1265
|
+
NSLayoutConstraint *height = [list.heightAnchor constraintEqualToConstant:table.rowHeight];
|
|
1266
|
+
height.active = YES;
|
|
1267
|
+
|
|
1268
|
+
[self.reloaders addObject:^{
|
|
1269
|
+
table.providerKeys = [weakSelf.actions quotaCardOrderForSettings] ?: @[];
|
|
1270
|
+
height.constant = MAX(1, table.providerKeys.count) * table.rowHeight;
|
|
1271
|
+
[table setFrameSize:NSMakeSize(table.frame.size.width, height.constant)];
|
|
1272
|
+
}];
|
|
1273
|
+
return [CCPetsFormBuilder rowWithTitle:L(@"Quota Card Order")
|
|
1274
|
+
subtitle:L(@"Drag to reorder cards in the hover panel") controls:@[list]];
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1101
1277
|
- (void)reloadValues {
|
|
1102
1278
|
if (![self.usageProfiles isEqualToArray:[self currentUsageProfiles]]) {
|
|
1103
1279
|
// 新增、移除、改名或重新定位账号后重建行,同时释放旧控件的闭包。
|
|
@@ -1336,7 +1512,7 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
|
1336
1512
|
|
|
1337
1513
|
[self.form addGroupWithTitle:L(@"Launch Protection") rows:@[
|
|
1338
1514
|
[self switchRowWithTitle:@"Shadowrocket"
|
|
1339
|
-
subtitle:L(@"Block Claude / Codex when Shadowrocket is disconnected or the exit is in an unsupported region")
|
|
1515
|
+
subtitle:L(@"Block Claude / Codex when Shadowrocket is disconnected or the exit is in an unsupported region. Antigravity only checks the connection.")
|
|
1340
1516
|
key:CCPetsShadowrocketLaunchCheckKey
|
|
1341
1517
|
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) {
|
|
1342
1518
|
CCPetsPrefSetBool(CCPetsShadowrocketLaunchCheckKey, enabled);
|
|
@@ -1348,8 +1524,12 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
|
1348
1524
|
NSMutableArray<NSView *> *panelRows = [NSMutableArray array];
|
|
1349
1525
|
self.usageProfiles = [self currentUsageProfiles];
|
|
1350
1526
|
for (NSDictionary *profile in self.usageProfiles) {
|
|
1351
|
-
NSString *provider =
|
|
1527
|
+
NSString *provider = CCPetsProviderForProfileProvider(profile[@"provider"]).name ?: profile[@"provider"];
|
|
1352
1528
|
NSString *name = profile[@"displayName"] ?: provider;
|
|
1529
|
+
if ([profile[@"provider"] isEqual:CCPetsProfileProviderAntigravity]) {
|
|
1530
|
+
name = CCPetsProfileIsOfficialDefault(profile) && ![profile[@"customName"] boolValue]
|
|
1531
|
+
? @"Antigravity CLI" : [NSString stringWithFormat:@"Antigravity CLI · %@", name];
|
|
1532
|
+
}
|
|
1353
1533
|
CCPetsPillButton *pill = [CCPetsPillButton new];
|
|
1354
1534
|
[pill setAccessibilityLabel:[NSString stringWithFormat:L(@"%@ usage display"), name]];
|
|
1355
1535
|
NSView *row = [CCPetsFormBuilder rowWithTitle:name subtitle:@" " controls:@[pill]];
|
|
@@ -1375,6 +1555,7 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
|
1375
1555
|
}];
|
|
1376
1556
|
[panelRows addObject:row];
|
|
1377
1557
|
}
|
|
1558
|
+
[panelRows addObject:[self quotaCardOrderRow]];
|
|
1378
1559
|
// 三项可以任意组合:用"可多选"的分段控件,一行放得下,也和上面的分段控件一个样子。
|
|
1379
1560
|
NSArray<NSString *> *metricKeys = @[SystemCPUEnabledKey, SystemTemperatureEnabledKey, SystemMemoryEnabledKey];
|
|
1380
1561
|
NSSegmentedControl *metrics = [NSSegmentedControl segmentedControlWithLabels:@[@"CPU", L(@"Temperature"), L(@"Memory")]
|
|
@@ -1392,7 +1573,7 @@ static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
|
1392
1573
|
[metrics setSelected:CCPetsPrefBool(metricKeys[index]) forSegment:(NSInteger)index];
|
|
1393
1574
|
}
|
|
1394
1575
|
}];
|
|
1395
|
-
[panelRows
|
|
1576
|
+
[panelRows insertObject:[CCPetsFormBuilder rowWithTitle:L(@"System Status") controls:@[metrics]] atIndex:0];
|
|
1396
1577
|
[self.form addGroupWithTitle:nil rows:panelRows footer:nil];
|
|
1397
1578
|
|
|
1398
1579
|
// 终端跳转:一张卡片,行在 refreshIDEIntegration 拿到检测结果后填入。
|
|
@@ -40,12 +40,14 @@ NSColor *CCPetsSelectionColor(void) { CACHED_COLOR(Dynamic(0x0e9db3, 0.13, 0x4fd
|
|
|
40
40
|
NSColor *CCPetsRingTrackColor(void) { CACHED_COLOR(Dynamic(0xe3e7ee, 1, 0x343a42, 1)); }
|
|
41
41
|
|
|
42
42
|
NSColor *CCPetsProviderColor(NSString *provider) {
|
|
43
|
-
static NSColor *claude, *codex;
|
|
43
|
+
static NSColor *claude, *codex, *antigravity;
|
|
44
44
|
static dispatch_once_t once;
|
|
45
45
|
dispatch_once(&once, ^{
|
|
46
46
|
claude = Dynamic(0xc8643b, 1, 0xe07a50, 1);
|
|
47
47
|
codex = Dynamic(0x3d4655, 1, 0xb9c2cf, 1);
|
|
48
|
+
antigravity = Dynamic(0x286fcb, 1, 0x71adff, 1);
|
|
48
49
|
});
|
|
50
|
+
if ([provider.lowercaseString isEqualToString:@"antigravity"]) return antigravity;
|
|
49
51
|
return [provider.lowercaseString isEqualToString:@"claude"] ? claude : codex;
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#import <Cocoa/Cocoa.h>
|
|
2
2
|
|
|
3
|
-
// 主窗口的「用量」页:本机
|
|
3
|
+
// 主窗口的「用量」页:本机 Agent 的 Token 用量,按模型分色堆叠的每日柱状图 + 模型表。
|
|
4
4
|
//
|
|
5
5
|
// 数据来自 CCPetsModelUsage(本机会话日志,不联网),由 CCPetsUsageStore 在后台按最长的 90 天算一次,
|
|
6
6
|
// 切换来源、区间、指标、模型都只在本地截取,不重算。页面显示期间每分钟问一次 loadIfStale,
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
// 90 天的模型用量,用量页和概览页共用一份。数据层按请求的起点清理缓存,所以统一按最长窗口取,
|
|
12
12
|
// 两页各取各的窗口会让较早的会话缓存被删了又重读。
|
|
13
13
|
//
|
|
14
|
-
// results:provider
|
|
14
|
+
// results:provider -> CCPetsModelUsage 的返回值;还没算完时为 nil。
|
|
15
15
|
extern NSNotificationName const CCPetsUsageStoreDidChangeNotification;
|
|
16
|
+
extern NSString *const CCPetsUsageProviderAntigravityApp;
|
|
16
17
|
@interface CCPetsUsageStore : NSObject
|
|
17
18
|
@property(class, nonatomic, readonly) NSDictionary<NSString *, NSDictionary *> *results;
|
|
18
|
-
// profileId →
|
|
19
|
+
// profileId → 独立模型用量。Antigravity App 只提供 results 中的独立来源。
|
|
19
20
|
@property(class, nonatomic, readonly) NSDictionary<NSString *, NSDictionary *> *profileResults;
|
|
20
21
|
@property(class, nonatomic, readonly) BOOL loading;
|
|
21
22
|
// 没算过、结果超过两分钟、或者跨过了午夜就重算;正在算时不重复发起。算完发 CCPetsUsageStoreDidChangeNotification。
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#import "CCPetsUsagePage.h"
|
|
2
2
|
#import "CCPetsFormBuilder.h"
|
|
3
3
|
#import "CCPetsL10n.h"
|
|
4
|
+
#import "CCPetsPaths.h"
|
|
4
5
|
#import "CCPetsUIStyle.h"
|
|
5
6
|
#import "CCPetsUsage.h"
|
|
6
7
|
#import "CCPetsProfiles.h"
|
|
8
|
+
#import "CCPetsProviderRegistry.h"
|
|
7
9
|
#import "CCPetsCLISupport.h"
|
|
8
10
|
#import "CCPetsUsageShared.h"
|
|
9
11
|
#import "CCPetsUsageChartView.h"
|
|
@@ -38,7 +40,26 @@ static NSString *HitRateText(NSDictionary *counts) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
static NSString *ProviderTitle(NSString *provider) {
|
|
41
|
-
|
|
43
|
+
if ([provider isEqualToString:CCPetsProfileProviderClaude]) return @"Claude Code";
|
|
44
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) return @"Antigravity CLI";
|
|
45
|
+
if ([provider isEqualToString:CCPetsUsageProviderAntigravityApp]) return @"Antigravity App";
|
|
46
|
+
return CCPetsProviderForProfileProvider(provider).name ?: provider;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static NSString *SourceTitle(NSDictionary *source) {
|
|
50
|
+
NSString *provider = source[@"provider"];
|
|
51
|
+
NSString *accountName = source[@"displayName"] ?: source[@"slug"];
|
|
52
|
+
if (accountName.length == 0) return ProviderTitle(provider);
|
|
53
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
54
|
+
NSString *title = ProviderTitle(provider);
|
|
55
|
+
if (CCPetsProfileIsOfficialDefault(source) && ![source[@"customName"] boolValue]) return title;
|
|
56
|
+
return [NSString stringWithFormat:@"%@ · %@", title, accountName];
|
|
57
|
+
}
|
|
58
|
+
return accountName;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static NSString *SourceIdentity(NSDictionary *source) {
|
|
62
|
+
return source[@"id"] ?: source[@"provider"];
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
static NSString *EntrySourceTitle(NSDictionary *entry) {
|
|
@@ -115,8 +136,8 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
115
136
|
@property(nonatomic) NSSegmentedControl *sourceControl;
|
|
116
137
|
@property(nonatomic) NSPopUpButton *sourcePopup;
|
|
117
138
|
@property(nonatomic) NSStackView *sourceSwitcher;
|
|
118
|
-
// segment 0
|
|
119
|
-
@property(nonatomic) NSArray<NSDictionary *> *
|
|
139
|
+
// segment 0 是全部来源,其余与这里的顺序一一对应。
|
|
140
|
+
@property(nonatomic) NSArray<NSDictionary *> *filterSources;
|
|
120
141
|
@property(nonatomic) NSSegmentedControl *rangeControl;
|
|
121
142
|
@property(nonatomic) NSSegmentedControl *metricControl;
|
|
122
143
|
@property(nonatomic) NSProgressIndicator *spinner;
|
|
@@ -182,7 +203,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
182
203
|
self.sourceSwitcher = [NSStackView stackViewWithViews:@[self.sourceControl, self.sourcePopup]];
|
|
183
204
|
self.sourceSwitcher.orientation = NSUserInterfaceLayoutOrientationHorizontal;
|
|
184
205
|
self.sourceSwitcher.spacing = 0;
|
|
185
|
-
[self
|
|
206
|
+
[self rebuildSourceControlSelectingID:nil];
|
|
186
207
|
NSMutableArray<NSString *> *ranges = [NSMutableArray array];
|
|
187
208
|
for (NSNumber *days in @[@7, @30, @90]) {
|
|
188
209
|
[ranges addObject:[NSString stringWithFormat:L(@"%ld Days"), (long)days.integerValue]];
|
|
@@ -237,8 +258,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
237
258
|
|
|
238
259
|
- (void)storeDidChange:(NSNotification *)notification {
|
|
239
260
|
[self.spinner stopAnimation:nil];
|
|
240
|
-
|
|
241
|
-
[self rebuildSourceControlSelectingProfileID:selectedID];
|
|
261
|
+
[self rebuildSourceControlSelectingID:SourceIdentity([self selectedSource])];
|
|
242
262
|
[self computeColorSlots];
|
|
243
263
|
[self render];
|
|
244
264
|
}
|
|
@@ -252,32 +272,42 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
252
272
|
return (UsageMetric)MAX(0, self.metricControl.selectedSegment);
|
|
253
273
|
}
|
|
254
274
|
|
|
255
|
-
- (void)
|
|
256
|
-
NSMutableArray<NSDictionary *> *
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
275
|
+
- (void)rebuildSourceControlSelectingID:(NSString *)selectedID {
|
|
276
|
+
NSMutableArray<NSDictionary *> *sources = [NSMutableArray array];
|
|
277
|
+
for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
|
|
278
|
+
NSString *provider = descriptor.profileProvider;
|
|
279
|
+
NSArray<NSDictionary *> *profiles = CCPetsProfilesForProvider(provider);
|
|
280
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity] && profiles.count > 1) {
|
|
281
|
+
[sources addObject:@{@"provider": provider}];
|
|
282
|
+
}
|
|
283
|
+
[sources addObjectsFromArray:profiles];
|
|
284
|
+
}
|
|
285
|
+
if (CCPetsUsageStore.results[CCPetsUsageProviderAntigravityApp] || CCPetsAntigravityAppUsageAvailable()) {
|
|
286
|
+
[sources addObject:@{@"provider": CCPetsUsageProviderAntigravityApp, @"home": DefaultAntigravityAppConfigDirectory()}];
|
|
287
|
+
}
|
|
288
|
+
self.filterSources = sources;
|
|
289
|
+
NSString *defaultTitle = L(@"All");
|
|
290
|
+
self.sourceControl.segmentCount = sources.count + 1;
|
|
291
|
+
[self.sourceControl setLabel:defaultTitle forSegment:0];
|
|
263
292
|
[self.sourceControl setWidth:0 forSegment:0];
|
|
264
293
|
[self.sourcePopup removeAllItems];
|
|
265
|
-
[self.sourcePopup addItemWithTitle:
|
|
294
|
+
[self.sourcePopup addItemWithTitle:defaultTitle];
|
|
266
295
|
NSInteger selectedSegment = 0;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
296
|
+
NSDictionary *labelAttributes = @{NSFontAttributeName: self.sourceControl.font};
|
|
297
|
+
CGFloat estimatedWidth = MAX(44, [defaultTitle sizeWithAttributes:labelAttributes].width + 22);
|
|
298
|
+
for (NSUInteger index = 0; index < sources.count; index++) {
|
|
299
|
+
NSDictionary *source = sources[index];
|
|
300
|
+
NSString *title = SourceTitle(source);
|
|
301
|
+
NSString *home = source[@"home"];
|
|
302
|
+
NSString *toolTip = home ? CCPetsTildePath(home) : nil;
|
|
271
303
|
NSInteger segment = (NSInteger)index + 1;
|
|
272
304
|
[self.sourceControl setLabel:title forSegment:segment];
|
|
273
|
-
[self.sourceControl setToolTip:
|
|
305
|
+
[self.sourceControl setToolTip:toolTip forSegment:segment];
|
|
274
306
|
[self.sourceControl setWidth:0 forSegment:segment];
|
|
275
307
|
[self.sourcePopup addItemWithTitle:title];
|
|
276
|
-
self.sourcePopup.lastItem.toolTip =
|
|
277
|
-
estimatedWidth += MAX(54, [title sizeWithAttributes
|
|
278
|
-
|
|
279
|
-
}].width + 22);
|
|
280
|
-
if (selectedID.length > 0 && [profile[@"id"] isEqualToString:selectedID]) {
|
|
308
|
+
self.sourcePopup.lastItem.toolTip = toolTip;
|
|
309
|
+
estimatedWidth += MAX(54, [title sizeWithAttributes:labelAttributes].width + 22);
|
|
310
|
+
if ([SourceIdentity(source) isEqualToString:selectedID]) {
|
|
281
311
|
selectedSegment = segment;
|
|
282
312
|
}
|
|
283
313
|
}
|
|
@@ -285,22 +315,17 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
285
315
|
[self.sourcePopup selectItemAtIndex:selectedSegment];
|
|
286
316
|
// 少量短名称保留快速分段切换;账号多或名称长时自动降级为下拉菜单,避免和
|
|
287
317
|
// 右侧时间范围控件互相挤压。下拉菜单仍完整保留每个账号和 Home 提示。
|
|
288
|
-
BOOL usePopup =
|
|
318
|
+
BOOL usePopup = sources.count > 3 || estimatedWidth > 360;
|
|
289
319
|
self.sourceControl.hidden = usePopup;
|
|
290
320
|
self.sourcePopup.hidden = !usePopup;
|
|
291
321
|
}
|
|
292
322
|
|
|
293
|
-
- (NSDictionary *)
|
|
323
|
+
- (NSDictionary *)selectedSource {
|
|
294
324
|
NSInteger selected = self.sourcePopup.hidden
|
|
295
325
|
? self.sourceControl.selectedSegment : self.sourcePopup.indexOfSelectedItem;
|
|
296
326
|
NSInteger index = selected - 1;
|
|
297
|
-
return index >= 0 && index < (NSInteger)self.
|
|
298
|
-
? self.
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
- (NSString *)selectedAccountID {
|
|
302
|
-
NSString *value = [self selectedProfile][@"id"];
|
|
303
|
-
return [value isKindOfClass:NSString.class] && value.length > 0 ? value : nil;
|
|
327
|
+
return index >= 0 && index < (NSInteger)self.filterSources.count
|
|
328
|
+
? self.filterSources[(NSUInteger)index] : nil;
|
|
304
329
|
}
|
|
305
330
|
|
|
306
331
|
// 色板位置:90 天、全部来源里按总用量排名,前 8 名各占一色,其余归「其他」。
|
|
@@ -346,15 +371,17 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
346
371
|
// 按当前来源和区间整理条目。区间合计由截取后的每日数据现加,不用数据层的 models(那是整整 90 天的)。
|
|
347
372
|
- (NSArray<NSDictionary *> *)entriesForRangeDays:(NSInteger)rangeDays {
|
|
348
373
|
NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];
|
|
349
|
-
NSDictionary *
|
|
350
|
-
NSString *selectedProvider =
|
|
351
|
-
|
|
352
|
-
|
|
374
|
+
NSDictionary *selectedSource = [self selectedSource];
|
|
375
|
+
NSString *selectedProvider = selectedSource[@"provider"];
|
|
376
|
+
NSString *selectedProfileID = selectedSource[@"id"];
|
|
377
|
+
NSString *sourceTitle = selectedProfileID ? SourceTitle(selectedSource) : nil;
|
|
378
|
+
NSDictionary *results = CCPetsUsageStore.results;
|
|
379
|
+
NSArray<NSString *> *providers = selectedProvider ? @[selectedProvider]
|
|
380
|
+
: [[CCPetsProviderDescriptors() valueForKey:@"profileProvider"] arrayByAddingObject:CCPetsUsageProviderAntigravityApp];
|
|
353
381
|
NSArray<NSNumber *> *stamps = nil;
|
|
354
382
|
for (NSString *provider in providers) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
? CCPetsUsageStore.profileResults[selectedID] : CCPetsUsageStore.results[provider];
|
|
383
|
+
NSDictionary *result = selectedProfileID
|
|
384
|
+
? CCPetsUsageStore.profileResults[selectedProfileID] : results[provider];
|
|
358
385
|
NSArray<NSDictionary *> *daily = result[@"daily"];
|
|
359
386
|
if (daily.count > (NSUInteger)rangeDays) {
|
|
360
387
|
daily = [daily subarrayWithRange:NSMakeRange(daily.count - (NSUInteger)rangeDays, (NSUInteger)rangeDays)];
|
|
@@ -369,8 +396,7 @@ static const NSTimeInterval UsagePageRefreshInterval = 60;
|
|
|
369
396
|
if (CCPetsTotalTokens(counts) == 0 && Count(counts, @"requests") == 0) continue;
|
|
370
397
|
NSMutableDictionary *entry = [@{@"key": [NSString stringWithFormat:@"%@|%@", provider, model],
|
|
371
398
|
@"provider": provider, @"model": model, @"counts": counts, @"days": days} mutableCopy];
|
|
372
|
-
|
|
373
|
-
if (accountName.length > 0) entry[@"accountName"] = accountName;
|
|
399
|
+
if (sourceTitle.length > 0) entry[@"accountName"] = sourceTitle;
|
|
374
400
|
[entries addObject:entry];
|
|
375
401
|
}
|
|
376
402
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import "CCPetsUsagePage.h"
|
|
2
2
|
#import "CCPetsProfiles.h"
|
|
3
|
+
#import "CCPetsProviderRegistry.h"
|
|
3
4
|
#import "CCPetsUsageShared.h"
|
|
4
5
|
|
|
5
6
|
#pragma mark - 数据
|
|
@@ -10,6 +11,7 @@ static const NSInteger UsageMaximumRangeDays = 90;
|
|
|
10
11
|
static const NSTimeInterval UsageStoreFreshness = 120;
|
|
11
12
|
|
|
12
13
|
NSNotificationName const CCPetsUsageStoreDidChangeNotification = @"CCPetsUsageStoreDidChange";
|
|
14
|
+
NSString *const CCPetsUsageProviderAntigravityApp = @"antigravity-app";
|
|
13
15
|
static NSDictionary<NSString *, NSDictionary *> *UsageStoreResults;
|
|
14
16
|
static NSDictionary<NSString *, NSDictionary *> *UsageStoreProfileResults;
|
|
15
17
|
static NSTimeInterval UsageStoreLoadedAt;
|
|
@@ -74,6 +76,8 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
74
76
|
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
75
77
|
[identity addObject:[NSString stringWithFormat:@"%@|%@", profile[@"id"], profile[@"home"]]];
|
|
76
78
|
}
|
|
79
|
+
BOOL antigravityAppAvailable = CCPetsAntigravityAppUsageAvailable();
|
|
80
|
+
if (antigravityAppAvailable) [identity addObject:CCPetsUsageProviderAntigravityApp];
|
|
77
81
|
NSString *fingerprint = [identity componentsJoinedByString:@"\n"];
|
|
78
82
|
NSCalendar *calendar = NSCalendar.currentCalendar;
|
|
79
83
|
NSDate *today = [calendar startOfDayForDate:NSDate.date];
|
|
@@ -92,7 +96,8 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
92
96
|
dispatch_async(queue, ^{
|
|
93
97
|
NSMutableDictionary *results = [NSMutableDictionary dictionary];
|
|
94
98
|
NSMutableDictionary *profileResults = [NSMutableDictionary dictionary];
|
|
95
|
-
for (
|
|
99
|
+
for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
|
|
100
|
+
NSString *provider = descriptor.profileProvider;
|
|
96
101
|
NSArray<NSDictionary *> *profiles = CCPetsProfilesForProvider(provider);
|
|
97
102
|
if (profiles.count == 0) continue;
|
|
98
103
|
NSMutableArray<NSDictionary *> *providerValues = [NSMutableArray array];
|
|
@@ -105,6 +110,11 @@ static NSDictionary *MergeModelUsageResults(NSArray<NSDictionary *> *values) {
|
|
|
105
110
|
}
|
|
106
111
|
results[provider] = MergeModelUsageResults(providerValues);
|
|
107
112
|
}
|
|
113
|
+
if (antigravityAppAvailable) {
|
|
114
|
+
NSDictionary *appUsage = CCPetsModelUsage(CCPetsUsageProviderAntigravityApp,
|
|
115
|
+
start.timeIntervalSince1970, end.timeIntervalSince1970);
|
|
116
|
+
if (appUsage) results[CCPetsUsageProviderAntigravityApp] = appUsage;
|
|
117
|
+
}
|
|
108
118
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
109
119
|
UsageStoreResults = results;
|
|
110
120
|
UsageStoreProfileResults = profileResults;
|
|
@@ -162,7 +162,7 @@ static NSButton *ActionButton(NSString *title, BOOL prominent, void (^action)(vo
|
|
|
162
162
|
|
|
163
163
|
#pragma mark 宠物卡
|
|
164
164
|
|
|
165
|
-
//
|
|
165
|
+
// 从每个来源的 90 天数据取最后一天,合计为今日用量。
|
|
166
166
|
- (NSArray<NSArray<NSString *> *> *)todayStats {
|
|
167
167
|
NSDictionary *results = CCPetsUsageStore.results;
|
|
168
168
|
if (!results) {
|