cc-pets 2.1.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/CHANGELOG.zh-CN.md +42 -0
- package/CONTRIBUTING.md +68 -0
- package/CONTRIBUTING.zh-CN.md +56 -0
- package/README.md +47 -31
- package/README.zh-CN.md +39 -20
- package/Resources/Info.plist +3 -1
- package/Resources/en.lproj/InfoPlist.strings +1 -0
- package/Resources/phrases.default.en.txt +182 -0
- package/Resources/zh-Hans.lproj/InfoPlist.strings +1 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +337 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +35 -36
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +16 -14
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +8 -10
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +33 -9
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +84 -8
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +7 -5
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +104 -79
- package/Sources/CCPets/CCPetsAppDelegate.h +1 -2
- package/Sources/CCPets/CCPetsAppDelegate.m +23 -15
- package/Sources/CCPets/CCPetsCleanup.m +9 -6
- package/Sources/CCPets/CCPetsEvents.m +4 -3
- package/Sources/CCPets/CCPetsImageLoader.h +2 -1
- package/Sources/CCPets/CCPetsImageLoader.m +10 -2
- package/Sources/CCPets/CCPetsL10n.h +55 -0
- package/Sources/CCPets/CCPetsL10n.m +219 -0
- package/Sources/CCPets/CCPetsPetSize.h +10 -0
- package/Sources/CCPets/CCPetsPetSize.m +21 -0
- package/Sources/CCPets/CCPetsPhrases.h +14 -1
- package/Sources/CCPets/CCPetsPhrases.m +107 -38
- package/Sources/CCPets/CCPetsPhrasesEditor.m +100 -65
- package/Sources/CCPets/CCPetsPreviews.m +7 -6
- package/Sources/CCPets/CCPetsVersion.h +7 -4
- package/Sources/CCPets/CCPetsVersion.m +14 -6
- package/Sources/CCPets/MenuChoiceRow.m +3 -0
- package/Sources/CCPets/MenuPetSizeView.h +5 -0
- package/Sources/CCPets/MenuPetSizeView.m +73 -0
- package/Sources/CCPets/MenuToggleSwitch.m +3 -2
- package/Sources/CCPets/PetView.m +156 -94
- package/Sources/CCPets/QuotaDashboardView.m +122 -85
- package/Sources/CCPets/main.m +3 -1
- package/bin/cc-pets +21 -22
- package/bin/claude-with-pet +2 -1
- package/bin/codex-with-pet +2 -1
- package/package.json +3 -2
- package/scripts/bridge/cli.mjs +39 -38
- package/scripts/bridge/core.mjs +27 -26
- package/scripts/bridge/hook.mjs +7 -6
- package/scripts/bridge/install.mjs +24 -23
- package/scripts/bridge/mcp-server.mjs +79 -71
- package/scripts/bridge/options.mjs +7 -6
- package/scripts/bridge/reservations.mjs +6 -5
- package/scripts/bridge/store.mjs +10 -9
- package/scripts/build.sh +24 -5
- package/scripts/check-l10n.mjs +168 -0
- package/scripts/configure-updater.mjs +4 -3
- package/scripts/doctor.mjs +93 -79
- package/scripts/i18n.mjs +122 -0
- package/scripts/i18n.zsh +66 -0
- package/scripts/install-app.sh +3 -2
- package/scripts/install-claude-hooks.mjs +10 -9
- package/scripts/install-codex-hooks.mjs +7 -6
- package/scripts/install-shell-integration.sh +6 -5
- package/scripts/locales/zh-Hans.json +366 -0
- package/scripts/pet-store.mjs +45 -44
- package/scripts/uninstall-app.sh +4 -3
- package/scripts/uninstall-integrations.mjs +8 -7
- package/scripts/uninstall-shell-integration.sh +8 -7
- /package/Resources/{phrases.default.txt → phrases.default.zh-Hans.txt} +0 -0
|
@@ -22,44 +22,44 @@
|
|
|
22
22
|
if ([event isEqualToString:@"PermissionRequest"] &&
|
|
23
23
|
![state isEqualToString:@"auto_review"] &&
|
|
24
24
|
[defaults boolForKey:NotificationApprovalKey]) {
|
|
25
|
-
[self sendNotificationWithTitle
|
|
26
|
-
body:[NSString stringWithFormat
|
|
25
|
+
[self sendNotificationWithTitle:L(@"Awaiting approval")
|
|
26
|
+
body:[NSString stringWithFormat:L(@"%@ is waiting for you."), provider]];
|
|
27
27
|
} else if ([event isEqualToString:@"StopFailure"] &&
|
|
28
28
|
[defaults boolForKey:NotificationFailureKey]) {
|
|
29
|
-
[self sendNotificationWithTitle
|
|
30
|
-
body:[NSString stringWithFormat
|
|
29
|
+
[self sendNotificationWithTitle:L(@"Task failed")
|
|
30
|
+
body:[NSString stringWithFormat:L(@"%@'s task failed."), provider]];
|
|
31
31
|
} else if (([event isEqualToString:@"Stop"] || [event isEqualToString:@"SessionEnd"]) &&
|
|
32
32
|
[defaults boolForKey:NotificationCompletionKey]) {
|
|
33
|
-
[self sendNotificationWithTitle
|
|
34
|
-
body:[NSString stringWithFormat
|
|
33
|
+
[self sendNotificationWithTitle:L(@"Task done")
|
|
34
|
+
body:[NSString stringWithFormat:L(@"%@ finished the current task."), provider]];
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
- (NSString *)statusTextForState:(NSString *)state tool:(NSString *)tool {
|
|
38
|
-
if ([state isEqualToString:@"starting"]) return @"
|
|
39
|
-
if ([state isEqualToString:@"idle"]) return @"
|
|
40
|
-
if ([state isEqualToString:@"thinking"]) return @"
|
|
41
|
-
if ([state isEqualToString:@"auto_review"]) return @"
|
|
42
|
-
if ([state isEqualToString:@"approval"]) return @"
|
|
43
|
-
if ([state isEqualToString:@"subagent"]) return @"
|
|
44
|
-
if ([state isEqualToString:@"tool_completed"]) return @"
|
|
45
|
-
if ([state isEqualToString:@"tool_failed"]) return @"
|
|
46
|
-
if ([state isEqualToString:@"completed"]) return @"
|
|
47
|
-
if ([state isEqualToString:@"failed"]) return @"
|
|
48
|
-
if ([state isEqualToString:@"notification"]) return @"
|
|
38
|
+
if ([state isEqualToString:@"starting"]) return L(@"Starting");
|
|
39
|
+
if ([state isEqualToString:@"idle"]) return L(@"Idle");
|
|
40
|
+
if ([state isEqualToString:@"thinking"]) return L(@"Thinking");
|
|
41
|
+
if ([state isEqualToString:@"auto_review"]) return L(@"Auto-reviewing");
|
|
42
|
+
if ([state isEqualToString:@"approval"]) return L(@"Awaiting approval");
|
|
43
|
+
if ([state isEqualToString:@"subagent"]) return L(@"Subagent working");
|
|
44
|
+
if ([state isEqualToString:@"tool_completed"]) return L(@"Step done");
|
|
45
|
+
if ([state isEqualToString:@"tool_failed"]) return L(@"Tool failed");
|
|
46
|
+
if ([state isEqualToString:@"completed"]) return L(@"Task completed");
|
|
47
|
+
if ([state isEqualToString:@"failed"]) return L(@"Task failed");
|
|
48
|
+
if ([state isEqualToString:@"notification"]) return L(@"Needs attention");
|
|
49
49
|
if ([state isEqualToString:@"tool"]) {
|
|
50
50
|
NSString *lower = tool.lowercaseString;
|
|
51
51
|
if ([lower containsString:@"bash"] || [lower containsString:@"exec"] ||
|
|
52
|
-
[lower containsString:@"shell"] || [lower containsString:@"terminal"]) return @"
|
|
52
|
+
[lower containsString:@"shell"] || [lower containsString:@"terminal"]) return L(@"Running a command");
|
|
53
53
|
if ([lower containsString:@"patch"] || [lower containsString:@"edit"] ||
|
|
54
|
-
[lower containsString:@"write"]) return @"
|
|
54
|
+
[lower containsString:@"write"]) return L(@"Editing files");
|
|
55
55
|
if ([lower containsString:@"read"] || [lower containsString:@"search"] ||
|
|
56
56
|
[lower containsString:@"find"] || [lower containsString:@"grep"] ||
|
|
57
57
|
[lower containsString:@"glob"] || [lower containsString:@"web"] ||
|
|
58
|
-
[lower hasPrefix:@"mcp__"]) return @"
|
|
59
|
-
if ([lower containsString:@"task"] || [lower containsString:@"agent"]) return @"
|
|
60
|
-
return @"
|
|
58
|
+
[lower hasPrefix:@"mcp__"]) return L(@"Looking things up");
|
|
59
|
+
if ([lower containsString:@"task"] || [lower containsString:@"agent"]) return L(@"Subagent working");
|
|
60
|
+
return L(@"Using a tool");
|
|
61
61
|
}
|
|
62
|
-
return @"
|
|
62
|
+
return L(@"Working");
|
|
63
63
|
}
|
|
64
64
|
// 状态卡副行的正文。每个 hook 状态都由宠物来讲,标题仍然给事实。
|
|
65
65
|
//
|
|
@@ -434,8 +434,8 @@
|
|
|
434
434
|
if (shouldNotify) {
|
|
435
435
|
NSInteger minutes = (NSInteger)((now - timestamp) / 60.0);
|
|
436
436
|
[self sendNotificationWithTitle:
|
|
437
|
-
[state isEqualToString:@"approval"] ? @"
|
|
438
|
-
body:[NSString stringWithFormat
|
|
437
|
+
[state isEqualToString:@"approval"] ? L(@"Approval still pending") : L(@"Agent unresponsive")
|
|
438
|
+
body:[NSString stringWithFormat:L(@"%1$@: %2$@ for %3$ld min."),
|
|
439
439
|
provider, [self statusTextForState:state tool:record[@"tool"]], (long)minutes]];
|
|
440
440
|
}
|
|
441
441
|
// 多个会话同时卡住时只把最旧的那条顶到气泡上:它等得最久。
|
|
@@ -529,7 +529,7 @@
|
|
|
529
529
|
NSArray<NSDictionary *> *deliveries = self.bridgeRecentDeliveries ?: @[];
|
|
530
530
|
NSDictionary<NSString *, NSNumber *> *pending = self.bridgePendingCounts ?: @{};
|
|
531
531
|
if (records.count == 0 && deliveries.count == 0 && pending.count == 0) return;
|
|
532
|
-
NSMenu *menu = [[NSMenu alloc] initWithTitle
|
|
532
|
+
NSMenu *menu = [[NSMenu alloc] initWithTitle:L(@"Recent Agent Sessions")];
|
|
533
533
|
if (deliveries.count > 0 || pending.count > 0) {
|
|
534
534
|
[self addBridgeItemsToMenu:menu deliveries:deliveries pending:pending];
|
|
535
535
|
[menu addItem:NSMenuItem.separatorItem];
|
|
@@ -541,7 +541,7 @@
|
|
|
541
541
|
[self popUpAgentSessionsMenu:menu from:sender];
|
|
542
542
|
return;
|
|
543
543
|
}
|
|
544
|
-
NSMenuItem *heading = [menu addItemWithTitle
|
|
544
|
+
NSMenuItem *heading = [menu addItemWithTitle:L(@"Recent Agent Sessions") action:nil keyEquivalent:@""];
|
|
545
545
|
heading.enabled = NO;
|
|
546
546
|
[menu addItem:NSMenuItem.separatorItem];
|
|
547
547
|
BOOL separatedApprovals = NO;
|
|
@@ -562,7 +562,7 @@
|
|
|
562
562
|
// 开启 CC Bridge 时带上会话名:用户和 Agent 之间就是用这个名字互相指代的。
|
|
563
563
|
NSDictionary *bridge = [self bridgeSessionEntryForRecord:record];
|
|
564
564
|
NSString *bridgeName = bridge.count > 0
|
|
565
|
-
? [NSString stringWithFormat
|
|
565
|
+
? [NSString stringWithFormat:L(@" (%@)"), bridge[@"name"]] : @"";
|
|
566
566
|
NSUInteger waiting = [pending[[self bridgeSessionIdForRecord:record] ?: @""] unsignedIntegerValue];
|
|
567
567
|
NSString *title = [NSString stringWithFormat:@"%@%@%@ · %@ · %@ · %@%@",
|
|
568
568
|
approval ? @"⚠️ " : @"",
|
|
@@ -597,6 +597,7 @@
|
|
|
597
597
|
}
|
|
598
598
|
// 状态卡:左内边距 20 + 文字 + 间隙 8 + 图标 34 + 右内边距 14。
|
|
599
599
|
- (void)resizeStatusCardToFitText {
|
|
600
|
+
if (!self.statusPanel) return;
|
|
600
601
|
const CGFloat leading = 20, gap = 8, iconWidth = 34, trailing = 14;
|
|
601
602
|
// 副行没内容时收成单行,而不是留一块空白。
|
|
602
603
|
//
|
|
@@ -611,13 +612,9 @@
|
|
|
611
612
|
}
|
|
612
613
|
CGFloat glassWidth = leading + textWidth + gap + iconWidth + trailing;
|
|
613
614
|
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
615
|
NSSize panelSize = NSMakeSize(glassWidth + 12, height + 12);
|
|
619
|
-
|
|
620
|
-
self.statusPanel
|
|
616
|
+
// 文字未变化时也重新应用比例,滑动条缩放不能被原来的尺寸早退跳过。
|
|
617
|
+
PetResizeBubblePanel(self.statusPanel, panelSize);
|
|
621
618
|
self.statusGlass.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
622
619
|
self.statusGlass.cornerRadius = height / 2.0;
|
|
623
620
|
self.statusShadowView.frame = NSMakeRect(6, 6, glassWidth, height);
|
|
@@ -639,6 +636,7 @@
|
|
|
639
636
|
self.statusIconButton.frame = NSMakeRect(glassWidth - trailing - iconWidth,
|
|
640
637
|
(height - iconWidth) / 2.0, iconWidth, iconWidth);
|
|
641
638
|
self.statusClickButton.frame = NSMakeRect(6, 6, glassWidth - 56, height);
|
|
639
|
+
[self layoutApprovalBadge];
|
|
642
640
|
}
|
|
643
641
|
// 面板底边到"最小那颗圆点底边"的距离。定位要拿它反推面板该放多高,
|
|
644
642
|
// 才能让圆点正好落在宠物头顶而不是悬在空中。
|
|
@@ -647,8 +645,9 @@
|
|
|
647
645
|
NSRect visible = (self.panel.screen ?: NSScreen.mainScreen).visibleFrame;
|
|
648
646
|
NSSize size = self.statusPanel.frame.size;
|
|
649
647
|
CGFloat x = NSMidX(petFrame) - size.width / 2.0;
|
|
650
|
-
CGFloat
|
|
651
|
-
CGFloat
|
|
648
|
+
CGFloat gap = 8 * CCPetsBubbleScalePreference();
|
|
649
|
+
CGFloat aboveY = NSMaxY(petFrame) + gap;
|
|
650
|
+
CGFloat belowY = NSMinY(petFrame) - size.height - gap;
|
|
652
651
|
BOOL aboveFits = aboveY + size.height <= NSMaxY(visible) - 10;
|
|
653
652
|
BOOL belowFits = belowY >= NSMinY(visible) + 10;
|
|
654
653
|
self.statusBubbleAbove = aboveFits || !belowFits;
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
successMessage:(NSString *)successMessage {
|
|
10
10
|
NSDictionary<NSString *, NSString *> *locator = CCBridgeCLILocator();
|
|
11
11
|
if (!locator) {
|
|
12
|
-
[self showAlertWithTitle
|
|
13
|
-
message
|
|
12
|
+
[self showAlertWithTitle:L(@"Can't Change CC Bridge Settings")
|
|
13
|
+
message:L(@"The cc-pets command-line tool wasn't found. Run cc-pets install in a terminal, then try again.")];
|
|
14
14
|
[self syncBridgeSwitch:sender];
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
}
|
|
50
50
|
[strongSelf syncBridgeSwitch:sender];
|
|
51
51
|
NSString *detail = [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
52
|
-
[strongSelf showAlertWithTitle
|
|
53
|
-
message:detail.length > 0 ? detail : @"
|
|
52
|
+
[strongSelf showAlertWithTitle:L(@"CC Bridge Setup Failed")
|
|
53
|
+
message:detail.length > 0 ? detail : L(@"The command failed.")];
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
56
|
NSError *error = nil;
|
|
57
57
|
if (![task launchAndReturnError:&error]) {
|
|
58
58
|
self.bridgeCommandRunning = NO;
|
|
59
59
|
[self syncBridgeSwitch:sender];
|
|
60
|
-
[self showAlertWithTitle
|
|
60
|
+
[self showAlertWithTitle:L(@"CC Bridge Setup Failed") message:error.localizedDescription];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
// 与其他菜单开关一致:目标状态按"实际存储的状态取反"算,不信任开关视图自己翻转后的 state——
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
BOOL enable = [self targetBridgeStateForSwitch:sender];
|
|
93
93
|
[self runBridgeCommand:@[enable ? @"enable" : @"disable"] sender:sender
|
|
94
94
|
successMessage:enable
|
|
95
|
-
? @"
|
|
96
|
-
: @"
|
|
95
|
+
? L(@"Enabled. Running Codex sessions need a restart and must be trusted in /hooks; Claude sessions get the cc-bridge tools after a restart.")
|
|
96
|
+
: L(@"Disabled. The related hooks and MCP registrations were removed.")];
|
|
97
97
|
}
|
|
98
98
|
// 一个分组同时作用于 Codex 免审批与 Claude 免确认:菜单上只有一组开关,两边保持一致。
|
|
99
99
|
- (void)toggleBridgeApproval:(NSButton *)sender {
|
|
@@ -141,8 +141,8 @@
|
|
|
141
141
|
[defaults setBool:granted forKey:BridgeNotificationKey];
|
|
142
142
|
sender.state = granted ? NSControlStateValueOn : NSControlStateValueOff;
|
|
143
143
|
if (!granted) {
|
|
144
|
-
[self showAlertWithTitle
|
|
145
|
-
@"
|
|
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
146
|
}
|
|
147
147
|
});
|
|
148
148
|
}];
|
|
@@ -196,9 +196,9 @@
|
|
|
196
196
|
NSDictionary *latest = fresh.firstObject;
|
|
197
197
|
NSString *body = fresh.count == 1
|
|
198
198
|
? [NSString stringWithFormat:@"%@ → %@", latest[@"from"], latest[@"to"]]
|
|
199
|
-
: [NSString stringWithFormat
|
|
199
|
+
: [NSString stringWithFormat:L(@"%1$@ → %2$@ and %3$lu more"), latest[@"from"], latest[@"to"],
|
|
200
200
|
(unsigned long)fresh.count];
|
|
201
|
-
[self sendNotificationWithTitle
|
|
201
|
+
[self sendNotificationWithTitle:L(@"New CC Bridge Message") body:body];
|
|
202
202
|
}
|
|
203
203
|
// 蓝色 = 有新的跨会话消息送达;橙色 = 有消息卡在某个会话的信箱里(那个 Claude 会话长时间空闲、
|
|
204
204
|
// 唤醒 watcher 已退出,要等用户在那个终端开口才会送进去),需要用户过去看一眼。
|
|
@@ -269,11 +269,13 @@
|
|
|
269
269
|
}
|
|
270
270
|
- (void)addBridgeItemsToMenu:(NSMenu *)menu deliveries:(NSArray<NSDictionary *> *)deliveries
|
|
271
271
|
pending:(NSDictionary<NSString *, NSNumber *> *)pending {
|
|
272
|
-
NSMenuItem *heading = [menu addItemWithTitle
|
|
272
|
+
NSMenuItem *heading = [menu addItemWithTitle:L(@"CC Bridge Messages") action:nil keyEquivalent:@""];
|
|
273
273
|
heading.enabled = NO;
|
|
274
274
|
[pending enumerateKeysAndObjectsUsingBlock:^(NSString *session, NSNumber *count, BOOL *stop) {
|
|
275
275
|
NSString *name = self.bridgeSessions[session][@"name"] ?: session;
|
|
276
|
-
NSString *title = [NSString stringWithFormat
|
|
276
|
+
NSString *title = [NSString stringWithFormat:count.unsignedLongValue != 1
|
|
277
|
+
? L(@"📬 %1$@ has %2$lu undelivered messages (say anything in that terminal to deliver)")
|
|
278
|
+
: L(@"📬 %1$@ has %2$lu undelivered message (say anything in that terminal to deliver)"),
|
|
277
279
|
name, count.unsignedLongValue];
|
|
278
280
|
NSMenuItem *item = [menu addItemWithTitle:title action:@selector(focusBridgeSession:) keyEquivalent:@""];
|
|
279
281
|
item.target = self;
|
|
@@ -291,7 +293,7 @@
|
|
|
291
293
|
NSMenuItem *item = [menu addItemWithTitle:title action:@selector(focusBridgeSession:) keyEquivalent:@""];
|
|
292
294
|
item.target = self;
|
|
293
295
|
item.representedObject = delivery[@"toSession"];
|
|
294
|
-
item.toolTip = [NSString stringWithFormat
|
|
296
|
+
item.toolTip = [NSString stringWithFormat:L(@"Jump to %@'s terminal"), delivery[@"to"]];
|
|
295
297
|
}
|
|
296
298
|
}
|
|
297
299
|
@end
|
|
@@ -122,13 +122,11 @@
|
|
|
122
122
|
|
|
123
123
|
[NSApp activateIgnoringOtherApps:YES];
|
|
124
124
|
NSAlert *alert = [NSAlert new];
|
|
125
|
-
alert.messageText = @"
|
|
126
|
-
alert.informativeText = @"
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
[alert addButtonWithTitle
|
|
130
|
-
[alert addButtonWithTitle:@"打开素材目录"];
|
|
131
|
-
[alert addButtonWithTitle:@"退出"];
|
|
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 pets” in the right-click menu. Then click “Rescan”.");
|
|
127
|
+
[alert addButtonWithTitle:L(@"Rescan")];
|
|
128
|
+
[alert addButtonWithTitle:L(@"Open Pets Folder")];
|
|
129
|
+
[alert addButtonWithTitle:L(@"Quit")];
|
|
132
130
|
NSModalResponse response = [alert runModal];
|
|
133
131
|
if (response == NSAlertSecondButtonReturn) {
|
|
134
132
|
NSString *directory = OwnPetsDirectory();
|
|
@@ -145,7 +143,7 @@
|
|
|
145
143
|
NSDictionary *option = [self petOptionWithID:petID inOptions:options];
|
|
146
144
|
if (!option) return;
|
|
147
145
|
NSInteger spriteRowCount = [option[@"spriteRowCount"] integerValue] ?: 9;
|
|
148
|
-
NSImage *image = LoadPetSpriteImage(option[@"path"],
|
|
146
|
+
NSImage *image = LoadPetSpriteImage(option[@"path"], CCPetsPetDecodeCellSize(), spriteRowCount);
|
|
149
147
|
if (!image) return;
|
|
150
148
|
[self.petView applySheet:image petID:petID rowCount:spriteRowCount];
|
|
151
149
|
PetPhrasesSetCurrentPetID(petID);
|
|
@@ -168,8 +166,8 @@
|
|
|
168
166
|
|
|
169
167
|
NSError *error = nil;
|
|
170
168
|
if (![NSFileManager.defaultManager removeItemAtPath:directory error:&error]) {
|
|
171
|
-
[self showAlertWithTitle
|
|
172
|
-
message:error.localizedDescription ?: @"
|
|
169
|
+
[self showAlertWithTitle:L(@"Can't Delete Pet")
|
|
170
|
+
message:error.localizedDescription ?: L(@"Failed to delete the pet folder.")];
|
|
173
171
|
return NO;
|
|
174
172
|
}
|
|
175
173
|
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// 共享常量、共用的小控件类,以及跨文件调用的方法声明。只给 AppDelegate 自己的实现文件 import。
|
|
3
3
|
#import "CCPetsAppDelegate.h"
|
|
4
4
|
#import "CCPetsPaths.h"
|
|
5
|
+
#import "CCPetsL10n.h"
|
|
5
6
|
#import "CCPetsVersion.h"
|
|
6
7
|
#import "CCPetsEvents.h"
|
|
7
8
|
#import "CCPetsQuotaHistory.h"
|
|
8
9
|
#import "CCPetsImageLoader.h"
|
|
10
|
+
#import "CCPetsPetSize.h"
|
|
9
11
|
#import "CCPetsPhrases.h"
|
|
10
12
|
#import "CCPetsPhrasesEditor.h"
|
|
11
13
|
#import "CCPetsUsage.h"
|
|
@@ -101,6 +103,22 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
101
103
|
return ceil(label.fittingSize.width) + 2;
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// 文案、玻璃与按钮仍使用原来的逻辑坐标,只缩小窗口与根视图的 frame。
|
|
107
|
+
// bounds 保留原尺寸,AppKit 会同步转换绘制和命中坐标,避免文字被小外壳裁掉。
|
|
108
|
+
static inline void PetResizeBubblePanel(NSPanel *panel, NSSize logicalSize) {
|
|
109
|
+
if (!panel) return;
|
|
110
|
+
CGFloat scale = CCPetsBubbleScalePreference();
|
|
111
|
+
NSSize size = NSMakeSize(logicalSize.width * scale, logicalSize.height * scale);
|
|
112
|
+
NSView *root = panel.contentView;
|
|
113
|
+
BOOL autoresizes = root.autoresizesSubviews;
|
|
114
|
+
root.autoresizesSubviews = NO;
|
|
115
|
+
[panel setContentSize:size];
|
|
116
|
+
root.frame = NSMakeRect(0, 0, size.width, size.height);
|
|
117
|
+
root.bounds = NSMakeRect(0, 0, logicalSize.width, logicalSize.height);
|
|
118
|
+
root.autoresizesSubviews = autoresizes;
|
|
119
|
+
root.needsDisplay = YES;
|
|
120
|
+
}
|
|
121
|
+
|
|
104
122
|
@interface CCPetsStatusClickButton : NSButton
|
|
105
123
|
@end
|
|
106
124
|
|
|
@@ -127,6 +145,8 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
127
145
|
|
|
128
146
|
// 右键菜单里的各项设置开关
|
|
129
147
|
@interface AppDelegate (Settings)
|
|
148
|
+
- (void)applyPetSizePreference;
|
|
149
|
+
- (void)setPetSizeFromSlider:(NSSlider *)sender;
|
|
130
150
|
- (void)toggleSystemMetric:(NSButton *)sender;
|
|
131
151
|
- (void)setUsageDisplayModeFromControl:(NSButton *)sender;
|
|
132
152
|
- (NSString *)systemMetricKeyForTag:(NSInteger)tag;
|
|
@@ -140,11 +160,14 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
140
160
|
- (void)setGlassDimLevel:(MenuChoiceRowView *)sender;
|
|
141
161
|
- (void)toggleSpeech:(NSButton *)sender;
|
|
142
162
|
- (void)togglePetInteraction:(NSButton *)sender;
|
|
143
|
-
- (void)setPetInteractionHeartThreshold:(
|
|
144
|
-
- (void)setPetInteractionAnnoyedThreshold:(
|
|
145
|
-
- (void)setPetInteractionInterval:(
|
|
146
|
-
- (void)setSpeechFrequency:(
|
|
163
|
+
- (void)setPetInteractionHeartThreshold:(MenuChoiceRowView *)sender;
|
|
164
|
+
- (void)setPetInteractionAnnoyedThreshold:(MenuChoiceRowView *)sender;
|
|
165
|
+
- (void)setPetInteractionInterval:(MenuChoiceRowView *)sender;
|
|
166
|
+
- (void)setSpeechFrequency:(MenuChoiceRowView *)sender;
|
|
167
|
+
- (void)setPhrasesSource:(MenuChoiceRowView *)sender;
|
|
147
168
|
- (void)editPhrasesFile:(id)sender;
|
|
169
|
+
- (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender;
|
|
170
|
+
- (void)languageDidChange:(NSNotification *)notification;
|
|
148
171
|
- (void)toggleNotification:(NSButton *)sender;
|
|
149
172
|
@end
|
|
150
173
|
|
|
@@ -302,16 +325,17 @@ static inline CGFloat PetMeasuredLabelWidth(NSTextField *label) {
|
|
|
302
325
|
- (void)retryUpdate:(NSArray *)context;
|
|
303
326
|
- (void)startUpdateToVersion:(NSString *)version attempt:(NSInteger)attempt;
|
|
304
327
|
- (void)showAboutPanel:(id)sender;
|
|
305
|
-
- (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version,
|
|
306
|
-
|
|
328
|
+
- (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSString *notes,
|
|
329
|
+
NSString *errorMessage))completion;
|
|
330
|
+
- (void)fetchReleaseNotesForVersion:(NSString *)version sourceIndex:(NSUInteger)index
|
|
331
|
+
completion:(void (^)(NSString *body))completion;
|
|
307
332
|
- (void)checkForUpdates:(id)sender;
|
|
308
333
|
- (void)showPendingUpdate:(id)sender;
|
|
309
334
|
- (void)silentCheckForUpdate;
|
|
310
|
-
- (void)rememberPendingUpdate:(NSString *)version
|
|
311
|
-
truncated:(BOOL)truncated;
|
|
335
|
+
- (void)rememberPendingUpdate:(NSString *)version notes:(NSString *)notes;
|
|
312
336
|
- (void)refreshUpdateBadge;
|
|
313
337
|
- (void)clearPendingUpdate;
|
|
314
|
-
- (NSView *)updateHighlightsAccessoryView;
|
|
338
|
+
- (NSView *)updateHighlightsAccessoryView:(NSArray<NSString *> *)highlights truncated:(BOOL)truncated;
|
|
315
339
|
- (void)showUpdateDialog;
|
|
316
340
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
|
|
317
341
|
- (void)applyUpdateBadgeStyle;
|
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
// 右键菜单里的各项设置开关。
|
|
2
2
|
#import "CCPetsAppDelegate+Private.h"
|
|
3
|
+
#import <math.h>
|
|
3
4
|
|
|
4
5
|
@implementation AppDelegate (Settings)
|
|
6
|
+
- (void)setPetSizeFromSlider:(NSSlider *)sender {
|
|
7
|
+
double scale = round(sender.doubleValue * 100) / 100;
|
|
8
|
+
if (!isfinite(scale)) return;
|
|
9
|
+
scale = MAX(CCPetsPetMinimumScale, MIN(CCPetsPetMaximumScale, scale));
|
|
10
|
+
sender.doubleValue = scale;
|
|
11
|
+
[NSUserDefaults.standardUserDefaults setDouble:scale forKey:CCPetsPetScaleKey];
|
|
12
|
+
[self applyPetSizePreference];
|
|
13
|
+
}
|
|
14
|
+
- (void)applyPetSizePreference {
|
|
15
|
+
if (!self.petView || !self.panel) return;
|
|
16
|
+
CGFloat scale = CCPetsPetScalePreference();
|
|
17
|
+
NSRect oldPet = [self.panel convertRectToScreen:self.petView.frame];
|
|
18
|
+
NSSize petSize = NSMakeSize(140 * scale + 4, 150 * scale);
|
|
19
|
+
NSSize panelSize = NSMakeSize(MAX(230, petSize.width + 86), petSize.height + 20);
|
|
20
|
+
// 脚底中心的屏幕坐标保持不变;透明余量继续留给拖动滞后和呼吸动画。
|
|
21
|
+
NSRect panelFrame = NSMakeRect(NSMidX(oldPet) - panelSize.width / 2,
|
|
22
|
+
NSMinY(oldPet), panelSize.width, panelSize.height);
|
|
23
|
+
[self.panel setFrame:panelFrame display:NO];
|
|
24
|
+
self.petView.frame = NSMakeRect((panelSize.width - petSize.width) / 2,
|
|
25
|
+
0, petSize.width, petSize.height);
|
|
26
|
+
[self.petView displayIfNeeded];
|
|
27
|
+
[self.updateBadgeView setFrameOrigin:NSMakePoint(NSMaxX(self.petView.frame) - 30,
|
|
28
|
+
NSMaxY(self.petView.frame) - 28)];
|
|
29
|
+
// 只更新已创建的气泡;独立消息气泡仍在首次播报时按需创建。
|
|
30
|
+
[self resizeStatusCardToFitText];
|
|
31
|
+
[self resizeSpeechBubbleToFitText];
|
|
32
|
+
[self.statusPanel.contentView displayIfNeeded];
|
|
33
|
+
[self.speechPanel.contentView displayIfNeeded];
|
|
34
|
+
[self petWindowDidMove:nil];
|
|
35
|
+
}
|
|
5
36
|
- (NSString *)systemMetricKeyForTag:(NSInteger)tag {
|
|
6
37
|
if (tag == 1) return SystemCPUEnabledKey;
|
|
7
38
|
if (tag == 2) return SystemTemperatureEnabledKey;
|
|
@@ -60,8 +91,8 @@
|
|
|
60
91
|
- (void)showImportedCodexPetsAlert:(NSUInteger)imported {
|
|
61
92
|
[NSApp activateIgnoringOtherApps:YES];
|
|
62
93
|
NSAlert *alert = [NSAlert new];
|
|
63
|
-
alert.messageText = @"
|
|
64
|
-
[alert addButtonWithTitle
|
|
94
|
+
alert.messageText = L(@"Codex Pets Imported");
|
|
95
|
+
[alert addButtonWithTitle:L(@"OK")];
|
|
65
96
|
[alert runModal];
|
|
66
97
|
}
|
|
67
98
|
- (NSString *)notificationKeyForTag:(NSInteger)tag {
|
|
@@ -135,13 +166,13 @@
|
|
|
135
166
|
[defaults setBool:enabled forKey:PetInteractionEnabledKey];
|
|
136
167
|
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
137
168
|
}
|
|
138
|
-
- (void)setPetInteractionHeartThreshold:(
|
|
169
|
+
- (void)setPetInteractionHeartThreshold:(MenuChoiceRowView *)sender {
|
|
139
170
|
NSNumber *value = [sender.representedObject isKindOfClass:NSNumber.class] ?
|
|
140
171
|
sender.representedObject : @3;
|
|
141
172
|
[NSUserDefaults.standardUserDefaults setInteger:MAX((NSInteger)2, value.integerValue)
|
|
142
173
|
forKey:PetInteractionHeartThresholdKey];
|
|
143
174
|
}
|
|
144
|
-
- (void)setPetInteractionAnnoyedThreshold:(
|
|
175
|
+
- (void)setPetInteractionAnnoyedThreshold:(MenuChoiceRowView *)sender {
|
|
145
176
|
NSNumber *value = [sender.representedObject isKindOfClass:NSNumber.class] ?
|
|
146
177
|
sender.representedObject : @10;
|
|
147
178
|
NSInteger heart = MAX((NSInteger)2, [NSUserDefaults.standardUserDefaults
|
|
@@ -149,7 +180,7 @@
|
|
|
149
180
|
[NSUserDefaults.standardUserDefaults setInteger:MAX(heart + 1, value.integerValue)
|
|
150
181
|
forKey:PetInteractionAnnoyedThresholdKey];
|
|
151
182
|
}
|
|
152
|
-
- (void)setPetInteractionInterval:(
|
|
183
|
+
- (void)setPetInteractionInterval:(MenuChoiceRowView *)sender {
|
|
153
184
|
NSNumber *value = [sender.representedObject isKindOfClass:NSNumber.class] ?
|
|
154
185
|
sender.representedObject : @1.2;
|
|
155
186
|
[NSUserDefaults.standardUserDefaults setDouble:MAX(0.4, MIN(3.0, value.doubleValue))
|
|
@@ -157,13 +188,37 @@
|
|
|
157
188
|
}
|
|
158
189
|
// 频率档位。改完立刻生效——四道闸都是现读的,不缓存。
|
|
159
190
|
// 顺手把冷却清掉,否则刚调高档位还要等完上一档的冷却才见效,会让人以为没生效。
|
|
160
|
-
- (void)setSpeechFrequency:(
|
|
191
|
+
- (void)setSpeechFrequency:(MenuChoiceRowView *)sender {
|
|
161
192
|
NSString *value = [sender.representedObject isKindOfClass:NSString.class] ?
|
|
162
193
|
sender.representedObject : PetSpeechFrequencyNormal;
|
|
163
194
|
[NSUserDefaults.standardUserDefaults setObject:value forKey:PetSpeechFrequencyKey];
|
|
164
195
|
self.speechCooldownUntil = 0;
|
|
165
196
|
self.lastIdleSpeechCheck = 0;
|
|
166
197
|
}
|
|
198
|
+
- (void)setPhrasesSource:(MenuChoiceRowView *)sender {
|
|
199
|
+
NSString *source = sender.representedObject;
|
|
200
|
+
if (![@[PetPhrasesSourcePet, PetPhrasesSourceDefault] containsObject:source] ||
|
|
201
|
+
[source isEqualToString:PetPhrasesSource()]) return;
|
|
202
|
+
PetPhrasesSetSource(source);
|
|
203
|
+
NSString *tag = self.lastPetVoiceTag;
|
|
204
|
+
self.lastPetVoiceTag = nil;
|
|
205
|
+
self.lastPetVoiceText = nil;
|
|
206
|
+
// 收起旧来源的碎碎念,状态卡副行也立即换成新来源。
|
|
207
|
+
if (!self.updateBubbleVisible) [self hideSpeechBubble];
|
|
208
|
+
if (self.hasAgentStatus && self.lastStatusState.length > 0) {
|
|
209
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
210
|
+
selector:@selector(restoreStatusDetail) object:nil];
|
|
211
|
+
// 保留当前工具对应的小节,不把执行命令、编辑文件等状态退成通用工具态。
|
|
212
|
+
tag = tag ?: [self petVoiceTagForState:self.lastStatusState tool:@""];
|
|
213
|
+
NSString *text = PetPhraseForTag(tag, [self speechSlots]);
|
|
214
|
+
self.lastPetVoiceTag = tag;
|
|
215
|
+
self.lastPetVoiceText = text;
|
|
216
|
+
self.statusDetailLabel.stringValue = text ?: @"";
|
|
217
|
+
[self resizeStatusCardToFitText];
|
|
218
|
+
[self positionAgentStatus];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
167
222
|
// 台词交给内置编辑器,不再 openURL: 丢给"文本编辑"。
|
|
168
223
|
//
|
|
169
224
|
// 换掉的理由是反馈:系统编辑器保存完什么都不会说,小节名拼错、句子超 30 字、槽位
|
|
@@ -196,10 +251,31 @@
|
|
|
196
251
|
} else {
|
|
197
252
|
sender.state = NSControlStateValueOff;
|
|
198
253
|
NSString *message = error.localizedDescription ?:
|
|
199
|
-
@"
|
|
200
|
-
[self showAlertWithTitle
|
|
254
|
+
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.");
|
|
255
|
+
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:message];
|
|
201
256
|
}
|
|
202
257
|
});
|
|
203
258
|
}];
|
|
204
259
|
}
|
|
260
|
+
// 菜单每次右键现建,切换后下次打开就是新语言;这里只刷新常驻的界面。
|
|
261
|
+
- (void)setLanguagePreferenceFromMenu:(NSMenuItem *)sender {
|
|
262
|
+
NSString *preference = [sender.representedObject isKindOfClass:NSString.class] ?
|
|
263
|
+
sender.representedObject : CCPetsLanguageSystem;
|
|
264
|
+
if ([preference isEqualToString:CCPetsLanguagePreference()]) return;
|
|
265
|
+
CCPetsSetLanguagePreference(preference);
|
|
266
|
+
}
|
|
267
|
+
- (void)languageDidChange:(NSNotification *)notification {
|
|
268
|
+
PetPhrasesAdoptLanguageDefaults();
|
|
269
|
+
NSApp.mainMenu = nil;
|
|
270
|
+
[self installEditMenu];
|
|
271
|
+
self.quotaView.needsDisplay = YES;
|
|
272
|
+
// 状态卡标题和副行都是按状态现算的,按最后的状态重排一遍。工具名没留,
|
|
273
|
+
// 工具态会暂时退成"正在使用工具",下一条事件就会补回来。
|
|
274
|
+
if (self.hasAgentStatus && self.lastStatusState.length > 0) {
|
|
275
|
+
[self applyStatusPresentationForState:self.lastStatusState
|
|
276
|
+
provider:self.lastStatusProvider ?: @"Agent" tool:@""];
|
|
277
|
+
}
|
|
278
|
+
// 正在显示的碎碎念是旧语言的,收起即可,下一句自然是新语言。更新提示由更新逻辑自己重排。
|
|
279
|
+
if (!self.updateBubbleVisible) [self hideSpeechBubble];
|
|
280
|
+
}
|
|
205
281
|
@end
|
|
@@ -189,9 +189,10 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
189
189
|
NSSize size = self.speechPanel.frame.size;
|
|
190
190
|
CGFloat x = NSMidX(petFrame) - size.width / 2.0;
|
|
191
191
|
// 头顶放不下就翻到脚下,尾巴跟着改朝向长在顶边。
|
|
192
|
-
CGFloat
|
|
192
|
+
CGFloat inset = 6 * CCPetsBubbleScalePreference();
|
|
193
|
+
CGFloat aboveY = NSMaxY(petFrame) - inset;
|
|
193
194
|
BOOL fitsAbove = aboveY + size.height <= NSMaxY(visible) - 10;
|
|
194
|
-
CGFloat y = fitsAbove ? aboveY : NSMinY(petFrame) - size.height +
|
|
195
|
+
CGFloat y = fitsAbove ? aboveY : NSMinY(petFrame) - size.height + inset;
|
|
195
196
|
x = fmax(NSMinX(visible) + 10, fmin(x, NSMaxX(visible) - size.width - 10));
|
|
196
197
|
y = fmax(NSMinY(visible) + 10, fmin(y, NSMaxY(visible) - size.height - 10));
|
|
197
198
|
[self.speechPanel setFrameOrigin:NSMakePoint(x, y)];
|
|
@@ -270,7 +271,7 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
270
271
|
if (![value isKindOfClass:NSString.class] || [value length] == 0) return;
|
|
271
272
|
[defaults removeObjectForKey:@"CCPetsSpeechDebugTag"];
|
|
272
273
|
NSString *text = PetPhraseForTag(value, [self speechSlots]);
|
|
273
|
-
if (text.length == 0) text = @"
|
|
274
|
+
if (text.length == 0) text = L(@"(No lines available for this tag)");
|
|
274
275
|
[self presentSpeechText:text];
|
|
275
276
|
}
|
|
276
277
|
- (void)hideSpeechBubble {
|
|
@@ -379,14 +380,15 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
379
380
|
}
|
|
380
381
|
// 独立气泡:左右各 16 内边距,没有图标。
|
|
381
382
|
- (void)resizeSpeechBubbleToFitText {
|
|
383
|
+
if (!self.speechPanel) return;
|
|
382
384
|
const CGFloat padding = 16;
|
|
383
385
|
CGFloat width = padding * 2 + PetMeasuredLabelWidth(self.speechLabel);
|
|
384
386
|
width = fmax(96.0, fmin(width, 300.0));
|
|
385
387
|
NSSize panelSize = NSMakeSize(width + 12, PetSpeechBodyHeight + 12);
|
|
386
|
-
|
|
387
|
-
self.speechPanel.contentView.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
388
|
+
PetResizeBubblePanel(self.speechPanel, panelSize);
|
|
388
389
|
self.speechGlass.frame = NSMakeRect(6, 6, width, PetSpeechBodyHeight);
|
|
389
390
|
self.speechGlass.cornerRadius = PetSpeechBodyHeight / 2.0;
|
|
390
391
|
self.speechLabel.frame = NSMakeRect(padding, 10, width - padding * 2, 18);
|
|
392
|
+
self.speechClickButton.frame = self.speechPanel.contentView.bounds;
|
|
391
393
|
}
|
|
392
394
|
@end
|