cc-pets 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +5 -2
- package/CC_BRIDGE.zh-CN.md +4 -2
- package/CHANGELOG.md +85 -0
- package/CHANGELOG.zh-CN.md +85 -0
- package/CONTRIBUTING.md +28 -11
- package/CONTRIBUTING.zh-CN.md +23 -11
- package/README.md +127 -27
- package/README.zh-CN.md +104 -30
- package/Resources/zh-Hans.lproj/Localizable.strings +573 -17
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +89 -31
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +18 -4
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +90 -21
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +269 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +13 -7
- package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +71 -47
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +16 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +110 -12
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +68 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
- package/Sources/CCPets/Pet/CCPetsImageLoader.h +5 -0
- package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +10 -2
- package/Sources/CCPets/Pet/CCPetsPetSize.h +10 -0
- package/Sources/CCPets/Pet/CCPetsPetSize.m +21 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +18 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +53 -22
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +42 -2
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
- package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +3 -0
- package/Sources/CCPets/UI/MenuPetSizeView.h +5 -0
- package/Sources/CCPets/UI/MenuPetSizeView.m +73 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +10 -2
- package/bin/codex-with-pet +13 -5
- package/package.json +1 -1
- package/scripts/build.sh +7 -3
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +0 -226
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsImageLoader.h +0 -4
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1806
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m}
RENAMED
|
@@ -162,13 +162,15 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
162
162
|
NSArray<NSString *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtPath:clientDirectory error:nil] ?: @[];
|
|
163
163
|
NSInteger liveClients = 0;
|
|
164
164
|
NSMutableSet<NSString *> *providers = [NSMutableSet set];
|
|
165
|
+
NSMutableSet<NSString *> *profileIDs = [NSMutableSet set];
|
|
166
|
+
NSMutableSet<NSString *> *unscopedProviders = [NSMutableSet set];
|
|
165
167
|
NSMutableSet<NSString *> *sessionKeys = [NSMutableSet set];
|
|
166
168
|
BOOL unlabeled = NO;
|
|
167
169
|
for (NSString *entry in entries) {
|
|
168
170
|
pid_t pid = (pid_t)entry.intValue;
|
|
169
171
|
NSString *path = [clientDirectory stringByAppendingPathComponent:entry];
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
+
// 包装脚本依次写 provider、TTY、profileId。旧版只有前两行,1.0.2 及更早
|
|
173
|
+
// 只 touch 出空文件;升级后仍在运行的老客户端按缺失层级逐级回退,避免
|
|
172
174
|
// “身份不明”,只要还有一个就不清场,避免把仍然活着的会话误判成已退出。
|
|
173
175
|
NSString *contents = [NSString stringWithContentsOfFile:path
|
|
174
176
|
encoding:NSUTF8StringEncoding error:nil] ?: @"";
|
|
@@ -178,14 +180,20 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
178
180
|
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
179
181
|
NSString *tty = lines.count > 1 ? [lines[1]
|
|
180
182
|
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
|
|
183
|
+
NSString *profileID = lines.count > 2 ? [lines[2]
|
|
184
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] : @"";
|
|
181
185
|
if (!ClientProcessAlive(pid, tty)) {
|
|
182
186
|
[NSFileManager.defaultManager removeItemAtPath:path error:nil];
|
|
183
187
|
continue;
|
|
184
188
|
}
|
|
185
189
|
liveClients += 1;
|
|
186
|
-
if (label.length > 0 && label.length <= 32)
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
if (label.length > 0 && label.length <= 32) {
|
|
191
|
+
[providers addObject:label];
|
|
192
|
+
if (profileID.length > 0 && profileID.length <= 128) [profileIDs addObject:profileID];
|
|
193
|
+
else [unscopedProviders addObject:label];
|
|
194
|
+
} else unlabeled = YES;
|
|
195
|
+
NSString *sessionKey = OnlineAgentSessionKey(label,
|
|
196
|
+
profileID.length <= 128 ? profileID : nil, tty);
|
|
189
197
|
if (sessionKey.length > 0) [sessionKeys addObject:sessionKey];
|
|
190
198
|
}
|
|
191
199
|
// 包装脚本启动的客户端有精确的退出信号:pid 文件被回收。这一段不该被为"直接跑
|
|
@@ -195,6 +203,8 @@ static BOOL ClientProcessAlive(pid_t pid, NSString *recordedTTY) {
|
|
|
195
203
|
NSSet<NSString *> *previousProviders = self.liveClientProviders;
|
|
196
204
|
self.liveClientCount = liveClients;
|
|
197
205
|
self.liveClientProviders = providers;
|
|
206
|
+
self.liveClientProfileIDs = profileIDs;
|
|
207
|
+
self.liveUnscopedClientProviders = unscopedProviders;
|
|
198
208
|
self.liveAgentSessionKeys = sessionKeys;
|
|
199
209
|
self.hasUnlabeledClient = unlabeled;
|
|
200
210
|
[self pruneOfflineAgentSessionRecords];
|
package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m}
RENAMED
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
// 会不断把这 60 秒重置掉——用户关掉所有 Codex 窗口后仍然看到“Codex 正在启动”。
|
|
137
137
|
- (void)hideAgentStatusIfClientGone {
|
|
138
138
|
if (!self.hasAgentStatus || self.hasUnlabeledClient) return;
|
|
139
|
-
NSString *provider = self.
|
|
139
|
+
NSString *provider = self.lastStatusAgentProvider;
|
|
140
140
|
if (provider.length == 0 || [self.liveClientProviders containsObject:provider]) return;
|
|
141
141
|
// 不经包装脚本启动的客户端(直接跑 claude / codex)没有 pid 文件,只能靠
|
|
142
142
|
// “最近还在发事件”证明自己活着,所以这里必须留一段静默宽限再清。
|
|
@@ -172,20 +172,23 @@
|
|
|
172
172
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
173
173
|
? record[@"terminal"] : nil;
|
|
174
174
|
if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
|
|
175
|
-
NSString *
|
|
175
|
+
NSString *identity = [self statusIdentityForRecord:record];
|
|
176
176
|
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
177
177
|
if ([self.lastStatusState isEqualToString:@"approval"] &&
|
|
178
|
-
[self.
|
|
178
|
+
[self.lastStatusIdentity isEqualToString:identity]) return;
|
|
179
|
+
[self noteStatusIdentityForRecord:record];
|
|
179
180
|
[self applyStatusPresentationForState:@"approval"
|
|
180
|
-
provider:
|
|
181
|
+
provider:[self statusPresentationNameForRecord:record] tool:tool];
|
|
181
182
|
}
|
|
182
183
|
// 勾选 = 显示气泡。没有 agent 状态时也允许改,这样用户可以提前设好偏好,
|
|
183
184
|
// 而不必等下一次会话开始。
|
|
184
185
|
- (void)toggleStatusBubbleFromMenu:(NSButton *)sender {
|
|
185
|
-
self
|
|
186
|
-
[NSUserDefaults.standardUserDefaults setBool:self.statusBubbleExpanded
|
|
187
|
-
forKey:StatusBubbleExpandedKey];
|
|
186
|
+
[self updateStatusBubbleExpanded:!self.statusBubbleExpanded];
|
|
188
187
|
sender.state = self.statusBubbleExpanded ? NSControlStateValueOn : NSControlStateValueOff;
|
|
188
|
+
}
|
|
189
|
+
- (void)updateStatusBubbleExpanded:(BOOL)expanded {
|
|
190
|
+
self.statusBubbleExpanded = expanded;
|
|
191
|
+
CCPetsPrefSetBool(StatusBubbleExpandedKey, expanded);
|
|
189
192
|
if (self.statusBubbleExpanded && self.hasAgentStatus) {
|
|
190
193
|
[self positionAgentStatus];
|
|
191
194
|
[self.statusPanel orderFrontRegardless];
|
|
@@ -204,6 +207,22 @@
|
|
|
204
207
|
return [event isEqualToString:@"SubagentStop"] || [event isEqualToString:@"PostToolUse"] ||
|
|
205
208
|
[event isEqualToString:@"TaskCompleted"];
|
|
206
209
|
}
|
|
210
|
+
// 标题优先显示账号名;同名账号(不同目录下都叫 claude)只影响展示,身份比较走 profileId。
|
|
211
|
+
- (NSString *)statusPresentationNameForRecord:(NSDictionary *)record {
|
|
212
|
+
NSString *profileName = SanitizedShortString(record[@"profileName"], 64);
|
|
213
|
+
if (profileName.length > 0) return profileName;
|
|
214
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
215
|
+
return provider.length > 0 ? provider : @"Agent";
|
|
216
|
+
}
|
|
217
|
+
- (NSString *)statusIdentityForRecord:(NSDictionary *)record {
|
|
218
|
+
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
219
|
+
NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
|
|
220
|
+
return profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
|
|
221
|
+
}
|
|
222
|
+
- (void)noteStatusIdentityForRecord:(NSDictionary *)record {
|
|
223
|
+
self.lastStatusAgentProvider = SanitizedShortString(record[@"provider"], 32);
|
|
224
|
+
self.lastStatusIdentity = [self statusIdentityForRecord:record];
|
|
225
|
+
}
|
|
207
226
|
- (void)applyStatusPresentationForState:(NSString *)state provider:(NSString *)provider
|
|
208
227
|
tool:(NSString *)tool {
|
|
209
228
|
self.lastStatusState = state;
|
|
@@ -225,6 +244,7 @@
|
|
|
225
244
|
[self resizeStatusCardToFitText];
|
|
226
245
|
[self layoutApprovalBadge];
|
|
227
246
|
[self positionAgentStatus];
|
|
247
|
+
[self notePetCardChanged];
|
|
228
248
|
if (self.statusBubbleExpanded) {
|
|
229
249
|
[self.statusPanel orderFrontRegardless];
|
|
230
250
|
// 卡片一出现就收掉独立气泡:两者都是宠物在说话,同时挂着就是重影。
|
|
@@ -245,6 +265,8 @@
|
|
|
245
265
|
- (void)showAgentStatusForRecord:(NSDictionary *)record notify:(BOOL)shouldNotify {
|
|
246
266
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
247
267
|
if (provider.length == 0) provider = @"Agent";
|
|
268
|
+
NSString *presentationName = [self statusPresentationNameForRecord:record];
|
|
269
|
+
NSString *identity = [self statusIdentityForRecord:record];
|
|
248
270
|
NSString *state = [record[@"state"] isKindOfClass:NSString.class]
|
|
249
271
|
? record[@"state"] : NormalizedStateForEvent(record[@"event"], [record[@"failed"] boolValue]);
|
|
250
272
|
NSString *tool = [record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @"";
|
|
@@ -253,19 +275,32 @@
|
|
|
253
275
|
if (!self.providerActivityAt) self.providerActivityAt = [NSMutableDictionary dictionary];
|
|
254
276
|
self.providerActivityAt[provider] = @(self.lastStatusTimestamp);
|
|
255
277
|
[self updateQuotaLiveState];
|
|
256
|
-
|
|
278
|
+
// 额外 Home 没有共用默认配置的文件监听;Hook 事件是最准确的变更信号。按 15 秒合并,
|
|
279
|
+
// 既让隐藏卡片及时更新,也避免工具密集执行时反复全量聚合。
|
|
280
|
+
if ([record[@"profileId"] isKindOfClass:NSString.class] &&
|
|
281
|
+
self.lastStatusTimestamp - self.lastUsageRefreshAt >= 15.0) {
|
|
282
|
+
[self refreshUsage:nil];
|
|
283
|
+
}
|
|
284
|
+
if (self.hasAgentStatus && [identity isEqualToString:self.lastStatusIdentity] &&
|
|
257
285
|
[self isTrailingRecord:record afterState:self.lastStatusState]) return;
|
|
258
286
|
|
|
259
287
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
260
288
|
? record[@"terminal"] : nil;
|
|
261
|
-
|
|
289
|
+
// Codex 的共享后台偶尔会先送到事件、稍后才完成会话与终端配对。无目标事件不能
|
|
290
|
+
// 把上一条已确认的回跳目标清空,否则卡片仍可见却会突然点不动。
|
|
291
|
+
if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
|
|
292
|
+
else if (self.hasAgentStatus && ![identity isEqualToString:self.lastStatusIdentity]) {
|
|
293
|
+
// 换成另一个账号且仍无法解析终端时,不能误跳到上一家账号。
|
|
294
|
+
self.lastTerminalFocusTarget = nil;
|
|
295
|
+
}
|
|
262
296
|
|
|
263
297
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
264
298
|
selector:@selector(hideAgentStatus) object:nil];
|
|
265
299
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
266
300
|
selector:@selector(enterIdleStatus) object:nil];
|
|
267
301
|
self.hasAgentStatus = YES;
|
|
268
|
-
[self
|
|
302
|
+
[self noteStatusIdentityForRecord:record];
|
|
303
|
+
[self applyStatusPresentationForState:state provider:presentationName tool:tool];
|
|
269
304
|
[self.panel orderFrontRegardless];
|
|
270
305
|
[self performSelector:@selector(hideAgentStatus)
|
|
271
306
|
withObject:nil afterDelay:AgentStatusInactivityInterval];
|
|
@@ -324,27 +359,23 @@
|
|
|
324
359
|
}
|
|
325
360
|
- (NSString *)agentSessionKeyForRecord:(NSDictionary *)record {
|
|
326
361
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
362
|
+
NSString *profileID = SanitizedShortString(record[@"profileId"], 128);
|
|
363
|
+
NSString *identity = profileID.length > 0 ? [NSString stringWithFormat:@"%@|%@", provider, profileID] : provider;
|
|
327
364
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
328
365
|
? record[@"terminal"] : nil;
|
|
329
366
|
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
330
367
|
NSString *bundleID = SanitizedShortString(terminal[@"bundleID"], 128);
|
|
331
368
|
if (tty.length > 0) {
|
|
332
|
-
return [NSString stringWithFormat:@"%@|%@|%@",
|
|
369
|
+
return [NSString stringWithFormat:@"%@|%@|%@", identity, bundleID, tty];
|
|
333
370
|
}
|
|
334
371
|
NSString *session = SanitizedShortString(record[@"session"], 128);
|
|
335
|
-
if (session.length > 0) return [NSString stringWithFormat:@"%@|%@",
|
|
336
|
-
return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@",
|
|
337
|
-
}
|
|
338
|
-
- (NSString *)onlineAgentSessionKeyForProvider:(NSString *)provider tty:(NSString *)tty {
|
|
339
|
-
provider = SanitizedShortString(provider, 32);
|
|
340
|
-
tty = SanitizedShortString(tty.lastPathComponent, 64);
|
|
341
|
-
if (provider.length == 0 || tty.length == 0) return nil;
|
|
342
|
-
return [NSString stringWithFormat:@"%@|%@", provider, tty];
|
|
372
|
+
if (session.length > 0) return [NSString stringWithFormat:@"%@|%@", identity, session];
|
|
373
|
+
return terminal.count > 0 ? [NSString stringWithFormat:@"%@|%@", identity, bundleID] : nil;
|
|
343
374
|
}
|
|
344
375
|
- (NSString *)onlineAgentSessionKeyForRecord:(NSDictionary *)record {
|
|
345
376
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
346
377
|
? record[@"terminal"] : nil;
|
|
347
|
-
return [
|
|
378
|
+
return OnlineAgentSessionKey(record[@"provider"], record[@"profileId"], terminal[@"tty"]);
|
|
348
379
|
}
|
|
349
380
|
// 在线判定优先用包装脚本写出的 pid 文件:它给出精确的退出信号,会话一关列表就更新。
|
|
350
381
|
// 但直接跑 claude / codex(或终端窗口早于 shim 安装就已打开)的会话根本没有 pid 文件,
|
|
@@ -354,6 +385,11 @@
|
|
|
354
385
|
- (BOOL)isAgentSessionRecordLive:(NSDictionary *)record {
|
|
355
386
|
NSString *onlineKey = [self onlineAgentSessionKeyForRecord:record];
|
|
356
387
|
if (onlineKey.length > 0 && [self.liveAgentSessionKeys containsObject:onlineKey]) return YES;
|
|
388
|
+
// 老版本包装脚本的 pid 文件不带账号,只能按 provider + tty 认领。
|
|
389
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
390
|
+
? record[@"terminal"] : nil;
|
|
391
|
+
NSString *unscopedKey = OnlineAgentSessionKey(record[@"provider"], nil, terminal[@"tty"]);
|
|
392
|
+
if (unscopedKey.length > 0 && [self.liveAgentSessionKeys containsObject:unscopedKey]) return YES;
|
|
357
393
|
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
358
394
|
if (provider.length > 0 && [self.liveClientProviders containsObject:provider]) return NO;
|
|
359
395
|
return NSDate.date.timeIntervalSince1970 - [record[@"timestamp"] doubleValue]
|
|
@@ -363,14 +399,35 @@
|
|
|
363
399
|
for (NSString *key in self.agentSessionRecords.allKeys) {
|
|
364
400
|
if (![self isAgentSessionRecordLive:self.agentSessionRecords[key]]) {
|
|
365
401
|
[self.agentSessionRecords removeObjectForKey:key];
|
|
402
|
+
[self notePetCardChanged];
|
|
366
403
|
}
|
|
367
404
|
}
|
|
368
405
|
}
|
|
406
|
+
- (NSString *)terminalSlotKeyForRecord:(NSDictionary *)record {
|
|
407
|
+
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
408
|
+
? record[@"terminal"] : nil;
|
|
409
|
+
NSString *tty = SanitizedShortString(terminal[@"tty"], 64);
|
|
410
|
+
if (tty.length == 0) return nil;
|
|
411
|
+
return [NSString stringWithFormat:@"%@|%@|%@", SanitizedShortString(record[@"provider"], 32),
|
|
412
|
+
SanitizedShortString(terminal[@"bundleID"], 128), tty];
|
|
413
|
+
}
|
|
369
414
|
- (void)trackAgentSessionRecord:(NSDictionary *)record {
|
|
370
415
|
NSString *key = [self agentSessionKeyForRecord:record];
|
|
371
416
|
if (key.length == 0) return;
|
|
372
417
|
if (!self.agentSessionRecords) self.agentSessionRecords = [NSMutableDictionary dictionary];
|
|
418
|
+
// 一个终端前台同时只跑一个客户端。同一终端里新起的会话(可能换了账号)说明之前那个
|
|
419
|
+
// 已经退出;它退出时不会补发结束事件,不在这里清掉就会在列表里留一行"正在启动"。
|
|
420
|
+
if ([record[@"event"] isEqual:@"SessionStart"]) {
|
|
421
|
+
NSString *ttyKey = [self terminalSlotKeyForRecord:record];
|
|
422
|
+
for (NSString *otherKey in self.agentSessionRecords.allKeys) {
|
|
423
|
+
if ([otherKey isEqualToString:key] || ttyKey.length == 0) continue;
|
|
424
|
+
if ([[self terminalSlotKeyForRecord:self.agentSessionRecords[otherKey]] isEqualToString:ttyKey]) {
|
|
425
|
+
[self.agentSessionRecords removeObjectForKey:otherKey];
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
373
429
|
self.agentSessionRecords[key] = record;
|
|
430
|
+
[self notePetCardChanged];
|
|
374
431
|
if (self.agentSessionRecords.count <= AgentSessionRecordLimit) return;
|
|
375
432
|
NSArray<NSDictionary *> *oldestFirst = [self.agentSessionRecords.allValues
|
|
376
433
|
sortedArrayUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
@@ -456,13 +513,13 @@
|
|
|
456
513
|
NSDictionary *terminal = [record[@"terminal"] isKindOfClass:NSDictionary.class]
|
|
457
514
|
? record[@"terminal"] : nil;
|
|
458
515
|
if (terminal.count > 0) self.lastTerminalFocusTarget = terminal;
|
|
459
|
-
NSString *provider = SanitizedShortString(record[@"provider"], 32);
|
|
460
516
|
NSString *state = [record[@"state"] isKindOfClass:NSString.class] ? record[@"state"] : @"";
|
|
461
517
|
self.hasAgentStatus = YES;
|
|
462
518
|
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
463
519
|
selector:@selector(hideAgentStatus) object:nil];
|
|
520
|
+
[self noteStatusIdentityForRecord:record];
|
|
464
521
|
[self applyStatusPresentationForState:state
|
|
465
|
-
provider:
|
|
522
|
+
provider:[self statusPresentationNameForRecord:record]
|
|
466
523
|
tool:[record[@"tool"] isKindOfClass:NSString.class] ? record[@"tool"] : @""];
|
|
467
524
|
[self.panel orderFrontRegardless];
|
|
468
525
|
[self performSelector:@selector(hideAgentStatus) withObject:nil
|
|
@@ -483,6 +540,8 @@
|
|
|
483
540
|
PetApprovalBadgeSize, PetApprovalBadgeSize);
|
|
484
541
|
}
|
|
485
542
|
- (void)refreshApprovalBadge {
|
|
543
|
+
// 收起状态卡(hideAgentStatus)也走这里,名片要跟着回到待机,放在角标判空之前。
|
|
544
|
+
[self notePetCardChanged];
|
|
486
545
|
CCPetsApprovalBadgeView *badge = (CCPetsApprovalBadgeView *)self.approvalBadgeView;
|
|
487
546
|
if (!badge) return;
|
|
488
547
|
badge.count = [self pendingApprovalSessionRecords].count;
|
|
@@ -536,7 +595,7 @@
|
|
|
536
595
|
}
|
|
537
596
|
// 菜单打开即视为看过:角标清零,下一条新消息再亮。
|
|
538
597
|
self.bridgeSeenAt = NSDate.date.timeIntervalSince1970;
|
|
539
|
-
[self
|
|
598
|
+
[self refreshBridgeState:nil];
|
|
540
599
|
if (records.count == 0) {
|
|
541
600
|
[self popUpAgentSessionsMenu:menu from:sender];
|
|
542
601
|
return;
|
|
@@ -597,6 +656,7 @@
|
|
|
597
656
|
}
|
|
598
657
|
// 状态卡:左内边距 20 + 文字 + 间隙 8 + 图标 34 + 右内边距 14。
|
|
599
658
|
- (void)resizeStatusCardToFitText {
|
|
659
|
+
if (!self.statusPanel) return;
|
|
600
660
|
const CGFloat leading = 20, gap = 8, iconWidth = 34, trailing = 14;
|
|
601
661
|
// 副行没内容时收成单行,而不是留一块空白。
|
|
602
662
|
//
|
|
@@ -611,13 +671,9 @@
|
|
|
611
671
|
}
|
|
612
672
|
CGFloat glassWidth = leading + textWidth + gap + iconWidth + trailing;
|
|
613
673
|
glassWidth = fmax(210.0, fmin(glassWidth, 420.0));
|
|
614
|
-
// 高度也要参与早退判断,否则单行/双行之间切换时尺寸不会更新。
|
|
615
|
-
if (fabs(NSWidth(self.statusGlass.frame) - glassWidth) < 0.5 &&
|
|
616
|
-
fabs(NSHeight(self.statusGlass.frame) - height) < 0.5) return;
|
|
617
|
-
|
|
618
674
|
NSSize panelSize = NSMakeSize(glassWidth + 12, height + 12);
|
|
619
|
-
|
|
620
|
-
self.statusPanel
|
|
675
|
+
// 文字未变化时也重新应用比例,滑动条缩放不能被原来的尺寸早退跳过。
|
|
676
|
+
PetResizeBubblePanel(self.statusPanel, panelSize);
|
|
621
677
|
self.statusGlass.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
622
678
|
self.statusGlass.cornerRadius = height / 2.0;
|
|
623
679
|
self.statusShadowView.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
@@ -639,6 +695,7 @@
|
|
|
639
695
|
self.statusIconButton.frame = NSMakeRect(glassWidth - trailing - iconWidth,
|
|
640
696
|
(height - iconWidth) / 2.0, iconWidth, iconWidth);
|
|
641
697
|
self.statusClickButton.frame = NSMakeRect(6, 6, glassWidth - 56, height);
|
|
698
|
+
[self layoutApprovalBadge];
|
|
642
699
|
}
|
|
643
700
|
// 面板底边到"最小那颗圆点底边"的距离。定位要拿它反推面板该放多高,
|
|
644
701
|
// 才能让圆点正好落在宠物头顶而不是悬在空中。
|
|
@@ -647,8 +704,9 @@
|
|
|
647
704
|
NSRect visible = (self.panel.screen ?: NSScreen.mainScreen).visibleFrame;
|
|
648
705
|
NSSize size = self.statusPanel.frame.size;
|
|
649
706
|
CGFloat x = NSMidX(petFrame) - size.width / 2.0;
|
|
650
|
-
CGFloat
|
|
651
|
-
CGFloat
|
|
707
|
+
CGFloat gap = 8 * CCPetsBubbleScalePreference();
|
|
708
|
+
CGFloat aboveY = NSMaxY(petFrame) + gap;
|
|
709
|
+
CGFloat belowY = NSMinY(petFrame) - size.height - gap;
|
|
652
710
|
BOOL aboveFits = aboveY + size.height <= NSMaxY(visible) - 10;
|
|
653
711
|
BOOL belowFits = belowY >= NSMinY(visible) + 10;
|
|
654
712
|
self.statusBubbleAbove = aboveFits || !belowFits;
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
}
|
|
21
21
|
self.bridgeCommandRunning = YES;
|
|
22
22
|
NSTask *task = [NSTask new];
|
|
23
|
-
task.executableURL = [NSURL fileURLWithPath:locator[@"
|
|
24
|
-
task.arguments = [@[
|
|
23
|
+
task.executableURL = [NSURL fileURLWithPath:locator[@"binary"]];
|
|
24
|
+
task.arguments = [@[@"bridge"] arrayByAddingObjectsFromArray:arguments];
|
|
25
25
|
NSMutableDictionary<NSString *, NSString *> *environment =
|
|
26
26
|
[NSProcessInfo.processInfo.environment mutableCopy];
|
|
27
27
|
NSString *existingPath = environment[@"PATH"].length > 0 ? environment[@"PATH"] : @"/usr/bin:/bin:/usr/sbin:/sbin";
|
|
28
|
-
// claude / codex 常装在
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// claude / codex 常装在 nvm 之类的目录里,从 Finder 启动的桌宠 PATH 里没有;
|
|
29
|
+
// 用 cc-pets 上次在终端里运行时记下的 PATH。
|
|
30
|
+
NSString *terminalPath = locator[@"path"];
|
|
31
|
+
environment[@"PATH"] = terminalPath.length > 0 ? [NSString stringWithFormat:@"%@:%@", terminalPath, existingPath] : existingPath;
|
|
31
32
|
task.environment = environment;
|
|
32
33
|
NSPipe *output = [NSPipe pipe];
|
|
33
34
|
task.standardOutput = output;
|
|
@@ -41,6 +42,8 @@
|
|
|
41
42
|
if (!strongSelf) return;
|
|
42
43
|
strongSelf.bridgeCommandRunning = NO;
|
|
43
44
|
[strongSelf refreshBridgeState:nil];
|
|
45
|
+
// 开关 Bridge 会改各账号是否算"已集成",让打开的多账号页重读。
|
|
46
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsProfilesDidChangeNotification object:nil];
|
|
44
47
|
if (finished.terminationStatus == EXIT_SUCCESS) {
|
|
45
48
|
if (successMessage.length > 0) {
|
|
46
49
|
[strongSelf sendNotificationWithTitle:@"CC Bridge" body:successMessage];
|
|
@@ -121,30 +124,19 @@
|
|
|
121
124
|
sender:sender successMessage:nil];
|
|
122
125
|
}
|
|
123
126
|
- (void)toggleBridgeBadge:(NSButton *)sender {
|
|
124
|
-
BOOL enabled = !
|
|
125
|
-
[
|
|
127
|
+
BOOL enabled = !CCPetsPrefBool(BridgeBadgeEnabledKey);
|
|
128
|
+
[self updateBridgeBadgeEnabled:enabled];
|
|
126
129
|
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
130
|
+
}
|
|
131
|
+
- (void)updateBridgeBadgeEnabled:(BOOL)enabled {
|
|
132
|
+
CCPetsPrefSetBool(BridgeBadgeEnabledKey, enabled);
|
|
127
133
|
[self refreshBridgeBadge];
|
|
128
134
|
}
|
|
129
135
|
// 与"系统通知"那组开关同一套授权流程:第一次打开时向系统申请通知权限。
|
|
130
136
|
- (void)toggleBridgeNotification:(NSButton *)sender {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
sender.state = NSControlStateValueOff;
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
[UNUserNotificationCenter.currentNotificationCenter
|
|
138
|
-
requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
|
139
|
-
completionHandler:^(BOOL granted, NSError *error) {
|
|
140
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
141
|
-
[defaults setBool:granted forKey:BridgeNotificationKey];
|
|
142
|
-
sender.state = granted ? NSControlStateValueOn : NSControlStateValueOff;
|
|
143
|
-
if (!granted) {
|
|
144
|
-
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:error.localizedDescription ?:
|
|
145
|
-
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.")];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
137
|
+
[self updateNotification:BridgeNotificationKey enabled:!CCPetsPrefBool(BridgeNotificationKey)
|
|
138
|
+
completion:^(BOOL enabled) {
|
|
139
|
+
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
148
140
|
}];
|
|
149
141
|
}
|
|
150
142
|
// 读 bridge 状态(会话名、最近送达、信箱积压),刷新角标。bridge 未开启时清空并隐藏。
|
|
@@ -156,6 +148,8 @@
|
|
|
156
148
|
self.bridgeRecentDeliveries = nil;
|
|
157
149
|
self.bridgePendingCounts = nil;
|
|
158
150
|
self.bridgeSentStamp = nil;
|
|
151
|
+
self.quotaView.bridgeActivityProfileIDs = [NSSet set];
|
|
152
|
+
self.quotaView.needsDisplay = YES;
|
|
159
153
|
[self refreshBridgeBadge];
|
|
160
154
|
return;
|
|
161
155
|
}
|
|
@@ -179,6 +173,23 @@
|
|
|
179
173
|
if (self.bridgeSessions[session]) pending[session] = count;
|
|
180
174
|
}];
|
|
181
175
|
self.bridgePendingCounts = pending;
|
|
176
|
+
NSMutableSet<NSString *> *bridgeProfiles = [NSMutableSet set];
|
|
177
|
+
for (NSString *session in pending) {
|
|
178
|
+
NSString *profileID = self.bridgeSessions[session][@"profileId"];
|
|
179
|
+
if (profileID.length > 0) [bridgeProfiles addObject:profileID];
|
|
180
|
+
}
|
|
181
|
+
for (NSDictionary *delivery in recent) {
|
|
182
|
+
if ([delivery[@"at"] doubleValue] <= self.bridgeSeenAt) continue;
|
|
183
|
+
for (NSString *key in @[@"toSession", @"fromSession"]) {
|
|
184
|
+
NSString *session = [delivery[key] isKindOfClass:NSString.class] ? delivery[key] : nil;
|
|
185
|
+
NSString *profileID = session.length > 0 ? self.bridgeSessions[session][@"profileId"] : nil;
|
|
186
|
+
if (profileID.length > 0) [bridgeProfiles addObject:profileID];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (![self.quotaView.bridgeActivityProfileIDs isEqualToSet:bridgeProfiles]) {
|
|
190
|
+
self.quotaView.bridgeActivityProfileIDs = bridgeProfiles;
|
|
191
|
+
self.quotaView.needsDisplay = YES;
|
|
192
|
+
}
|
|
182
193
|
[self notifyNewBridgeDeliveries];
|
|
183
194
|
[self refreshBridgeBadge];
|
|
184
195
|
}
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
[NSApp activateIgnoringOtherApps:YES];
|
|
124
124
|
NSAlert *alert = [NSAlert new];
|
|
125
125
|
alert.messageText = L(@"No Pet Sprites Found");
|
|
126
|
-
alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex
|
|
126
|
+
alert.informativeText = L(@"Download one with `cc-pets pet add <name>`, or put a PNG / WebP sprite sheet in ~/.cc-pets/pets/<name>/. CC Pets doesn't read ~/.petdex/pets/ or ~/.codex/pets/; to use Codex pets, turn on “Import Codex Pets” on the Pet page of the Main menu. Then click “Rescan”.");
|
|
127
127
|
[alert addButtonWithTitle:L(@"Rescan")];
|
|
128
128
|
[alert addButtonWithTitle:L(@"Open Pets Folder")];
|
|
129
129
|
[alert addButtonWithTitle:L(@"Quit")];
|
|
@@ -143,11 +143,25 @@
|
|
|
143
143
|
NSDictionary *option = [self petOptionWithID:petID inOptions:options];
|
|
144
144
|
if (!option) return;
|
|
145
145
|
NSInteger spriteRowCount = [option[@"spriteRowCount"] integerValue] ?: 9;
|
|
146
|
-
NSImage *image = LoadPetSpriteImage(option[@"path"],
|
|
146
|
+
NSImage *image = LoadPetSpriteImage(option[@"path"], CCPetsPetDecodeCellSize(), spriteRowCount);
|
|
147
147
|
if (!image) return;
|
|
148
148
|
[self.petView applySheet:image petID:petID rowCount:spriteRowCount];
|
|
149
149
|
PetPhrasesSetCurrentPetID(petID);
|
|
150
|
-
[NSUserDefaults.standardUserDefaults setObject:petID forKey
|
|
150
|
+
[NSUserDefaults.standardUserDefaults setObject:petID forKey:PetSelectedSpriteKey];
|
|
151
|
+
[self notePetCardChanged];
|
|
152
|
+
}
|
|
153
|
+
// 主窗口宠物页的选择列表:只给展示要的字段,素材由页面在后台解码。
|
|
154
|
+
- (NSArray<NSDictionary *> *)petPickerOptions {
|
|
155
|
+
NSMutableArray<NSDictionary *> *options = [NSMutableArray array];
|
|
156
|
+
for (NSDictionary *option in [self petOptions]) {
|
|
157
|
+
[options addObject:@{@"id": option[@"id"], @"name": option[@"name"] ?: @"", @"path": option[@"path"] ?: @"",
|
|
158
|
+
@"rowCount": option[@"spriteRowCount"] ?: @9,
|
|
159
|
+
@"builtin": @([option[@"id"] hasPrefix:@"builtin:"])}];
|
|
160
|
+
}
|
|
161
|
+
return options;
|
|
162
|
+
}
|
|
163
|
+
- (NSString *)currentPetID {
|
|
164
|
+
return self.petView.currentPetID;
|
|
151
165
|
}
|
|
152
166
|
- (BOOL)deletePetWithID:(NSString *)petID {
|
|
153
167
|
if (![petID hasPrefix:@"external:"]) return NO;
|
|
@@ -177,7 +191,7 @@
|
|
|
177
191
|
if (fallback) [self switchPetToID:fallback[@"id"]];
|
|
178
192
|
else {
|
|
179
193
|
PetPhrasesSetCurrentPetID(nil);
|
|
180
|
-
[NSUserDefaults.standardUserDefaults removeObjectForKey
|
|
194
|
+
[NSUserDefaults.standardUserDefaults removeObjectForKey:PetSelectedSpriteKey];
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
return YES;
|