cc-pets 2.4.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 +93 -14
- package/CC_BRIDGE.zh-CN.md +71 -11
- package/CHANGELOG.md +55 -0
- package/CHANGELOG.zh-CN.md +56 -1
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +116 -34
- package/README.zh-CN.md +99 -35
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +99 -26
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +51 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +120 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +24 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +24 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +33 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +24 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.m +18 -8
- 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 +41 -17
- 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 +272 -50
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +341 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +227 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +35 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +310 -42
- 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/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +38 -8
- 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 +11 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +217 -45
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +64 -5
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- 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 +14 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +36 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +533 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +98 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +7 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +205 -8
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- 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 +6 -4
- 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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// 额度面板、用量刷新与系统指标。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import "CCPetsBridgeStore.h"
|
|
3
4
|
#import "CCPetsWorkbench.h"
|
|
5
|
+
#import "CCPetsProviderRegistry.h"
|
|
4
6
|
|
|
5
7
|
@implementation AppDelegate (Quota)
|
|
6
8
|
- (void)rescheduleUsageTimer {
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
return NSDate.date.timeIntervalSince1970 - self.lastUsageRefreshAt >= UsageRefreshCoalesceWindow;
|
|
20
22
|
}
|
|
21
23
|
- (void)showQuotaDashboard {
|
|
24
|
+
if (![self petVisible]) return;
|
|
22
25
|
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideQuotaDashboardIfNeeded) object:nil];
|
|
23
26
|
if ([self shouldRefreshUsageForDashboard]) [self refreshUsage:nil];
|
|
24
27
|
[self positionQuotaDashboard];
|
|
@@ -124,9 +127,7 @@
|
|
|
124
127
|
[self updateSystemMetricsTimer];
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
|
-
//
|
|
128
|
-
// 发事件。只看前者会把直接跑 claude / codex 的会话误判成离线;只看后者则在客户端退出后
|
|
129
|
-
// 还要挂满一整个静默窗口。额度数据本身不是在线信号——它一直缓存着,用它判定会恒亮。
|
|
130
|
+
// 在线判定合并托管 CLI 进程、最近的 Agent 事件和桌面端运行状态。额度缓存不参与判定。
|
|
130
131
|
- (void)updateQuotaLiveState {
|
|
131
132
|
NSMutableSet<NSString *> *online = [self.liveClientProviders mutableCopy] ?: [NSMutableSet set];
|
|
132
133
|
NSMutableSet<NSString *> *onlineProfiles = [self.liveClientProfileIDs mutableCopy]
|
|
@@ -134,6 +135,14 @@
|
|
|
134
135
|
NSMutableSet<NSString *> *unscopedProviders = [self.liveUnscopedClientProviders mutableCopy]
|
|
135
136
|
?: [NSMutableSet set];
|
|
136
137
|
NSMutableSet<NSString *> *approvalProfiles = [NSMutableSet set];
|
|
138
|
+
NSInteger desktopSessions = 0;
|
|
139
|
+
if (AntigravityDesktopApplicationIsRunning()) {
|
|
140
|
+
[online addObject:CCBridgeAntigravityAppProvider];
|
|
141
|
+
desktopSessions += 1;
|
|
142
|
+
NSDictionary *profile = CCPetsProfileForHome(CCPetsProfileProviderAntigravity, DefaultAntigravityAppConfigDirectory());
|
|
143
|
+
NSString *profileID = profile[@"id"];
|
|
144
|
+
if (profileID.length > 0) [onlineProfiles addObject:profileID];
|
|
145
|
+
}
|
|
137
146
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
138
147
|
for (NSString *provider in self.providerActivityAt) {
|
|
139
148
|
NSTimeInterval last = [self.providerActivityAt[provider] doubleValue];
|
|
@@ -143,6 +152,9 @@
|
|
|
143
152
|
NSString *profileID = [record[@"profileId"] isKindOfClass:NSString.class]
|
|
144
153
|
? record[@"profileId"] : nil;
|
|
145
154
|
if (![self isAgentSessionRecordLive:record]) continue;
|
|
155
|
+
NSString *provider = [record[@"provider"] isKindOfClass:NSString.class] ? record[@"provider"] : nil;
|
|
156
|
+
if (provider.length > 0) [online addObject:provider];
|
|
157
|
+
if ([provider isEqual:@"Codex"] && IsCodexDesktopFocusTarget(record[@"terminal"])) desktopSessions += 1;
|
|
146
158
|
if (profileID.length > 0) {
|
|
147
159
|
[onlineProfiles addObject:profileID];
|
|
148
160
|
if ([record[@"state"] isEqualToString:@"approval"]) [approvalProfiles addObject:profileID];
|
|
@@ -152,7 +164,7 @@
|
|
|
152
164
|
if (provider.length > 0) [unscopedProviders addObject:provider];
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
|
-
NSInteger count = MAX(self.liveClientCount, (NSInteger)online.count);
|
|
167
|
+
NSInteger count = MAX(self.liveClientCount + desktopSessions, (NSInteger)online.count);
|
|
156
168
|
if (self.quotaView.activeAgentCount == count &&
|
|
157
169
|
[self.quotaView.liveProviders isEqualToSet:online] &&
|
|
158
170
|
[self.quotaView.liveProfileIDs isEqualToSet:onlineProfiles] &&
|
|
@@ -170,9 +182,11 @@
|
|
|
170
182
|
}
|
|
171
183
|
// 面板高度取决于渲染几张额度卡。调整玻璃容器后,内部内容随 autoresizingMask 铺满。
|
|
172
184
|
- (void)resizeQuotaDashboard {
|
|
173
|
-
NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale,
|
|
174
|
-
|
|
175
|
-
|
|
185
|
+
NSSize size = NSMakeSize(QuotaLogicalWidth * QuotaScale, [self.quotaView logicalHeight] * QuotaScale);
|
|
186
|
+
if (NSEqualSizes(self.quotaPanel.frame.size, size)) {
|
|
187
|
+
[self.quotaView refreshQuotaCardLayout];
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
176
190
|
// 只改 size 不动 origin:窗口 frame 的原点在左下,面板会朝上收缩,底边保持贴着宠物。
|
|
177
191
|
NSRect frame = self.quotaPanel.frame;
|
|
178
192
|
frame.size = size;
|
|
@@ -180,7 +194,7 @@
|
|
|
180
194
|
NSRect bounds = NSMakeRect(0, 0, size.width, size.height);
|
|
181
195
|
self.quotaPanel.contentView.frame = bounds;
|
|
182
196
|
for (NSView *subview in self.quotaPanel.contentView.subviews) subview.frame = bounds;
|
|
183
|
-
self.quotaView
|
|
197
|
+
[self.quotaView refreshQuotaCardLayout];
|
|
184
198
|
if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
|
|
185
199
|
}
|
|
186
200
|
// 卡片来自自动登记的官方 Home 与用户明确登记的自定义 Home。自定义目录不会被扫描;
|
|
@@ -195,8 +209,8 @@
|
|
|
195
209
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
196
210
|
NSMutableSet<NSString *> *detected = [NSMutableSet set];
|
|
197
211
|
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
198
|
-
|
|
199
|
-
if (
|
|
212
|
+
CCPetsProviderDescriptor *provider = CCPetsProviderForProfileProvider(profile[@"provider"]);
|
|
213
|
+
if (provider) [detected addObject:provider.name];
|
|
200
214
|
}
|
|
201
215
|
if (self.quotaView.detectedProviders &&
|
|
202
216
|
[detected isEqualToSet:self.quotaView.detectedProviders]) return;
|
|
@@ -205,12 +219,11 @@
|
|
|
205
219
|
[self resizeQuotaDashboard];
|
|
206
220
|
self.quotaView.needsDisplay = YES;
|
|
207
221
|
}
|
|
208
|
-
- (void)
|
|
209
|
-
self.quotaView.
|
|
210
|
-
self.quotaView.claudeUsage = claudeUsage;
|
|
222
|
+
- (void)applyUsageByProvider:(NSDictionary<NSString *, NSDictionary *> *)usageByProvider {
|
|
223
|
+
self.quotaView.usageByProvider = usageByProvider;
|
|
211
224
|
[self refreshDetectedProviders];
|
|
212
|
-
|
|
213
|
-
|
|
225
|
+
[self resizeQuotaDashboard];
|
|
226
|
+
NSDictionary *history = RecordQuotaHistory(self.quotaView.usageByProvider);
|
|
214
227
|
history = RecordProfileQuotaHistory(self.usageMonitor.profileUsages, self.usageMonitor.profiles);
|
|
215
228
|
NSMutableDictionary *profileHistories = [NSMutableDictionary dictionary];
|
|
216
229
|
for (NSDictionary *profile in self.usageMonitor.profiles) {
|
|
@@ -218,8 +231,11 @@
|
|
|
218
231
|
if (profileID.length > 0) profileHistories[profileID] = QuotaHistorySeriesForProfile(history, profileID);
|
|
219
232
|
}
|
|
220
233
|
self.quotaView.profileHistories = profileHistories;
|
|
221
|
-
|
|
222
|
-
|
|
234
|
+
NSMutableDictionary *historyByProvider = [NSMutableDictionary dictionary];
|
|
235
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
236
|
+
historyByProvider[provider.name] = QuotaHistorySeries(history, provider.key);
|
|
237
|
+
}
|
|
238
|
+
self.quotaView.historyByProvider = historyByProvider;
|
|
223
239
|
self.quotaView.lastUpdatedAt = NSDate.date.timeIntervalSince1970;
|
|
224
240
|
self.quotaView.needsDisplay = YES;
|
|
225
241
|
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
#import "CCPetsAppDelegate+Private.h"
|
|
7
7
|
#import "CCPetsUsageMode.h"
|
|
8
8
|
#import "CCPetsWorkbench.h"
|
|
9
|
+
#import "CCPetsProviderRegistry.h"
|
|
9
10
|
|
|
10
11
|
@implementation AppDelegate (Settings)
|
|
11
12
|
- (void)setPetSizeFromSlider:(NSSlider *)sender {
|
|
@@ -48,12 +49,43 @@
|
|
|
48
49
|
}
|
|
49
50
|
- (void)applyUsageDisplayModePreferences {
|
|
50
51
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
NSMutableDictionary *showsAPIUsageByProvider = [NSMutableDictionary dictionary];
|
|
53
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
54
|
+
showsAPIUsageByProvider[provider.name] =
|
|
55
|
+
@([[defaults stringForKey:provider.usageDisplayModeDefaultsKey] isEqualToString:@"api"]);
|
|
56
|
+
}
|
|
57
|
+
self.quotaView.showsAPIUsageByProvider = showsAPIUsageByProvider;
|
|
55
58
|
self.quotaView.needsDisplay = YES;
|
|
56
59
|
}
|
|
60
|
+
- (NSArray<NSString *> *)quotaCardOrderForSettings {
|
|
61
|
+
return [self.quotaView orderedQuotaProviderKeys] ?: @[];
|
|
62
|
+
}
|
|
63
|
+
- (void)updateQuotaCardOrder:(NSArray<NSString *> *)order {
|
|
64
|
+
if (order.count == 0) {
|
|
65
|
+
CCPetsPrefSetObject(CCPetsQuotaCardOrderKey, nil);
|
|
66
|
+
[self.quotaView refreshQuotaCardLayout];
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
NSArray<NSString *> *visible = [self quotaCardOrderForSettings];
|
|
70
|
+
NSSet<NSString *> *visibleKeys = [NSSet setWithArray:visible];
|
|
71
|
+
NSArray<NSString *> *requested = CCPetsPrefNormalizedValue(CCPetsQuotaCardOrderKey, order);
|
|
72
|
+
if (requested.count == 0) return;
|
|
73
|
+
NSMutableOrderedSet<NSString *> *reordered = [NSMutableOrderedSet orderedSetWithArray:requested];
|
|
74
|
+
[reordered intersectSet:visibleKeys];
|
|
75
|
+
[reordered addObjectsFromArray:visible];
|
|
76
|
+
if ([reordered.array isEqualToArray:visible]) return;
|
|
77
|
+
|
|
78
|
+
// Keep the previous slots for known cards that are absent from the current panel.
|
|
79
|
+
NSSet<NSString *> *knownKeys = [NSSet setWithArray:[CCPetsProviderDescriptors() valueForKey:@"key"]];
|
|
80
|
+
NSMutableArray<NSString *> *saved = [NSMutableArray array];
|
|
81
|
+
NSUInteger next = 0;
|
|
82
|
+
for (NSString *key in CCPetsQuotaCardOrder()) {
|
|
83
|
+
if (![knownKeys containsObject:key]) continue;
|
|
84
|
+
[saved addObject:[visibleKeys containsObject:key] ? reordered[next++] : key];
|
|
85
|
+
}
|
|
86
|
+
while (next < reordered.count) [saved addObject:reordered[next++]];
|
|
87
|
+
if (CCPetsPrefSetObject(CCPetsQuotaCardOrderKey, saved)) [self.quotaView refreshQuotaCardLayout];
|
|
88
|
+
}
|
|
57
89
|
- (void)setUsageDisplayModeFromControl:(NSButton *)sender {
|
|
58
90
|
if (sender.identifier.length > 0) {
|
|
59
91
|
NSDictionary *profile = CCPetsProfileWithID(sender.identifier);
|
|
@@ -65,14 +97,18 @@
|
|
|
65
97
|
return;
|
|
66
98
|
}
|
|
67
99
|
NSString *key = sender.tag == 1 ? CodexUsageDisplayModeKey
|
|
68
|
-
: (sender.tag == 2 ? ClaudeUsageDisplayModeKey
|
|
100
|
+
: (sender.tag == 2 ? ClaudeUsageDisplayModeKey
|
|
101
|
+
: (sender.tag == 3 ? AntigravityUsageDisplayModeKey : nil));
|
|
69
102
|
NSString *mode = sender.state == NSControlStateValueOn ? @"api" : @"subscription";
|
|
70
103
|
if (!key) return;
|
|
71
104
|
[self updateUsageDisplayMode:mode forKey:key];
|
|
72
105
|
}
|
|
73
106
|
- (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key {
|
|
74
|
-
|
|
75
|
-
|
|
107
|
+
NSMutableSet<NSString *> *providerKeys = [NSMutableSet set];
|
|
108
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
109
|
+
if (provider.usageDisplayModeDefaultsKey.length > 0) [providerKeys addObject:provider.usageDisplayModeDefaultsKey];
|
|
110
|
+
}
|
|
111
|
+
if (![providerKeys containsObject:key] || ![@[@"api", @"subscription"] containsObject:mode]) return;
|
|
76
112
|
CCPetsPrefSetObject(key, mode);
|
|
77
113
|
[self applyUsageDisplayModePreferences];
|
|
78
114
|
// 展示模式决定了会话要回溯多远(订阅 8 天 / API 到上月月初),切换之后必须重新聚合,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 说话气泡与碎碎念。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import "CCPetsProviderRegistry.h"
|
|
3
4
|
#import "CCPetsUsageMode.h"
|
|
4
5
|
|
|
5
6
|
// 档位写进 defaults 的键;PetView 的右键菜单也要读它。
|
|
@@ -70,7 +71,8 @@ static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
|
|
|
70
71
|
return ![self.lastStatusState isEqualToString:@"idle"];
|
|
71
72
|
}
|
|
72
73
|
- (BOOL)canSpeakNow {
|
|
73
|
-
|
|
74
|
+
// 「仅菜单栏」时没有地方放这句话,也不占预算和冷却。
|
|
75
|
+
if (![self speechEnabled] || ![self petVisible]) return NO;
|
|
74
76
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
75
77
|
if (now < self.speechCooldownUntil) return NO;
|
|
76
78
|
if (!self.speechTimestamps) self.speechTimestamps = [NSMutableArray array];
|
|
@@ -186,7 +188,7 @@ static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
|
|
|
186
188
|
NSDictionary *slots = [self speechSlotsWithTool:self.lastSpeechTool usage:usages[profileID]];
|
|
187
189
|
NSString *text = PetPhraseForTag(PetPhraseTagQuotaLow, slots);
|
|
188
190
|
if (text.length == 0) continue;
|
|
189
|
-
NSString *provider =
|
|
191
|
+
NSString *provider = CCPetsProviderForProfileProvider(profile[@"provider"]).name ?: profile[@"provider"];
|
|
190
192
|
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: provider;
|
|
191
193
|
text = [NSString stringWithFormat:@"%@ · %@: %@", provider, name, text];
|
|
192
194
|
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
@@ -281,7 +283,7 @@ static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
|
|
|
281
283
|
// 话往哪儿显示只在这一处决定:有状态卡就并进它的副行,没有才起独立气泡。
|
|
282
284
|
// 调试触发也必须走这里——否则看到的是现实中不会出现的画面(两个泡叠着)。
|
|
283
285
|
- (void)presentSpeechText:(NSString *)text {
|
|
284
|
-
if (text.length == 0) return;
|
|
286
|
+
if (text.length == 0 || ![self petVisible]) return;
|
|
285
287
|
if (self.statusPanel.isVisible) {
|
|
286
288
|
self.statusDetailLabel.stringValue = text;
|
|
287
289
|
[self resizeStatusCardToFitText];
|
|
@@ -350,7 +352,8 @@ static NSString *SpeechQuotaResetTime(NSDictionary *usage) {
|
|
|
350
352
|
// 被更新气泡临时收起的状态卡还回去(会话已结束或用户关了状态卡就不还)。
|
|
351
353
|
if (self.updateBubbleSuppressedStatus) {
|
|
352
354
|
self.updateBubbleSuppressedStatus = NO;
|
|
353
|
-
if (self.hasAgentStatus && self.statusBubbleExpanded &&
|
|
355
|
+
if (self.hasAgentStatus && self.statusBubbleExpanded && [self petVisible] &&
|
|
356
|
+
!self.statusPanel.isVisible) {
|
|
354
357
|
[self positionAgentStatus];
|
|
355
358
|
[self.statusPanel orderFrontRegardless];
|
|
356
359
|
}
|
|
@@ -218,7 +218,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
218
218
|
NSString *latestVersion = [metadata isKindOfClass:NSDictionary.class] &&
|
|
219
219
|
[metadata[@"version"] isKindOfClass:NSString.class] ? metadata[@"version"] : nil;
|
|
220
220
|
BOOL valid = NO;
|
|
221
|
-
NSComparisonResult comparison =
|
|
221
|
+
NSComparisonResult comparison = CompareInstalledVersionToRelease(@CC_PETS_VERSION, latestVersion, &valid);
|
|
222
222
|
if (error || httpResponse.statusCode != 200 || !valid) {
|
|
223
223
|
NSString *message = error.localizedDescription ?: L(@"The npm registry returned invalid version info. Please try again later.");
|
|
224
224
|
dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil, message); });
|
|
@@ -290,7 +290,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
BOOL valid = NO;
|
|
293
|
-
if (
|
|
293
|
+
if (CompareInstalledVersionToRelease(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
|
|
294
294
|
[strongSelf clearPendingUpdate];
|
|
295
295
|
[strongSelf showAlertWithTitle:L(@"You're Up to Date")
|
|
296
296
|
message:[NSString stringWithFormat:L(@"Version %@"), @CC_PETS_VERSION]];
|
|
@@ -319,7 +319,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
319
319
|
strongSelf.checkingForUpdate = NO;
|
|
320
320
|
if (errorMessage || strongSelf.updating) return;
|
|
321
321
|
BOOL valid = NO;
|
|
322
|
-
if (
|
|
322
|
+
if (CompareInstalledVersionToRelease(@CC_PETS_VERSION, version, &valid) != NSOrderedAscending) {
|
|
323
323
|
[strongSelf clearPendingUpdate];
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
@@ -445,7 +445,9 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
445
445
|
// agent 在忙就先记下来,等它闲下来(considerIdleSpeech 每 3 秒一跳)再冒;
|
|
446
446
|
// 状态卡只是在待命时,临时把它收起让位,气泡消失后再放回来。
|
|
447
447
|
- (void)showUpdateBubble {
|
|
448
|
-
|
|
448
|
+
// 「仅菜单栏」时更新入口是菜单栏菜单里的「更新到 x.y.z…」,不排队等气泡。
|
|
449
|
+
if (self.pendingUpdateVersion.length == 0 || self.updating || self.updateReminderSnoozed ||
|
|
450
|
+
![self petVisible]) {
|
|
449
451
|
self.updateBubbleDeferred = NO;
|
|
450
452
|
return;
|
|
451
453
|
}
|
|
@@ -468,6 +470,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
468
470
|
stringByReplacingOccurrencesOfString:@"{version}" withString:self.pendingUpdateVersion];
|
|
469
471
|
}
|
|
470
472
|
- (void)showUpdateBubbleWithText:(NSString *)text dwell:(NSTimeInterval)dwell {
|
|
473
|
+
if (![self petVisible]) return;
|
|
471
474
|
if (self.statusPanel.isVisible) {
|
|
472
475
|
[self.statusPanel orderOut:nil];
|
|
473
476
|
self.updateBubbleSuppressedStatus = YES;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// 不新增任何采集。
|
|
3
3
|
#import "CCPetsAppDelegate+Private.h"
|
|
4
4
|
#import "CCPetsBridge.h"
|
|
5
|
+
#import "CCPetsBridgeStore.h"
|
|
5
6
|
#import "CCPetsDiagnosticsPage.h"
|
|
6
7
|
#import "CCPetsUsageMode.h"
|
|
8
|
+
#import "CCPetsProviderRegistry.h"
|
|
7
9
|
|
|
8
10
|
NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWorkbenchQuotasDidChange";
|
|
9
11
|
|
|
@@ -15,7 +17,8 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
15
17
|
NSMutableArray<NSDictionary *> *sessions = [NSMutableArray array];
|
|
16
18
|
for (NSString *key in self.agentSessionRecords) {
|
|
17
19
|
NSDictionary *record = self.agentSessionRecords[key];
|
|
18
|
-
NSString *provider = SanitizedShortString(record[@"provider"], 32)
|
|
20
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
21
|
+
NSString *providerKey = provider.lowercaseString;
|
|
19
22
|
// 和状态气泡一致:启动后一直没有后续事件,说明会话已就绪、在等输入。
|
|
20
23
|
NSString *state = SessionDisplayState([record[@"state"] isKindOfClass:NSString.class]
|
|
21
24
|
? record[@"state"] : @"", [record[@"timestamp"] doubleValue], NSDate.date.timeIntervalSince1970);
|
|
@@ -23,8 +26,8 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
23
26
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class] ? record[@"terminal"] : nil;
|
|
24
27
|
NSMutableDictionary *session = [NSMutableDictionary dictionary];
|
|
25
28
|
session[@"id"] = key;
|
|
26
|
-
session[@"provider"] = [
|
|
27
|
-
: ([
|
|
29
|
+
session[@"provider"] = [providerKey isEqualToString:@"claude"] ? @"Claude"
|
|
30
|
+
: ([providerKey isEqualToString:@"codex"] ? @"Codex" : (provider.length > 0 ? provider : @"Agent"));
|
|
28
31
|
if ([record[@"profileId"] isKindOfClass:NSString.class]) session[@"profileId"] = record[@"profileId"];
|
|
29
32
|
if ([record[@"profileName"] isKindOfClass:NSString.class]) session[@"profileName"] = record[@"profileName"];
|
|
30
33
|
session[@"state"] = state;
|
|
@@ -34,6 +37,7 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
34
37
|
session[@"updatedAt"] = record[@"timestamp"] ?: @0;
|
|
35
38
|
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
36
39
|
if ([bridge[@"name"] isKindOfClass:NSString.class]) session[@"name"] = bridge[@"name"];
|
|
40
|
+
session[@"displayName"] = CCBridgeSessionDisplayName(bridge);
|
|
37
41
|
NSString *bridgeID = [self bridgeSessionIdForRecord:record];
|
|
38
42
|
session[@"pendingMessages"] = bridgeID ? (pending[bridgeID] ?: @0) : @0;
|
|
39
43
|
[sessions addObject:session];
|
|
@@ -54,7 +58,9 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
54
58
|
NSMutableArray<NSDictionary *> *pending = [NSMutableArray array];
|
|
55
59
|
[self.bridgePendingCounts enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
56
60
|
NSString *name = self.bridgeSessions[session][@"name"];
|
|
61
|
+
NSString *displayName = CCBridgeSessionDisplayName(self.bridgeSessions[session]);
|
|
57
62
|
[pending addObject:@{@"session": session, @"name": [name isKindOfClass:NSString.class] ? name : session,
|
|
63
|
+
@"displayName": displayName.length > 0 ? displayName : session,
|
|
58
64
|
@"count": count}];
|
|
59
65
|
}];
|
|
60
66
|
[pending sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
@@ -71,11 +77,13 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
71
77
|
|
|
72
78
|
- (NSArray<NSDictionary *> *)workbenchQuotas {
|
|
73
79
|
NSMutableArray<NSDictionary *> *quotas = [NSMutableArray array];
|
|
74
|
-
//
|
|
75
|
-
for (
|
|
80
|
+
// 工作台展示已检测的平台和全部账号,也包含不进入悬停面板的平台。
|
|
81
|
+
for (CCPetsProviderDescriptor *descriptor in CCPetsProviderDescriptors()) {
|
|
82
|
+
NSString *provider = descriptor.name;
|
|
83
|
+
if (self.quotaView.detectedProviders && ![self.quotaView.detectedProviders containsObject:provider]) continue;
|
|
76
84
|
NSMutableArray<NSDictionary *> *profiles = [NSMutableArray array];
|
|
77
85
|
for (NSDictionary *profile in self.quotaView.profiles ?: CCPetsProfiles()) {
|
|
78
|
-
if ([profile[@"provider"] isEqualToString:
|
|
86
|
+
if ([profile[@"provider"] isEqualToString:descriptor.profileProvider]) [profiles addObject:profile];
|
|
79
87
|
}
|
|
80
88
|
// 未登记账号时保留旧版的平台卡片。
|
|
81
89
|
if (profiles.count == 0) [profiles addObject:@{}];
|
|
@@ -83,24 +91,18 @@ NSNotificationName const CCPetsWorkbenchQuotasDidChangeNotification = @"CCPetsWo
|
|
|
83
91
|
NSString *profileID = profile[@"id"];
|
|
84
92
|
NSMutableDictionary *quota = [[self.quotaView accountSnapshotForProvider:provider
|
|
85
93
|
profile:profile.count > 0 ? profile : nil] mutableCopy];
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
quota[[window[1] stringByAppendingString:@"Remaining"]] = @(100 - clamped);
|
|
95
|
-
if ([window[1] isEqualToString:@"week"]) weekUsed = @(clamped);
|
|
96
|
-
}
|
|
97
|
-
if ([limit[@"resets_at"] isKindOfClass:NSNumber.class]) {
|
|
98
|
-
quota[[window[1] stringByAppendingString:@"Reset"]] = limit[@"resets_at"];
|
|
99
|
-
}
|
|
94
|
+
NSArray *windows = quota[@"normalized"][@"windows"];
|
|
95
|
+
for (NSDictionary *window in windows) {
|
|
96
|
+
NSString *key = window[@"key"];
|
|
97
|
+
NSString *prefix = [key isEqualToString:@"fiveHour"] ? @"five" : key;
|
|
98
|
+
NSNumber *used = window[@"used"];
|
|
99
|
+
if (used) quota[[prefix stringByAppendingString:@"Remaining"]] = @(100 - used.doubleValue);
|
|
100
|
+
NSNumber *reset = window[@"quota"][@"resets_at"];
|
|
101
|
+
if ([reset isKindOfClass:NSNumber.class]) quota[[prefix stringByAppendingString:@"Reset"]] = reset;
|
|
100
102
|
}
|
|
101
103
|
if (![quota[@"apiMode"] boolValue]) {
|
|
102
|
-
NSDictionary *
|
|
103
|
-
|
|
104
|
+
NSDictionary *pace = [self.quotaView paceStatusForWindow:CCPetsTrendWindow(windows)
|
|
105
|
+
color:NSColor.systemTealColor];
|
|
104
106
|
if (pace[@"level"]) {
|
|
105
107
|
quota[@"pace"] = pace[@"label"];
|
|
106
108
|
quota[@"paceLevel"] = pace[@"level"];
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
#import "CCPetsSystemMonitor.h"
|
|
7
7
|
#import "CCPetsGlassView.h"
|
|
8
8
|
|
|
9
|
+
@class CCPetsStatusItemController;
|
|
10
|
+
|
|
9
11
|
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
|
10
12
|
@property NSPanel *panel;
|
|
11
13
|
@property NSPanel *quotaPanel;
|
|
@@ -65,10 +67,14 @@
|
|
|
65
67
|
@property NSInteger liveClientCount;
|
|
66
68
|
@property NSString *lastStatusState;
|
|
67
69
|
@property NSString *lastStatusProvider;
|
|
70
|
+
// 当前卡片所属会话的短标签(目录名.动物)和悬停提示;语言切换、回落待机时重排标题要用。
|
|
71
|
+
@property NSString *lastStatusSessionLabel;
|
|
72
|
+
@property NSString *lastStatusSessionTooltip;
|
|
68
73
|
// lastStatusProvider 是卡片标题(有账号名时显示账号名),不能拿去对 pid 文件里的
|
|
69
74
|
// "Claude"/"Codex";在线判定用原始 provider,判断“是不是同一账号”用 provider|profileId。
|
|
70
75
|
@property NSString *lastStatusAgentProvider;
|
|
71
76
|
@property NSString *lastStatusIdentity;
|
|
77
|
+
@property NSDictionary *lastStatusRecord;
|
|
72
78
|
@property NSDictionary *lastTerminalFocusTarget;
|
|
73
79
|
@property NSTimeInterval lastStatusTimestamp;
|
|
74
80
|
@property NSSet<NSString *> *liveClientProviders;
|
|
@@ -77,6 +83,8 @@
|
|
|
77
83
|
@property NSSet<NSString *> *liveUnscopedClientProviders;
|
|
78
84
|
// 包装脚本仍存活的精确 Agent 会话,键为 provider + TTY。
|
|
79
85
|
@property NSSet<NSString *> *liveAgentSessionKeys;
|
|
86
|
+
// 曾由包装器管理的会话身份(包含 session ID),不把复用同一 tty 的新会话认成旧会话。
|
|
87
|
+
@property NSMutableSet<NSString *> *managedAgentSessionKeys;
|
|
80
88
|
// 每个 provider 最近一次事件的时间。不经包装脚本启动的客户端没有 pid 文件,
|
|
81
89
|
// 只能靠"最近还在发事件"证明自己活着。
|
|
82
90
|
@property NSMutableDictionary<NSString *, NSNumber *> *providerActivityAt;
|
|
@@ -126,4 +134,6 @@
|
|
|
126
134
|
@property NSTimer *quotaClockTimer;
|
|
127
135
|
@property NSTimer *systemMetricsTimer;
|
|
128
136
|
@property CCPetsSystemMonitor *systemMonitor;
|
|
137
|
+
// 菜单栏图标。显示位置为「仅桌宠」时为 nil。
|
|
138
|
+
@property CCPetsStatusItemController *statusItemController;
|
|
129
139
|
@end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// 共享常量和跨文件的方法声明见 CCPetsAppDelegate+Private.h。
|
|
3
3
|
#import "CCPetsAppDelegate+Private.h"
|
|
4
4
|
#import "CCPetsOpenCommand.h"
|
|
5
|
+
#import "CCPetsProviderRegistry.h"
|
|
5
6
|
|
|
6
7
|
@implementation CCPetsBubbleContainerView
|
|
7
8
|
@end
|
|
@@ -219,7 +220,8 @@
|
|
|
219
220
|
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
220
221
|
[defaults registerDefaults:@{StatusBubbleExpandedKey: @YES,
|
|
221
222
|
CodexUsageDisplayModeKey: @"subscription",
|
|
222
|
-
ClaudeUsageDisplayModeKey: @"subscription"
|
|
223
|
+
ClaudeUsageDisplayModeKey: @"subscription",
|
|
224
|
+
AntigravityUsageDisplayModeKey: @"subscription"}];
|
|
223
225
|
[defaults registerDefaults:@{
|
|
224
226
|
SystemCPUEnabledKey: @YES,
|
|
225
227
|
SystemTemperatureEnabledKey: @YES,
|
|
@@ -258,7 +260,8 @@
|
|
|
258
260
|
self.panel.backgroundColor = NSColor.clearColor;
|
|
259
261
|
self.panel.hasShadow = NO;
|
|
260
262
|
self.panel.level = NSFloatingWindowLevel;
|
|
261
|
-
self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces |
|
|
263
|
+
self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces |
|
|
264
|
+
NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorCanJoinAllApplications;
|
|
262
265
|
// 与 1.0 一致:透明背景交给 AppKit 原生拖动;PetView 通过
|
|
263
266
|
// mouseDownCanMoveWindow=NO 保留自己的点击和奔跑动画拖动,两条路径按命中区隔离。
|
|
264
267
|
self.panel.movableByWindowBackground = YES;
|
|
@@ -466,12 +469,17 @@
|
|
|
466
469
|
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
467
470
|
[self applySystemMetricPreferences];
|
|
468
471
|
[self applyUsageDisplayModePreferences];
|
|
469
|
-
|
|
470
|
-
|
|
472
|
+
NSMutableDictionary *logoByProvider = [NSMutableDictionary dictionary];
|
|
473
|
+
for (CCPetsProviderDescriptor *provider in CCPetsProviderDescriptors()) {
|
|
474
|
+
NSImage *logo = OfficialAppIcon(provider.logoBundleIdentifier, provider.logoResourceName);
|
|
475
|
+
if (logo) logoByProvider[provider.name] = logo;
|
|
476
|
+
}
|
|
477
|
+
self.quotaView.logoByProvider = logoByProvider;
|
|
471
478
|
self.quotaView.hoverChanged = ^(BOOL hovering) {
|
|
472
479
|
weakSelf.dashboardHovering = hovering;
|
|
473
480
|
if (!hovering) [weakSelf scheduleQuotaDashboardHide];
|
|
474
481
|
};
|
|
482
|
+
self.quotaView.layoutChanged = ^{ [weakSelf resizeQuotaDashboard]; };
|
|
475
483
|
[self.quotaGlass.contentView addSubview:self.quotaView];
|
|
476
484
|
self.quotaPanel.contentView = quotaRoot;
|
|
477
485
|
// 先探测再第一次显示:否则面板会先按两张卡的高度弹出来再收缩一下。
|
|
@@ -482,16 +490,17 @@
|
|
|
482
490
|
[self applyPetSizePreference];
|
|
483
491
|
size = self.panel.frame.size;
|
|
484
492
|
[self.panel setFrameOrigin:NSMakePoint(NSMaxX(visible) - size.width - 24, NSMinY(visible) + 18)];
|
|
485
|
-
|
|
493
|
+
// 按显示位置决定桌宠窗口和菜单栏图标谁出现。
|
|
494
|
+
[self applyDisplayMode];
|
|
486
495
|
self.usageMonitor = [CCPetsUsageMonitor new];
|
|
487
496
|
self.systemMonitor = [CCPetsSystemMonitor new];
|
|
488
497
|
self.agentEventPartialLine = [NSMutableData data];
|
|
489
498
|
self.pendingApprovalRecords = [NSMutableDictionary dictionary];
|
|
490
499
|
self.stallNotifiedSessionKeys = [NSMutableSet set];
|
|
491
|
-
self.usageMonitor.changeHandler = ^(NSDictionary
|
|
500
|
+
self.usageMonitor.changeHandler = ^(NSDictionary<NSString *, NSDictionary *> *usageByProvider) {
|
|
492
501
|
weakSelf.quotaView.profiles = weakSelf.usageMonitor.profiles;
|
|
493
502
|
weakSelf.quotaView.profileUsages = weakSelf.usageMonitor.profileUsages;
|
|
494
|
-
[weakSelf
|
|
503
|
+
[weakSelf applyUsageByProvider:usageByProvider];
|
|
495
504
|
[weakSelf considerQuotaSpeech];
|
|
496
505
|
};
|
|
497
506
|
[self.usageMonitor start];
|
|
@@ -549,7 +558,8 @@
|
|
|
549
558
|
[self.petView setAnimationSuspended:YES];
|
|
550
559
|
}
|
|
551
560
|
- (void)screensDidWake:(NSNotification *)notification {
|
|
552
|
-
|
|
561
|
+
// 「仅菜单栏」时宠物藏着,醒来也别恢复逐帧动画。
|
|
562
|
+
if ([self petVisible]) [self.petView setAnimationSuspended:NO];
|
|
553
563
|
}
|
|
554
564
|
- (void)petWindowDidMove:(NSNotification *)notification {
|
|
555
565
|
if (self.quotaPanel.isVisible) [self positionQuotaDashboard];
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
// 只接受严格的三段纯数字版本号;valid 为 NO 时返回值无意义。
|
|
8
8
|
// 自动更新会把比较结果作为是否升级的唯一依据,所以这里刻意不接受预发布号。
|
|
9
9
|
NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *valid);
|
|
10
|
+
// 应用内更新用:本机版本可以是预览版(X.Y.Z-beta.0 这类 semver 预发布号),npm 的 latest
|
|
11
|
+
// 仍必须是严格的正式版,误发成 latest 的预发布号会被当作无效,不会推给正式版用户。
|
|
12
|
+
// 预览版低于同号正式版:2.6.0-beta.0 < 2.6.0。
|
|
13
|
+
NSComparisonResult CompareInstalledVersionToRelease(NSString *installed, NSString *release, BOOL *valid);
|
|
10
14
|
int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed);
|
|
11
15
|
|
|
12
16
|
// npm 安装日志里是否只是暂时性故障(值得自动重试一次),而不是真的装不上。
|
|
@@ -36,6 +36,40 @@ NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *
|
|
|
36
36
|
return NSOrderedSame;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// semver 预发布号:点分隔的标识符,只含字母数字和连字符;纯数字标识符不许有前导零。
|
|
40
|
+
static BOOL ValidPrerelease(NSString *prerelease) {
|
|
41
|
+
if (prerelease.length == 0 || prerelease.length > 64) return NO;
|
|
42
|
+
NSCharacterSet *allowed = [NSCharacterSet characterSetWithCharactersInString:
|
|
43
|
+
@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"];
|
|
44
|
+
NSCharacterSet *nonDigits = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"].invertedSet;
|
|
45
|
+
for (NSString *identifier in [prerelease componentsSeparatedByString:@"."]) {
|
|
46
|
+
if (identifier.length == 0 || [identifier rangeOfCharacterFromSet:allowed.invertedSet].location != NSNotFound) return NO;
|
|
47
|
+
BOOL numeric = [identifier rangeOfCharacterFromSet:nonDigits].location == NSNotFound;
|
|
48
|
+
if (numeric && identifier.length > 1 && [identifier hasPrefix:@"0"]) return NO;
|
|
49
|
+
}
|
|
50
|
+
return YES;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
NSComparisonResult CompareInstalledVersionToRelease(NSString *installed, NSString *release, BOOL *valid) {
|
|
54
|
+
BOOL parsed = NO;
|
|
55
|
+
if (valid) *valid = NO;
|
|
56
|
+
if (![installed isKindOfClass:NSString.class]) return NSOrderedSame;
|
|
57
|
+
NSString *core = installed;
|
|
58
|
+
NSString *prerelease = nil;
|
|
59
|
+
NSRange dash = [installed rangeOfString:@"-"];
|
|
60
|
+
if (dash.location != NSNotFound) {
|
|
61
|
+
core = [installed substringToIndex:dash.location];
|
|
62
|
+
prerelease = [installed substringFromIndex:NSMaxRange(dash)];
|
|
63
|
+
if (!ValidPrerelease(prerelease)) return NSOrderedSame;
|
|
64
|
+
}
|
|
65
|
+
NSComparisonResult comparison = CompareStableVersions(core, release, &parsed);
|
|
66
|
+
if (!parsed) return NSOrderedSame;
|
|
67
|
+
if (valid) *valid = YES;
|
|
68
|
+
// latest 只会是正式版,预览版只需和同号正式版分出先后。
|
|
69
|
+
if (comparison == NSOrderedSame && prerelease) return NSOrderedAscending;
|
|
70
|
+
return comparison;
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
|
|
40
74
|
for (NSUInteger attempt = 0; attempt < 300; attempt++) {
|
|
41
75
|
if (pid <= 1 || (kill(pid, 0) != 0 && errno == ESRCH)) break;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#import <Cocoa/Cocoa.h>
|
|
3
3
|
#import "CCPetsAppDelegate.h"
|
|
4
4
|
#import "CCPetsEvents.h"
|
|
5
|
+
#import "CCPetsAntigravityEvents.h"
|
|
5
6
|
#import "CCPetsPaths.h"
|
|
6
7
|
#import "CCPetsPhrases.h"
|
|
7
8
|
#import "CCPetsPreviews.h"
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
#import "CCPetsCleanup.h"
|
|
12
13
|
#import "CCPetsIntegrations.h"
|
|
13
14
|
#import "CCPetsBridgeCLI.h"
|
|
15
|
+
#import "CCPetsBridgeTerminalTitle.h"
|
|
14
16
|
#import "CCPetsDoctor.h"
|
|
15
17
|
#import "CCPetsOpenCommand.h"
|
|
16
18
|
#import "CCPetsPetStore.h"
|
|
@@ -27,6 +29,9 @@ int main(int argc, const char *argv[]) {
|
|
|
27
29
|
@autoreleasepool {
|
|
28
30
|
// 下面这些都是命令行入口,输出语言跟终端走;真正启动桌宠前再切回 App 的语言规则。
|
|
29
31
|
CCPetsUseCommandLineLanguage(YES);
|
|
32
|
+
if (argc > 1 && strcmp(argv[1], "--agy-bridge-title") == 0) {
|
|
33
|
+
return CCBridgePrintAntigravityTitle(argc > 2 ? @(argv[2]) : nil);
|
|
34
|
+
}
|
|
30
35
|
if (argc > 1 && strcmp(argv[1], "--launch-preflight") == 0) {
|
|
31
36
|
NSMutableArray<NSString *> *arguments = [NSMutableArray array];
|
|
32
37
|
for (int index = 3; index < argc; index++) [arguments addObject:@(argv[index])];
|
|
@@ -93,6 +98,12 @@ int main(int argc, const char *argv[]) {
|
|
|
93
98
|
return RestartAfterPID(pid, appPath, managed);
|
|
94
99
|
}
|
|
95
100
|
if (argc > 1 && strcmp(argv[1], "--hook") == 0) return RecordHookEvent();
|
|
101
|
+
if (argc == 3 && strcmp(argv[1], "--agy-hook") == 0) return CCPetsRecordAntigravityHook(@(argv[2]));
|
|
102
|
+
if (argc == 2 && strcmp(argv[1], "--agy-status-line") == 0) return CCPetsRecordAntigravityStatusLine();
|
|
103
|
+
if (argc == 2 && strcmp(argv[1], "--agy-launch") == 0) {
|
|
104
|
+
CCPetsRegisterAntigravityTerminalClient(getppid());
|
|
105
|
+
return EXIT_SUCCESS;
|
|
106
|
+
}
|
|
96
107
|
if (argc > 1 && strcmp(argv[1], "--frontmost-bundle-id") == 0) {
|
|
97
108
|
puts(FrontmostApplicationBundleIdentifier().UTF8String);
|
|
98
109
|
return EXIT_SUCCESS;
|