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
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
#import "CCPetsSettingsPage.h"
|
|
2
|
+
#import "CCPetsBridge.h"
|
|
3
|
+
#import "CCPetsCLISupport.h"
|
|
4
|
+
#import "CCPetsDiagnosticsPage.h"
|
|
5
|
+
#import "CCPetsFormBuilder.h"
|
|
6
|
+
#import "CCPetsGlassView.h"
|
|
7
|
+
#import "CCPetsImageLoader.h"
|
|
8
|
+
#import "CCPetsL10n.h"
|
|
9
|
+
#import "CCPetsPaths.h"
|
|
10
|
+
#import "CCPetsPetSize.h"
|
|
11
|
+
#import "CCPetsPhrases.h"
|
|
12
|
+
#import "CCPetsPreferences.h"
|
|
13
|
+
#import "CCPetsProfiles.h"
|
|
14
|
+
#import "CCPetsUsageMode.h"
|
|
15
|
+
#import "CCPetsUIStyle.h"
|
|
16
|
+
#import <QuartzCore/QuartzCore.h>
|
|
17
|
+
|
|
18
|
+
// 定义在 CCPetsAppDelegate+Speech.m;那边的头文件是 AppDelegate 私有的,这里单独 extern。
|
|
19
|
+
extern NSString *const PetSpeechFrequencyKey;
|
|
20
|
+
|
|
21
|
+
// 控件的 target 只能是对象,用它把 action 转成 block,免得每个控件写一个方法。
|
|
22
|
+
@interface CCPetsSettingsHandler : NSObject
|
|
23
|
+
@property(nonatomic, copy) void (^block)(id sender);
|
|
24
|
+
- (void)invoke:(id)sender;
|
|
25
|
+
@end
|
|
26
|
+
|
|
27
|
+
@implementation CCPetsSettingsHandler
|
|
28
|
+
- (void)invoke:(id)sender {
|
|
29
|
+
if (self.block) self.block(sender);
|
|
30
|
+
}
|
|
31
|
+
@end
|
|
32
|
+
|
|
33
|
+
static NSString *ClickCountText(NSInteger count) {
|
|
34
|
+
return [[NSString stringWithFormat:@"%ld", (long)count] stringByAppendingString:L(@" clicks")];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static void RevealFolder(NSString *path) {
|
|
38
|
+
// 第一次用时文件夹可能还不存在;建出来比让按钮点了没反应好。
|
|
39
|
+
[NSFileManager.defaultManager createDirectoryAtPath:path withIntermediateDirectories:YES
|
|
40
|
+
attributes:nil error:nil];
|
|
41
|
+
[NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:path isDirectory:YES]];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 三个设置页共用:控件绑定、按 defaults 回填、监听设置变更。
|
|
45
|
+
@interface CCPetsSettingsPageBase ()
|
|
46
|
+
@property(nonatomic) CCPetsFormBuilder *form;
|
|
47
|
+
@property(nonatomic) NSMutableArray<CCPetsSettingsHandler *> *handlers;
|
|
48
|
+
// 每个控件一个"按 defaults 回填自己"的 block。设置一变就全部跑一遍。
|
|
49
|
+
@property(nonatomic) NSMutableArray<void (^)(void)> *reloaders;
|
|
50
|
+
@end
|
|
51
|
+
|
|
52
|
+
@implementation CCPetsSettingsPageBase
|
|
53
|
+
|
|
54
|
+
- (id<CCPetsSettingsActions>)actions {
|
|
55
|
+
id delegate = NSApp.delegate;
|
|
56
|
+
return [delegate respondsToSelector:@selector(updatePetScale:)] ? delegate : nil;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (NSString *)pageTitle {
|
|
60
|
+
return @"";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (NSString *)pageSubtitle {
|
|
64
|
+
return @"";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)buildContent {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (void)loadView {
|
|
71
|
+
self.handlers = [NSMutableArray array];
|
|
72
|
+
self.reloaders = [NSMutableArray array];
|
|
73
|
+
self.form = [[CCPetsFormBuilder alloc] initWithTitle:[self pageTitle] subtitle:[self pageSubtitle]];
|
|
74
|
+
self.view = self.form.view;
|
|
75
|
+
[self buildContent];
|
|
76
|
+
[self reloadValues];
|
|
77
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(preferencesDidChange:)
|
|
78
|
+
name:CCPetsPreferencesDidChangeNotification object:nil];
|
|
79
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(preferencesDidChange:)
|
|
80
|
+
name:CCPetsAuthenticationModesDidChangeNotification object:nil];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (void)dealloc {
|
|
84
|
+
[NSNotificationCenter.defaultCenter removeObserver:self];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
- (void)preferencesDidChange:(NSNotification *)notification {
|
|
88
|
+
[self reloadValues];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (void)reloadValues {
|
|
92
|
+
for (void (^reload)(void) in self.reloaders) reload();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
- (void)bind:(NSControl *)control to:(void (^)(id sender))block {
|
|
96
|
+
CCPetsSettingsHandler *handler = [CCPetsSettingsHandler new];
|
|
97
|
+
handler.block = block;
|
|
98
|
+
[self.handlers addObject:handler];
|
|
99
|
+
control.target = handler;
|
|
100
|
+
control.action = @selector(invoke:);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
- (CCPetsSwitch *)switchWithValue:(BOOL (^)(void))value action:(void (^)(CCPetsSwitch *control))action {
|
|
104
|
+
CCPetsSwitch *control = [CCPetsSwitch new];
|
|
105
|
+
[self bind:control to:^(CCPetsSwitch *sender) { action(sender); }];
|
|
106
|
+
[self.reloaders addObject:^{
|
|
107
|
+
control.state = value() ? NSControlStateValueOn : NSControlStateValueOff;
|
|
108
|
+
}];
|
|
109
|
+
return control;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 普通布尔设置:读写同一个键,写完交给 AppDelegate 生效。
|
|
113
|
+
- (NSView *)switchRowWithTitle:(NSString *)title subtitle:(NSString *)subtitle key:(NSString *)key
|
|
114
|
+
apply:(void (^)(id<CCPetsSettingsActions> actions, BOOL enabled))apply {
|
|
115
|
+
__weak typeof(self) weakSelf = self;
|
|
116
|
+
CCPetsSwitch *control = [self switchWithValue:^BOOL { return CCPetsPrefBool(key); }
|
|
117
|
+
action:^(CCPetsSwitch *sender) {
|
|
118
|
+
apply(weakSelf.actions, sender.state == NSControlStateValueOn);
|
|
119
|
+
}];
|
|
120
|
+
return [CCPetsFormBuilder rowWithTitle:title subtitle:subtitle controls:@[control]];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 系统通知要先拿到授权,失败就弹回关闭,所以不能直接用 switchRow。
|
|
124
|
+
- (NSView *)notificationRowWithTitle:(NSString *)title subtitle:(NSString *)subtitle key:(NSString *)key {
|
|
125
|
+
__weak typeof(self) weakSelf = self;
|
|
126
|
+
CCPetsSwitch *control = [self switchWithValue:^BOOL { return CCPetsPrefBool(key); }
|
|
127
|
+
action:^(CCPetsSwitch *sender) {
|
|
128
|
+
[weakSelf.actions updateNotification:key enabled:sender.state == NSControlStateValueOn
|
|
129
|
+
completion:^(BOOL enabled) {
|
|
130
|
+
sender.state = enabled ? NSControlStateValueOn : NSControlStateValueOff;
|
|
131
|
+
}];
|
|
132
|
+
}];
|
|
133
|
+
return [CCPetsFormBuilder rowWithTitle:title subtitle:subtitle controls:@[control]];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
- (NSPopUpButton *)popUpWithOptions:(NSArray<NSArray *> *)options selected:(id (^)(void))selected
|
|
137
|
+
action:(void (^)(id value))action {
|
|
138
|
+
NSPopUpButton *popUp = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
|
|
139
|
+
popUp.controlSize = NSControlSizeSmall;
|
|
140
|
+
popUp.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
141
|
+
for (NSArray *option in options) {
|
|
142
|
+
[popUp addItemWithTitle:option[0]];
|
|
143
|
+
popUp.lastItem.representedObject = option[1];
|
|
144
|
+
}
|
|
145
|
+
[self bind:popUp to:^(NSPopUpButton *sender) { action(sender.selectedItem.representedObject); }];
|
|
146
|
+
[self.reloaders addObject:^{
|
|
147
|
+
id value = selected();
|
|
148
|
+
for (NSMenuItem *item in popUp.itemArray) {
|
|
149
|
+
if (![item.representedObject isEqual:value]) continue;
|
|
150
|
+
[popUp selectItem:item];
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}];
|
|
154
|
+
return popUp;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 档位少(四个以内)的单选用分段控件,一眼看到全部选项;多了再用弹出菜单。
|
|
158
|
+
- (NSSegmentedControl *)segmentedWithOptions:(NSArray<NSArray *> *)options selected:(id (^)(void))selected
|
|
159
|
+
action:(void (^)(id value))action {
|
|
160
|
+
NSMutableArray<NSString *> *labels = [NSMutableArray array];
|
|
161
|
+
for (NSArray *option in options) [labels addObject:option[0]];
|
|
162
|
+
NSSegmentedControl *control = [NSSegmentedControl segmentedControlWithLabels:labels
|
|
163
|
+
trackingMode:NSSegmentSwitchTrackingSelectOne target:nil action:nil];
|
|
164
|
+
control.controlSize = NSControlSizeSmall;
|
|
165
|
+
control.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
166
|
+
CCPetsApplyAccent(control);
|
|
167
|
+
[self bind:control to:^(NSSegmentedControl *sender) {
|
|
168
|
+
if (sender.selectedSegment >= 0) action(options[(NSUInteger)sender.selectedSegment][1]);
|
|
169
|
+
}];
|
|
170
|
+
[self.reloaders addObject:^{
|
|
171
|
+
id value = selected();
|
|
172
|
+
for (NSUInteger index = 0; index < options.count; index++) {
|
|
173
|
+
if ([options[index][1] isEqual:value]) control.selectedSegment = (NSInteger)index;
|
|
174
|
+
}
|
|
175
|
+
}];
|
|
176
|
+
return control;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 步进器 + 数值标签。菜单里只有三档,这里可以连续调。
|
|
180
|
+
- (NSView *)stepperRowWithTitle:(NSString *)title key:(NSString *)key minimum:(double)minimum
|
|
181
|
+
maximum:(double)maximum increment:(double)increment fallback:(double)fallback
|
|
182
|
+
format:(NSString *(^)(double value))format {
|
|
183
|
+
NSStepper *stepper = [NSStepper new];
|
|
184
|
+
stepper.controlSize = NSControlSizeSmall;
|
|
185
|
+
stepper.minValue = minimum;
|
|
186
|
+
stepper.maxValue = maximum;
|
|
187
|
+
stepper.increment = increment;
|
|
188
|
+
stepper.valueWraps = NO;
|
|
189
|
+
NSTextField *valueLabel = CCPetsNumberLabel(@"", 12, NSFontWeightRegular, CCPetsInkColor());
|
|
190
|
+
valueLabel.alignment = NSTextAlignmentRight;
|
|
191
|
+
[valueLabel.widthAnchor constraintGreaterThanOrEqualToConstant:52].active = YES;
|
|
192
|
+
__weak typeof(self) weakSelf = self;
|
|
193
|
+
[self bind:stepper to:^(NSStepper *sender) {
|
|
194
|
+
// 步进 0.1 的浮点累加会出现 1.2000000002,按步长取整再交出去。
|
|
195
|
+
double value = round(sender.doubleValue / increment) * increment;
|
|
196
|
+
[weakSelf.actions updatePetInteractionValue:@(value) forKey:key];
|
|
197
|
+
}];
|
|
198
|
+
[self.reloaders addObject:^{
|
|
199
|
+
id stored = [NSUserDefaults.standardUserDefaults objectForKey:key];
|
|
200
|
+
double value = [stored isKindOfClass:NSNumber.class] ? [stored doubleValue] : fallback;
|
|
201
|
+
// 生气阈值的下限跟着比心阈值走,和 CCPetsPrefNormalizedValue 的钳制一致。
|
|
202
|
+
if ([key isEqualToString:PetInteractionAnnoyedThresholdKey]) {
|
|
203
|
+
stepper.minValue = MAX((NSInteger)2, [NSUserDefaults.standardUserDefaults
|
|
204
|
+
integerForKey:PetInteractionHeartThresholdKey]) + 1;
|
|
205
|
+
}
|
|
206
|
+
stepper.doubleValue = value;
|
|
207
|
+
valueLabel.stringValue = format(value);
|
|
208
|
+
}];
|
|
209
|
+
return [CCPetsFormBuilder rowWithTitle:title controls:@[valueLabel, stepper]];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
- (NSButton *)smallButtonWithTitle:(NSString *)title action:(void (^)(void))action {
|
|
213
|
+
NSButton *button = [NSButton buttonWithTitle:title target:nil action:nil];
|
|
214
|
+
button.controlSize = NSControlSizeSmall;
|
|
215
|
+
button.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
216
|
+
[self bind:button to:^(id sender) { action(); }];
|
|
217
|
+
return button;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
- (NSSlider *)sliderWithMinimum:(double)minimum maximum:(double)maximum width:(CGFloat)width {
|
|
221
|
+
NSSlider *slider = [NSSlider sliderWithValue:minimum minValue:minimum maxValue:maximum target:nil action:nil];
|
|
222
|
+
slider.continuous = YES;
|
|
223
|
+
slider.controlSize = NSControlSizeSmall;
|
|
224
|
+
CCPetsApplyAccent(slider);
|
|
225
|
+
[slider.widthAnchor constraintEqualToConstant:width].active = YES;
|
|
226
|
+
return slider;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
- (NSTextField *)sliderValueLabel {
|
|
230
|
+
NSTextField *label = CCPetsNumberLabel(@"", 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
231
|
+
label.alignment = NSTextAlignmentRight;
|
|
232
|
+
[label.widthAnchor constraintEqualToConstant:40].active = YES;
|
|
233
|
+
return label;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@end
|
|
237
|
+
|
|
238
|
+
#pragma mark - 多账号
|
|
239
|
+
|
|
240
|
+
@interface CCPetsAccountsPage ()
|
|
241
|
+
// 上次建页时的账号与集成状态;没变就不重建,免得切页、回到前台时整页闪一下。
|
|
242
|
+
@property(nonatomic, copy) NSArray<NSDictionary *> *entries;
|
|
243
|
+
// 控件回调(弹出菜单、确认框、选文件面板)期间主队列照样会跑,这时重建会释放正在执行的
|
|
244
|
+
// 闭包和弹出菜单所依附的按钮,只记下来,等回调返回后再建。
|
|
245
|
+
@property(nonatomic) NSInteger interactionDepth;
|
|
246
|
+
@property(nonatomic) BOOL needsRebuild;
|
|
247
|
+
@end
|
|
248
|
+
|
|
249
|
+
@implementation CCPetsAccountsPage
|
|
250
|
+
|
|
251
|
+
- (NSString *)pageTitle {
|
|
252
|
+
return L(@"Multi-Account");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
- (NSString *)pageSubtitle {
|
|
256
|
+
return L(@"Add and manage Claude and Codex Homes.");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
- (void)loadView {
|
|
260
|
+
[super loadView];
|
|
261
|
+
// 集成状态还取决于 CC Bridge 开关和各 Home 的配置文件:诊断修复、命令行改动之后回到 App 时也要重读。
|
|
262
|
+
for (NSNotificationName name in @[CCPetsProfilesDidChangeNotification, CCPetsDiagnosticsDidChangeNotification,
|
|
263
|
+
NSApplicationDidBecomeActiveNotification]) {
|
|
264
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(profilesDidChange:)
|
|
265
|
+
name:name object:nil];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
- (void)viewWillAppear {
|
|
270
|
+
[super viewWillAppear];
|
|
271
|
+
[self profilesDidChange:nil];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
- (void)profilesDidChange:(NSNotification *)notification {
|
|
275
|
+
if (notification && !self.view.window) return;
|
|
276
|
+
if (self.interactionDepth > 0) {
|
|
277
|
+
self.needsRebuild = YES;
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if ([self.entries isEqualToArray:[self currentEntries]]) return;
|
|
281
|
+
[self.handlers removeAllObjects];
|
|
282
|
+
[self.reloaders removeAllObjects];
|
|
283
|
+
[self.form removeAllContent];
|
|
284
|
+
[self buildContent];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
- (NSArray<NSDictionary *> *)currentEntries {
|
|
288
|
+
NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];
|
|
289
|
+
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
290
|
+
[entries addObject:@{@"profile": profile, @"state": CCPetsProfileStatus(profile)[@"state"] ?: @""}];
|
|
291
|
+
}
|
|
292
|
+
return entries.copy;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
- (void)bind:(NSControl *)control to:(void (^)(id sender))block {
|
|
296
|
+
__weak typeof(self) weakSelf = self;
|
|
297
|
+
[super bind:control to:^(id sender) {
|
|
298
|
+
typeof(self) strongSelf = weakSelf;
|
|
299
|
+
strongSelf.interactionDepth++;
|
|
300
|
+
block(sender);
|
|
301
|
+
strongSelf.interactionDepth--;
|
|
302
|
+
if (strongSelf.interactionDepth > 0 || !strongSelf.needsRebuild) return;
|
|
303
|
+
strongSelf.needsRebuild = NO;
|
|
304
|
+
// 下一轮再建:现在还在这个控件的闭包里。
|
|
305
|
+
dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf profilesDidChange:nil]; });
|
|
306
|
+
}];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
- (NSButton *)manageButtonForProfile:(NSDictionary *)profile {
|
|
310
|
+
__weak typeof(self) weakSelf = self;
|
|
311
|
+
NSButton *button = [NSButton buttonWithTitle:L(@"Manage…") target:nil action:nil];
|
|
312
|
+
button.controlSize = NSControlSizeSmall;
|
|
313
|
+
button.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
314
|
+
[self bind:button to:^(NSButton *sender) {
|
|
315
|
+
NSMenu *menu = [NSMenu new];
|
|
316
|
+
NSMutableArray<NSArray *> *actions = [@[
|
|
317
|
+
@[L(@"Repair Integration"), NSStringFromSelector(@selector(repairAgentProfile:))],
|
|
318
|
+
@[L(@"Rename…"), NSStringFromSelector(@selector(renameAgentProfile:))]
|
|
319
|
+
] mutableCopy];
|
|
320
|
+
if (!CCPetsProfileIsOfficialDefault(profile)) {
|
|
321
|
+
[actions addObject:@[L(@"Relocate Home…"), NSStringFromSelector(@selector(relocateAgentProfile:))]];
|
|
322
|
+
[actions addObject:@[L(@"Remove Integration…"), NSStringFromSelector(@selector(removeAgentProfile:))]];
|
|
323
|
+
}
|
|
324
|
+
for (NSArray *action in actions) {
|
|
325
|
+
NSMenuItem *item = [menu addItemWithTitle:action[0]
|
|
326
|
+
action:NSSelectorFromString(action[1]) keyEquivalent:@""];
|
|
327
|
+
item.target = weakSelf.actions;
|
|
328
|
+
item.representedObject = profile[@"id"];
|
|
329
|
+
}
|
|
330
|
+
[menu popUpMenuPositioningItem:nil atLocation:NSMakePoint(0, NSMaxY(sender.bounds)) inView:sender];
|
|
331
|
+
}];
|
|
332
|
+
return button;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
- (void)buildContent {
|
|
336
|
+
__weak typeof(self) weakSelf = self;
|
|
337
|
+
[self.form setAccessoryViews:@[
|
|
338
|
+
[self smallButtonWithTitle:L(@"Add Claude Home…") action:^{ [weakSelf.actions addClaudeProfile:nil]; }],
|
|
339
|
+
[self smallButtonWithTitle:L(@"Add Codex Home…") action:^{ [weakSelf.actions addCodexProfile:nil]; }]
|
|
340
|
+
]];
|
|
341
|
+
self.entries = [self currentEntries];
|
|
342
|
+
if (self.entries.count == 0) {
|
|
343
|
+
[self.form addGroupWithTitle:nil rows:@[
|
|
344
|
+
[CCPetsFormBuilder rowWithTitle:L(@"No Agent accounts detected")
|
|
345
|
+
subtitle:L(@"Use the buttons above to add an existing Claude or Codex Home.") controls:@[]]
|
|
346
|
+
] footer:nil];
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
for (NSString *provider in @[CCPetsProfileProviderClaude, CCPetsProfileProviderCodex]) {
|
|
350
|
+
NSMutableArray<NSView *> *rows = [NSMutableArray array];
|
|
351
|
+
for (NSDictionary *entry in self.entries) {
|
|
352
|
+
NSDictionary *profile = entry[@"profile"];
|
|
353
|
+
if (![profile[@"provider"] isEqualToString:provider]) continue;
|
|
354
|
+
NSString *state = entry[@"state"];
|
|
355
|
+
NSColor *color = [state isEqualToString:CCPetsProfileStateIntegrated]
|
|
356
|
+
? CCPetsSecondaryInkColor() : NSColor.systemOrangeColor;
|
|
357
|
+
NSTextField *label = CCPetsLabel(CCPetsProfileStateTitle(state), 11, NSFontWeightRegular, color);
|
|
358
|
+
NSView *row = [CCPetsFormBuilder rowWithTitle:profile[@"displayName"] ?: profile[@"slug"]
|
|
359
|
+
subtitle:CCPetsTildePath(profile[@"home"])
|
|
360
|
+
controls:@[label, [self manageButtonForProfile:profile]]];
|
|
361
|
+
row.toolTip = profile[@"home"];
|
|
362
|
+
[rows addObject:row];
|
|
363
|
+
}
|
|
364
|
+
if (rows.count > 0) [self.form addGroupWithTitle:
|
|
365
|
+
[provider isEqualToString:CCPetsProfileProviderClaude] ? @"Claude" : @"Codex" rows:rows footer:nil];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
@end
|
|
370
|
+
|
|
371
|
+
#pragma mark - 宠物
|
|
372
|
+
|
|
373
|
+
@interface CCPetsPetPage ()
|
|
374
|
+
@property(nonatomic) NSStackView *pickerRows;
|
|
375
|
+
@property(nonatomic) NSMutableDictionary<NSString *, CCPetsTileView *> *petTiles;
|
|
376
|
+
@property(nonatomic) NSMutableDictionary<NSString *, CCPetsSpriteView *> *petSprites;
|
|
377
|
+
@property(nonatomic) NSMutableDictionary<NSString *, NSImage *> *sheetCache;
|
|
378
|
+
@property(nonatomic) NSTextField *sampleLine;
|
|
379
|
+
@end
|
|
380
|
+
|
|
381
|
+
// 选择列表一行几只。窗口最窄时(内容区约 520pt)每张卡也有 110pt 以上,名字放得下。
|
|
382
|
+
static const NSUInteger PetPickerColumns = 4;
|
|
383
|
+
|
|
384
|
+
@implementation CCPetsPetPage
|
|
385
|
+
|
|
386
|
+
- (NSString *)pageTitle {
|
|
387
|
+
return L(@"Pet");
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
- (NSString *)pageSubtitle {
|
|
391
|
+
return L(@"Pick the pet that lives on your desktop, its size, how chatty it is and how it reacts when poked.");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
- (void)loadView {
|
|
395
|
+
self.petTiles = [NSMutableDictionary dictionary];
|
|
396
|
+
self.petSprites = [NSMutableDictionary dictionary];
|
|
397
|
+
self.sheetCache = [NSMutableDictionary dictionary];
|
|
398
|
+
[super loadView];
|
|
399
|
+
// 切宠物不走 defaults 写入口(选中项记在桌宠自己身上),靠名片通知得知换了。
|
|
400
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(petDidChange:)
|
|
401
|
+
name:CCPetsPetCardDidChangeNotification object:nil];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
- (void)petDidChange:(NSNotification *)notification {
|
|
405
|
+
[self updatePetSelection];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
- (void)buildContent {
|
|
409
|
+
__weak typeof(self) weakSelf = self;
|
|
410
|
+
|
|
411
|
+
NSStackView *rows = [NSStackView stackViewWithViews:@[]];
|
|
412
|
+
rows.orientation = NSUserInterfaceLayoutOrientationVertical;
|
|
413
|
+
rows.alignment = NSLayoutAttributeLeading;
|
|
414
|
+
rows.spacing = 10;
|
|
415
|
+
self.pickerRows = rows;
|
|
416
|
+
[self.form addView:rows];
|
|
417
|
+
[self rebuildPicker];
|
|
418
|
+
|
|
419
|
+
// 大小
|
|
420
|
+
NSSlider *scale = [self sliderWithMinimum:CCPetsPetMinimumScale maximum:CCPetsPetMaximumScale width:200];
|
|
421
|
+
NSTextField *scaleLabel = [self sliderValueLabel];
|
|
422
|
+
[self bind:scale to:^(NSSlider *sender) { [weakSelf.actions updatePetScale:sender.doubleValue]; }];
|
|
423
|
+
[self.reloaders addObject:^{
|
|
424
|
+
CGFloat value = CCPetsPetScalePreference();
|
|
425
|
+
scale.doubleValue = value;
|
|
426
|
+
scaleLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)lround(value * 100)];
|
|
427
|
+
}];
|
|
428
|
+
[self.form addGroupWithTitle:nil rows:@[
|
|
429
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Pet Size") controls:@[scale, scaleLabel]],
|
|
430
|
+
[self switchRowWithTitle:L(@"Import Codex Pets") subtitle:L(@"Copy pets from ~/.codex/pets into your own folder")
|
|
431
|
+
key:ImportCodexPetsKey
|
|
432
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) { [actions updateImportCodexPets:enabled]; }],
|
|
433
|
+
] footer:nil];
|
|
434
|
+
|
|
435
|
+
// 碎碎念
|
|
436
|
+
NSSegmentedControl *frequency = [self segmentedWithOptions:@[
|
|
437
|
+
@[L(@"Rarely"), @"low"], @[L(@"Normal"), @"normal"], @[L(@"Often"), @"high"], @[L(@"Chatty"), @"chatty"]]
|
|
438
|
+
selected:^id { return [NSUserDefaults.standardUserDefaults stringForKey:PetSpeechFrequencyKey] ?: @"normal"; }
|
|
439
|
+
action:^(NSString *value) { [weakSelf.actions updateSpeechFrequency:value]; }];
|
|
440
|
+
NSPopUpButton *source = [self popUpWithOptions:@[
|
|
441
|
+
@[L(@"Pet-specific Lines"), PetPhrasesSourcePet], @[L(@"Default Lines"), PetPhrasesSourceDefault]]
|
|
442
|
+
selected:^id { return PetPhrasesSource(); }
|
|
443
|
+
action:^(NSString *value) { [weakSelf.actions updatePhrasesSource:value]; }];
|
|
444
|
+
|
|
445
|
+
// 先抽一句给用户看,满意再让桌面上的宠物说:换了台词来源能马上听到区别。
|
|
446
|
+
NSTextField *sample = CCPetsLabel(@"", 12, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
447
|
+
[sample setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow
|
|
448
|
+
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
449
|
+
self.sampleLine = sample;
|
|
450
|
+
NSButton *say = [self smallButtonWithTitle:L(@"Say It") action:^{
|
|
451
|
+
NSString *text = weakSelf.sampleLine.toolTip;
|
|
452
|
+
if (text.length == 0) text = [weakSelf.actions sampleSpeechLine];
|
|
453
|
+
if (text.length > 0) [weakSelf.actions presentSpeechText:text];
|
|
454
|
+
[weakSelf drawSampleLine];
|
|
455
|
+
}];
|
|
456
|
+
NSButton *edit = [self smallButtonWithTitle:L(@"Edit Lines…") action:^{ [weakSelf.actions editPhrasesFile:nil]; }];
|
|
457
|
+
[self drawSampleLine];
|
|
458
|
+
[self.reloaders addObject:^{ [weakSelf drawSampleLine]; }];
|
|
459
|
+
|
|
460
|
+
[self.form addGroupWithTitle:L(@"Chatter") rows:@[
|
|
461
|
+
[self switchRowWithTitle:L(@"Let the pet talk on its own") subtitle:nil key:PetSpeechEnabledKey
|
|
462
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) { [actions updateSpeechEnabled:enabled]; }],
|
|
463
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Frequency") controls:@[frequency]],
|
|
464
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Line Source") controls:@[source]],
|
|
465
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Try a Line") controls:@[sample, say, edit]],
|
|
466
|
+
] footer:nil];
|
|
467
|
+
|
|
468
|
+
// 戳它的反应是宠物自己的性格,和碎碎念放在一起,不和系统通知混在一页。
|
|
469
|
+
[self.form addGroupWithTitle:L(@"Click Reactions") rows:@[
|
|
470
|
+
[self switchRowWithTitle:L(@"React when poked") subtitle:nil key:PetInteractionEnabledKey
|
|
471
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) {
|
|
472
|
+
[actions updatePetInteractionEnabled:enabled];
|
|
473
|
+
}],
|
|
474
|
+
[self stepperRowWithTitle:L(@"Hearts After") key:PetInteractionHeartThresholdKey
|
|
475
|
+
minimum:2 maximum:20 increment:1 fallback:3
|
|
476
|
+
format:^NSString *(double value) { return ClickCountText((NSInteger)value); }],
|
|
477
|
+
[self stepperRowWithTitle:L(@"Annoyed After") key:PetInteractionAnnoyedThresholdKey
|
|
478
|
+
minimum:3 maximum:50 increment:1 fallback:10
|
|
479
|
+
format:^NSString *(double value) { return ClickCountText((NSInteger)value); }],
|
|
480
|
+
[self stepperRowWithTitle:L(@"Click Window") key:PetInteractionIntervalKey
|
|
481
|
+
minimum:0.4 maximum:3.0 increment:0.1 fallback:1.2
|
|
482
|
+
format:^NSString *(double value) {
|
|
483
|
+
return [[NSString stringWithFormat:@"%.1f", value] stringByAppendingString:L(@" s")];
|
|
484
|
+
}],
|
|
485
|
+
] footer:nil];
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
- (void)drawSampleLine {
|
|
489
|
+
NSString *text = [self.actions sampleSpeechLine];
|
|
490
|
+
self.sampleLine.toolTip = text;
|
|
491
|
+
self.sampleLine.stringValue = text.length > 0 ? [NSString stringWithFormat:L(@"“%@”"), text] : @"";
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// 宠物卡片:精灵图 + 名字 + 来源。最后一张是"添加宠物",打开素材文件夹。
|
|
495
|
+
- (void)rebuildPicker {
|
|
496
|
+
for (NSView *view in [self.pickerRows.arrangedSubviews copy]) {
|
|
497
|
+
[self.pickerRows removeArrangedSubview:view];
|
|
498
|
+
[view removeFromSuperview];
|
|
499
|
+
}
|
|
500
|
+
[self.petTiles removeAllObjects];
|
|
501
|
+
[self.petSprites removeAllObjects];
|
|
502
|
+
NSArray<NSDictionary *> *options = [self.actions petPickerOptions] ?: @[];
|
|
503
|
+
NSMutableArray<NSView *> *tiles = [NSMutableArray array];
|
|
504
|
+
__weak typeof(self) weakSelf = self;
|
|
505
|
+
for (NSDictionary *option in options) {
|
|
506
|
+
NSString *petID = option[@"id"];
|
|
507
|
+
CCPetsSpriteView *sprite = [[CCPetsSpriteView alloc] initWithFrame:NSZeroRect];
|
|
508
|
+
CCPetsTileView *tile = [self tileWithTop:sprite title:option[@"name"]
|
|
509
|
+
subtitle:[option[@"builtin"] boolValue] ? L(@"Built-in") : L(@"Your folder")];
|
|
510
|
+
tile.onClick = ^{ [weakSelf.actions switchPetToID:petID]; };
|
|
511
|
+
tile.toolTip = option[@"name"];
|
|
512
|
+
self.petTiles[petID] = tile;
|
|
513
|
+
self.petSprites[petID] = sprite;
|
|
514
|
+
[tiles addObject:tile];
|
|
515
|
+
[self loadSheetForOption:option intoSprite:sprite];
|
|
516
|
+
}
|
|
517
|
+
NSTextField *plus = CCPetsLabel(@"+", 30, NSFontWeightLight, CCPetsTertiaryInkColor());
|
|
518
|
+
plus.alignment = NSTextAlignmentCenter;
|
|
519
|
+
CCPetsTileView *add = [self tileWithTop:plus title:L(@"Add a Pet") subtitle:L(@"cc-pets pet add <name>")];
|
|
520
|
+
add.onClick = ^{ RevealFolder(OwnPetsDirectory()); };
|
|
521
|
+
add.toolTip = L(@"Opens your pets folder. Put a sprite sheet in its own folder there, or run cc-pets pet add <name>.");
|
|
522
|
+
[tiles addObject:add];
|
|
523
|
+
|
|
524
|
+
for (NSUInteger start = 0; start < tiles.count; start += PetPickerColumns) {
|
|
525
|
+
NSMutableArray<NSView *> *rowViews = [NSMutableArray array];
|
|
526
|
+
for (NSUInteger index = start; index < start + PetPickerColumns; index++) {
|
|
527
|
+
// 末行不满时用空视图占位,卡片宽度和上面几行对齐。
|
|
528
|
+
[rowViews addObject:index < tiles.count ? tiles[index] : [NSView new]];
|
|
529
|
+
}
|
|
530
|
+
NSStackView *row = [NSStackView stackViewWithViews:rowViews];
|
|
531
|
+
row.distribution = NSStackViewDistributionFillEqually;
|
|
532
|
+
row.spacing = 10;
|
|
533
|
+
row.alignment = NSLayoutAttributeTop;
|
|
534
|
+
row.translatesAutoresizingMaskIntoConstraints = NO;
|
|
535
|
+
[self.pickerRows addArrangedSubview:row];
|
|
536
|
+
[row.widthAnchor constraintEqualToAnchor:self.pickerRows.widthAnchor].active = YES;
|
|
537
|
+
}
|
|
538
|
+
[self updatePetSelection];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
- (CCPetsTileView *)tileWithTop:(NSView *)top title:(NSString *)title subtitle:(NSString *)subtitle {
|
|
542
|
+
CCPetsTileView *tile = [CCPetsTileView new];
|
|
543
|
+
NSTextField *name = CCPetsLabel(title, 12, NSFontWeightSemibold, CCPetsInkColor());
|
|
544
|
+
NSTextField *detail = CCPetsLabel(subtitle, 11, NSFontWeightRegular, CCPetsTertiaryInkColor());
|
|
545
|
+
for (NSTextField *label in @[name, detail]) {
|
|
546
|
+
label.alignment = NSTextAlignmentCenter;
|
|
547
|
+
[label setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow
|
|
548
|
+
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
549
|
+
}
|
|
550
|
+
for (NSView *view in @[top, name, detail]) {
|
|
551
|
+
view.translatesAutoresizingMaskIntoConstraints = NO;
|
|
552
|
+
[tile addSubview:view];
|
|
553
|
+
}
|
|
554
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
555
|
+
// 素材格子是 140×150,按同样比例缩小。
|
|
556
|
+
[top.topAnchor constraintEqualToAnchor:tile.topAnchor constant:12],
|
|
557
|
+
[top.centerXAnchor constraintEqualToAnchor:tile.centerXAnchor],
|
|
558
|
+
[top.widthAnchor constraintEqualToConstant:66],
|
|
559
|
+
[top.heightAnchor constraintEqualToConstant:72],
|
|
560
|
+
[name.topAnchor constraintEqualToAnchor:top.bottomAnchor constant:6],
|
|
561
|
+
[name.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:8],
|
|
562
|
+
[name.trailingAnchor constraintEqualToAnchor:tile.trailingAnchor constant:-8],
|
|
563
|
+
[detail.topAnchor constraintEqualToAnchor:name.bottomAnchor constant:1],
|
|
564
|
+
[detail.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:8],
|
|
565
|
+
[detail.trailingAnchor constraintEqualToAnchor:tile.trailingAnchor constant:-8],
|
|
566
|
+
[detail.bottomAnchor constraintEqualToAnchor:tile.bottomAnchor constant:-12],
|
|
567
|
+
]];
|
|
568
|
+
return tile;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 精灵图解码要几十毫秒一张,Codex 导入的宠物可能有几十只:每张放到下一轮主线程再解,
|
|
572
|
+
// 页面先出来,图一张张补上。解码器会读屏幕倍率,所以留在主线程。
|
|
573
|
+
- (void)loadSheetForOption:(NSDictionary *)option intoSprite:(CCPetsSpriteView *)sprite {
|
|
574
|
+
NSString *path = option[@"path"];
|
|
575
|
+
NSInteger rowCount = [option[@"rowCount"] integerValue] ?: 9;
|
|
576
|
+
NSImage *cached = self.sheetCache[path];
|
|
577
|
+
if (cached) {
|
|
578
|
+
[sprite setSheet:cached rowCount:rowCount];
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
__weak typeof(self) weakSelf = self;
|
|
582
|
+
__weak CCPetsSpriteView *weakSprite = sprite;
|
|
583
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
584
|
+
if (!weakSelf || !weakSprite || path.length == 0) return;
|
|
585
|
+
NSImage *sheet = LoadPetSpriteImage(path, NSMakeSize(66, 72), rowCount);
|
|
586
|
+
if (!sheet) return;
|
|
587
|
+
weakSelf.sheetCache[path] = sheet;
|
|
588
|
+
[weakSprite setSheet:sheet rowCount:rowCount];
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
- (void)updatePetSelection {
|
|
593
|
+
NSString *current = [self.actions currentPetID];
|
|
594
|
+
[self.petTiles enumerateKeysAndObjectsUsingBlock:^(NSString *petID, CCPetsTileView *tile, BOOL *stop) {
|
|
595
|
+
BOOL selected = [petID isEqualToString:current];
|
|
596
|
+
tile.selected = selected;
|
|
597
|
+
// 只让选中的那只动,其余停在第一帧。
|
|
598
|
+
self.petSprites[petID].playing = selected;
|
|
599
|
+
}];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
@end
|
|
603
|
+
|
|
604
|
+
#pragma mark - 提醒
|
|
605
|
+
|
|
606
|
+
@implementation CCPetsAlertsPage
|
|
607
|
+
|
|
608
|
+
- (NSString *)pageTitle {
|
|
609
|
+
return L(@"Alerts");
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
- (NSString *)pageSubtitle {
|
|
613
|
+
return L(@"When to interrupt you: system notifications, the status card and message badges.");
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
- (void)buildContent {
|
|
617
|
+
[self.form addGroupWithTitle:L(@"Notifications") rows:@[
|
|
618
|
+
[self notificationRowWithTitle:L(@"Awaiting approval") subtitle:L(@"An Agent is stuck on a permission prompt")
|
|
619
|
+
key:NotificationApprovalKey],
|
|
620
|
+
[self notificationRowWithTitle:L(@"Task failed") subtitle:nil key:NotificationFailureKey],
|
|
621
|
+
[self notificationRowWithTitle:L(@"Task done") subtitle:nil key:NotificationCompletionKey],
|
|
622
|
+
[self notificationRowWithTitle:L(@"Stalled") subtitle:L(@"The same step has been running too long")
|
|
623
|
+
key:NotificationStallKey],
|
|
624
|
+
] footer:nil];
|
|
625
|
+
|
|
626
|
+
// CC Bridge 这里只放只影响桌宠的两项;启用和免审批会改 Claude Code / Codex 的配置,仍在右键菜单里。
|
|
627
|
+
[self.form addGroupWithTitle:L(@"Desktop Status Card") rows:@[
|
|
628
|
+
[self switchRowWithTitle:L(@"Show Status Card") subtitle:L(@"The card next to the pet while an Agent is working")
|
|
629
|
+
key:StatusBubbleExpandedKey
|
|
630
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) { [actions updateStatusBubbleExpanded:enabled]; }],
|
|
631
|
+
[self switchRowWithTitle:L(@"CC Bridge unread badge") subtitle:nil key:BridgeBadgeEnabledKey
|
|
632
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) { [actions updateBridgeBadgeEnabled:enabled]; }],
|
|
633
|
+
[self notificationRowWithTitle:L(@"CC Bridge message notifications")
|
|
634
|
+
subtitle:L(@"Only who sent it to whom, never the message") key:BridgeNotificationKey],
|
|
635
|
+
] footer:L(@"Enabling CC Bridge, auto-approve and other options that change Claude Code / Codex settings stay in the pet's right-click menu.")];
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
@end
|
|
639
|
+
|
|
640
|
+
#pragma mark - 通用
|
|
641
|
+
|
|
642
|
+
@interface CCPetsGeneralPage ()
|
|
643
|
+
@property(nonatomic) NSView *glassPreviewDim;
|
|
644
|
+
@property(nonatomic, copy) NSArray<NSDictionary *> *usageProfiles;
|
|
645
|
+
@end
|
|
646
|
+
|
|
647
|
+
@implementation CCPetsGeneralPage
|
|
648
|
+
|
|
649
|
+
- (void)loadView {
|
|
650
|
+
[super loadView];
|
|
651
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(preferencesDidChange:)
|
|
652
|
+
name:CCPetsProfilesDidChangeNotification object:nil];
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
- (void)viewWillAppear {
|
|
656
|
+
[super viewWillAppear];
|
|
657
|
+
[self reloadValues];
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
- (NSArray<NSDictionary *> *)currentUsageProfiles {
|
|
661
|
+
NSMutableArray<NSDictionary *> *profiles = [NSMutableArray array];
|
|
662
|
+
for (NSString *provider in @[@"claude", @"codex"]) {
|
|
663
|
+
NSArray *registered = CCPetsProfilesForProvider(provider);
|
|
664
|
+
[profiles addObjectsFromArray:registered.count > 0 ? registered : @[@{@"provider": provider}]];
|
|
665
|
+
}
|
|
666
|
+
return profiles.copy;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
- (void)reloadValues {
|
|
670
|
+
if (![self.usageProfiles isEqualToArray:[self currentUsageProfiles]]) {
|
|
671
|
+
// 新增、移除、改名或重新定位账号后重建行,同时释放旧控件的闭包。
|
|
672
|
+
[self.handlers removeAllObjects];
|
|
673
|
+
[self.reloaders removeAllObjects];
|
|
674
|
+
[self.form removeAllContent];
|
|
675
|
+
[self buildContent];
|
|
676
|
+
}
|
|
677
|
+
[super reloadValues];
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
- (NSString *)pageTitle {
|
|
681
|
+
return L(@"Settings");
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
- (NSString *)pageSubtitle {
|
|
685
|
+
return L(@"Language, panel appearance and data folders.");
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// 主题卡片上方的小预览:三条横线代表面板里的文字行。
|
|
689
|
+
- (NSView *)themePreviewLiquid:(BOOL)liquid {
|
|
690
|
+
NSView *preview = [NSView new];
|
|
691
|
+
preview.wantsLayer = YES;
|
|
692
|
+
preview.layer.cornerRadius = 6;
|
|
693
|
+
preview.layer.masksToBounds = YES;
|
|
694
|
+
if (liquid) {
|
|
695
|
+
CAGradientLayer *gradient = [CAGradientLayer layer];
|
|
696
|
+
gradient.colors = @[(id)[NSColor colorWithSRGBRed:0.43 green:0.56 blue:0.70 alpha:1].CGColor,
|
|
697
|
+
(id)[NSColor colorWithSRGBRed:0.18 green:0.29 blue:0.42 alpha:1].CGColor,
|
|
698
|
+
(id)[NSColor colorWithSRGBRed:0.25 green:0.37 blue:0.27 alpha:1].CGColor];
|
|
699
|
+
gradient.startPoint = CGPointMake(0, 1);
|
|
700
|
+
gradient.endPoint = CGPointMake(1, 0);
|
|
701
|
+
gradient.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
|
|
702
|
+
[preview.layer addSublayer:gradient];
|
|
703
|
+
} else {
|
|
704
|
+
preview.layer.backgroundColor = [NSColor colorWithSRGBRed:0.12 green:0.14 blue:0.16 alpha:1].CGColor;
|
|
705
|
+
}
|
|
706
|
+
NSArray<NSArray *> *bars = @[@[@1.0, liquid ? @0.55 : @0.25], @[@0.7, liquid ? @0.85 : @1.0], @[@0.45, liquid ? @0.55 : @0.25]];
|
|
707
|
+
NSView *previous = nil;
|
|
708
|
+
for (NSUInteger index = 0; index < bars.count; index++) {
|
|
709
|
+
NSView *bar = [NSView new];
|
|
710
|
+
bar.wantsLayer = YES;
|
|
711
|
+
bar.layer.cornerRadius = 2;
|
|
712
|
+
// 经典主题的第二条用强调青,和真正的经典面板一样。
|
|
713
|
+
bar.layer.backgroundColor = (!liquid && index == 1)
|
|
714
|
+
? [NSColor colorWithSRGBRed:0.31 green:0.83 blue:0.90 alpha:1].CGColor
|
|
715
|
+
: [NSColor colorWithWhite:1 alpha:[bars[index][1] doubleValue]].CGColor;
|
|
716
|
+
bar.translatesAutoresizingMaskIntoConstraints = NO;
|
|
717
|
+
[preview addSubview:bar];
|
|
718
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
719
|
+
[bar.leadingAnchor constraintEqualToAnchor:preview.leadingAnchor constant:10],
|
|
720
|
+
[bar.widthAnchor constraintEqualToAnchor:preview.widthAnchor multiplier:[bars[index][0] doubleValue]
|
|
721
|
+
constant:-20 * [bars[index][0] doubleValue]],
|
|
722
|
+
[bar.heightAnchor constraintEqualToConstant:4],
|
|
723
|
+
previous ? [bar.topAnchor constraintEqualToAnchor:previous.bottomAnchor constant:5]
|
|
724
|
+
: [bar.topAnchor constraintEqualToAnchor:preview.topAnchor constant:18],
|
|
725
|
+
]];
|
|
726
|
+
previous = bar;
|
|
727
|
+
}
|
|
728
|
+
if (liquid) {
|
|
729
|
+
// 压暗层:滑块拖动时跟着变深变浅。
|
|
730
|
+
NSView *dim = [NSView new];
|
|
731
|
+
dim.wantsLayer = YES;
|
|
732
|
+
dim.translatesAutoresizingMaskIntoConstraints = NO;
|
|
733
|
+
[preview addSubview:dim];
|
|
734
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
735
|
+
[dim.leadingAnchor constraintEqualToAnchor:preview.leadingAnchor],
|
|
736
|
+
[dim.trailingAnchor constraintEqualToAnchor:preview.trailingAnchor],
|
|
737
|
+
[dim.topAnchor constraintEqualToAnchor:preview.topAnchor],
|
|
738
|
+
[dim.bottomAnchor constraintEqualToAnchor:preview.bottomAnchor],
|
|
739
|
+
]];
|
|
740
|
+
self.glassPreviewDim = dim;
|
|
741
|
+
}
|
|
742
|
+
return preview;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
- (CCPetsTileView *)themeTileLiquid:(BOOL)liquid {
|
|
746
|
+
CCPetsTileView *tile = [CCPetsTileView new];
|
|
747
|
+
NSView *preview = [self themePreviewLiquid:liquid];
|
|
748
|
+
NSTextField *title = CCPetsLabel(liquid ? @"Liquid Glass" : L(@"Classic"), 13, NSFontWeightSemibold, CCPetsInkColor());
|
|
749
|
+
NSMutableArray<NSView *> *views = [NSMutableArray arrayWithObjects:preview, title, nil];
|
|
750
|
+
NSTextField *note = nil;
|
|
751
|
+
if (liquid) {
|
|
752
|
+
note = CCPetsLabel(L(@"macOS 26 or later"), 11, NSFontWeightRegular, CCPetsTertiaryInkColor());
|
|
753
|
+
[views addObject:note];
|
|
754
|
+
}
|
|
755
|
+
for (NSView *view in views) {
|
|
756
|
+
view.translatesAutoresizingMaskIntoConstraints = NO;
|
|
757
|
+
[tile addSubview:view];
|
|
758
|
+
}
|
|
759
|
+
NSView *last = note ?: title;
|
|
760
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
761
|
+
[preview.topAnchor constraintEqualToAnchor:tile.topAnchor constant:10],
|
|
762
|
+
[preview.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:10],
|
|
763
|
+
[preview.trailingAnchor constraintEqualToAnchor:tile.trailingAnchor constant:-10],
|
|
764
|
+
[preview.heightAnchor constraintEqualToConstant:62],
|
|
765
|
+
[title.topAnchor constraintEqualToAnchor:preview.bottomAnchor constant:10],
|
|
766
|
+
[title.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:12],
|
|
767
|
+
[title.trailingAnchor constraintLessThanOrEqualToAnchor:tile.trailingAnchor constant:-12],
|
|
768
|
+
// 两张卡片等高(经典卡没有说明行),所以底边只约束"不超出",多出的高度留在下面。
|
|
769
|
+
[last.bottomAnchor constraintLessThanOrEqualToAnchor:tile.bottomAnchor constant:-10],
|
|
770
|
+
]];
|
|
771
|
+
if (note) {
|
|
772
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
773
|
+
[note.topAnchor constraintEqualToAnchor:title.bottomAnchor constant:1],
|
|
774
|
+
[note.leadingAnchor constraintEqualToAnchor:title.leadingAnchor],
|
|
775
|
+
[note.bottomAnchor constraintEqualToAnchor:tile.bottomAnchor constant:-10],
|
|
776
|
+
]];
|
|
777
|
+
}
|
|
778
|
+
return tile;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
- (void)buildContent {
|
|
782
|
+
__weak typeof(self) weakSelf = self;
|
|
783
|
+
|
|
784
|
+
NSMutableArray<NSArray *> *languages = [NSMutableArray arrayWithObject:@[L(@"System Default"), CCPetsLanguageSystem]];
|
|
785
|
+
for (NSString *language in CCPetsSupportedLanguages()) {
|
|
786
|
+
[languages addObject:@[CCPetsLanguageDisplayName(language), language]];
|
|
787
|
+
}
|
|
788
|
+
NSPopUpButton *language = [self popUpWithOptions:languages
|
|
789
|
+
selected:^id { return CCPetsLanguagePreference(); }
|
|
790
|
+
action:^(NSString *value) {
|
|
791
|
+
if ([value isEqualToString:CCPetsLanguagePreference()]) return;
|
|
792
|
+
// 主窗口收到语言变更会重建本页,别在控件自己的 action 里把它拆掉。
|
|
793
|
+
dispatch_async(dispatch_get_main_queue(), ^{ CCPetsSetLanguagePreference(value); });
|
|
794
|
+
}];
|
|
795
|
+
NSSegmentedControl *appearance = [self segmentedWithOptions:@[
|
|
796
|
+
@[L(@"System Default"), @"system"], @[L(@"Light"), @"light"], @[L(@"Dark"), @"dark"]]
|
|
797
|
+
selected:^id { return CCPetsMainWindowAppearancePreference(); }
|
|
798
|
+
action:^(NSString *value) { CCPetsPrefSetObject(CCPetsMainWindowAppearanceKey, value); }];
|
|
799
|
+
[self.form addGroupWithTitle:nil rows:@[
|
|
800
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Language") controls:@[language]],
|
|
801
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Window Appearance")
|
|
802
|
+
subtitle:L(@"Only this window; the pet's panels follow Panel Appearance below") controls:@[appearance]],
|
|
803
|
+
] footer:nil];
|
|
804
|
+
|
|
805
|
+
// 浮层外观:两张主题卡片 + 玻璃压暗滑块。
|
|
806
|
+
[self.form addGroupTitle:L(@"Panel Appearance") note:nil];
|
|
807
|
+
CCPetsTileView *classic = [self themeTileLiquid:NO];
|
|
808
|
+
CCPetsTileView *liquid = [self themeTileLiquid:YES];
|
|
809
|
+
classic.onClick = ^{ [weakSelf.actions updatePanelTheme:@"classic"]; };
|
|
810
|
+
BOOL liquidAvailable = CCPetsLiquidGlassAvailable();
|
|
811
|
+
if (liquidAvailable) liquid.onClick = ^{ [weakSelf.actions updatePanelTheme:@"liquid"]; };
|
|
812
|
+
else liquid.alphaValue = 0.5;
|
|
813
|
+
NSStackView *themes = [NSStackView stackViewWithViews:@[classic, liquid]];
|
|
814
|
+
themes.distribution = NSStackViewDistributionFillEqually;
|
|
815
|
+
themes.alignment = NSLayoutAttributeTop;
|
|
816
|
+
themes.spacing = 10;
|
|
817
|
+
[self.form addView:themes];
|
|
818
|
+
[classic.heightAnchor constraintEqualToAnchor:liquid.heightAnchor].active = YES;
|
|
819
|
+
|
|
820
|
+
NSSlider *dim = [self sliderWithMinimum:0 maximum:CCPetsGlassDimMaximum width:200];
|
|
821
|
+
NSTextField *dimLabel = [self sliderValueLabel];
|
|
822
|
+
[self bind:dim to:^(NSSlider *sender) {
|
|
823
|
+
NSInteger value = (NSInteger)lround(sender.doubleValue);
|
|
824
|
+
dimLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)value];
|
|
825
|
+
[weakSelf showGlassDim:value];
|
|
826
|
+
[weakSelf.actions updateGlassDimLevel:@(value)];
|
|
827
|
+
}];
|
|
828
|
+
NSView *dimRow = [CCPetsFormBuilder rowWithTitle:L(@"Glass Dimming")
|
|
829
|
+
subtitle:L(@"Raise it when a bright wallpaper makes text hard to read") controls:@[dim, dimLabel]];
|
|
830
|
+
[self.reloaders addObject:^{
|
|
831
|
+
BOOL isLiquid = [CCPetsPanelTheme() isEqualToString:@"liquid"] && liquidAvailable;
|
|
832
|
+
classic.selected = !isLiquid;
|
|
833
|
+
liquid.selected = isLiquid;
|
|
834
|
+
NSInteger level = CCPetsGlassDimLevel();
|
|
835
|
+
dim.doubleValue = level;
|
|
836
|
+
dimLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)level];
|
|
837
|
+
// 压暗只作用于原生玻璃,经典主题下没有这层。
|
|
838
|
+
dim.enabled = isLiquid;
|
|
839
|
+
[weakSelf showGlassDim:level];
|
|
840
|
+
}];
|
|
841
|
+
[self.form addGroupWithTitle:nil rows:@[dimRow] footer:nil];
|
|
842
|
+
|
|
843
|
+
// 悬停面板:每家一个胶囊,点一下在订阅额度和 Token 用量之间切换,和右键菜单同一个样子。
|
|
844
|
+
[self.form addGroupTitle:L(@"Hover Panel") note:L(@"Click a pill to switch")];
|
|
845
|
+
NSMutableArray<NSView *> *panelRows = [NSMutableArray array];
|
|
846
|
+
self.usageProfiles = [self currentUsageProfiles];
|
|
847
|
+
for (NSDictionary *profile in self.usageProfiles) {
|
|
848
|
+
NSString *provider = [profile[@"provider"] isEqualToString:@"codex"] ? @"Codex" : @"Claude";
|
|
849
|
+
NSString *name = profile[@"displayName"] ?: provider;
|
|
850
|
+
CCPetsPillButton *pill = [CCPetsPillButton new];
|
|
851
|
+
[pill setAccessibilityLabel:[NSString stringWithFormat:L(@"%@ usage display"), name]];
|
|
852
|
+
NSView *row = [CCPetsFormBuilder rowWithTitle:name subtitle:@" " controls:@[pill]];
|
|
853
|
+
NSTextField *detail = [self subtitleLabelInRow:row];
|
|
854
|
+
[self bind:pill to:^(id sender) {
|
|
855
|
+
NSDictionary *current = profile[@"id"] ? CCPetsProfileWithID(profile[@"id"]) : profile;
|
|
856
|
+
if (!current || !CCPetsProfileCanSwitchUsageMode(current)) return;
|
|
857
|
+
BOOL api = CCPetsProfileShowsAPIUsage(current);
|
|
858
|
+
if (current[@"id"]) [weakSelf.actions updateUsageDisplayMode:api ? @"subscription" : @"api" forProfileID:current[@"id"]];
|
|
859
|
+
else [weakSelf.actions updateUsageDisplayMode:api ? @"subscription" : @"api" forKey:CCPetsUsageModePreferenceKey(current)];
|
|
860
|
+
}];
|
|
861
|
+
[self.reloaders addObject:^{
|
|
862
|
+
NSDictionary *current = profile[@"id"] ? CCPetsProfileWithID(profile[@"id"]) : profile;
|
|
863
|
+
BOOL api = current && CCPetsProfileShowsAPIUsage(current);
|
|
864
|
+
pill.enabled = current && CCPetsProfileCanSwitchUsageMode(current);
|
|
865
|
+
pill.toolTip = pill.enabled ? nil : L(@"API authentication: usage display is fixed to API.");
|
|
866
|
+
pill.title = api ? L(@"API") : L(@"Plan");
|
|
867
|
+
// 订阅用绿、用量用蓝,和右键菜单里的胶囊一致。
|
|
868
|
+
pill.fillColor = api ? CCPetsChartColor(6) : CCPetsChartColor(5);
|
|
869
|
+
detail.stringValue = !pill.enabled ? L(@"API authentication: usage display is fixed to API.")
|
|
870
|
+
: (api ? L(@"Token usage: today's new and cached tokens")
|
|
871
|
+
: L(@"Plan quota: what's left of the 5-hour and weekly limits"));
|
|
872
|
+
}];
|
|
873
|
+
[panelRows addObject:row];
|
|
874
|
+
}
|
|
875
|
+
// 三项可以任意组合:用"可多选"的分段控件,一行放得下,也和上面的分段控件一个样子。
|
|
876
|
+
NSArray<NSString *> *metricKeys = @[SystemCPUEnabledKey, SystemTemperatureEnabledKey, SystemMemoryEnabledKey];
|
|
877
|
+
NSSegmentedControl *metrics = [NSSegmentedControl segmentedControlWithLabels:@[@"CPU", L(@"Temperature"), L(@"Memory")]
|
|
878
|
+
trackingMode:NSSegmentSwitchTrackingSelectAny target:nil action:nil];
|
|
879
|
+
metrics.controlSize = NSControlSizeSmall;
|
|
880
|
+
metrics.font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
881
|
+
CCPetsApplyAccent(metrics);
|
|
882
|
+
[self bind:metrics to:^(NSSegmentedControl *sender) {
|
|
883
|
+
NSInteger segment = sender.selectedSegment;
|
|
884
|
+
if (segment < 0 || segment >= (NSInteger)metricKeys.count) return;
|
|
885
|
+
[weakSelf.actions updateSystemMetric:metricKeys[(NSUInteger)segment] enabled:[sender isSelectedForSegment:segment]];
|
|
886
|
+
}];
|
|
887
|
+
[self.reloaders addObject:^{
|
|
888
|
+
for (NSUInteger index = 0; index < metricKeys.count; index++) {
|
|
889
|
+
[metrics setSelected:CCPetsPrefBool(metricKeys[index]) forSegment:(NSInteger)index];
|
|
890
|
+
}
|
|
891
|
+
}];
|
|
892
|
+
[panelRows addObject:[CCPetsFormBuilder rowWithTitle:L(@"System Status") controls:@[metrics]]];
|
|
893
|
+
[self.form addGroupWithTitle:nil rows:panelRows footer:nil];
|
|
894
|
+
|
|
895
|
+
[self.form addGroupWithTitle:L(@"Data") rows:@[
|
|
896
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Pet sprites folder") subtitle:[self displayPath:OwnPetsDirectory()]
|
|
897
|
+
controls:@[[self smallButtonWithTitle:L(@"Show in Finder") action:^{ RevealFolder(OwnPetsDirectory()); }]]],
|
|
898
|
+
] footer:nil];
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
- (NSString *)displayPath:(NSString *)path {
|
|
902
|
+
return path.stringByAbbreviatingWithTildeInPath;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// rowWithTitle:subtitle: 里的说明标签,胶囊切换时要跟着改文字。
|
|
906
|
+
- (NSTextField *)subtitleLabelInRow:(NSView *)row {
|
|
907
|
+
NSStackView *stack = (NSStackView *)row;
|
|
908
|
+
NSStackView *titles = (NSStackView *)stack.arrangedSubviews.firstObject;
|
|
909
|
+
if (![titles isKindOfClass:NSStackView.class]) return nil;
|
|
910
|
+
return (NSTextField *)titles.arrangedSubviews.lastObject;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
- (void)showGlassDim:(NSInteger)level {
|
|
914
|
+
self.glassPreviewDim.layer.backgroundColor = [NSColor colorWithWhite:0 alpha:level / 100.0].CGColor;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
@end
|