cc-pets 2.3.0 → 2.4.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 +19 -0
- package/CC_BRIDGE.zh-CN.md +15 -0
- package/CHANGELOG.md +51 -0
- package/CHANGELOG.zh-CN.md +51 -0
- package/CONTRIBUTING.md +22 -0
- package/CONTRIBUTING.zh-CN.md +17 -0
- package/README.md +117 -26
- package/README.zh-CN.md +92 -22
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +155 -27
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +12 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +1 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +3 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +113 -47
- package/Sources/CCPets/App/CCPetsAppDelegate.h +2 -2
- package/Sources/CCPets/App/main.m +6 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +11 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +78 -38
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +2 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +50 -32
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +46 -40
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +9 -6
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +171 -53
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +107 -25
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +2 -2
- package/Sources/CCPets/Support/CCPetsDoctor.m +26 -12
- package/Sources/CCPets/Support/CCPetsPreferences.h +2 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +34 -2
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +2 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +18 -7
- package/Sources/CCPets/UI/CCPetsGlassView.h +26 -4
- package/Sources/CCPets/UI/CCPetsGlassView.m +40 -9
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +2 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +561 -66
- package/Sources/CCPets/UI/CCPetsUIStyle.h +5 -2
- package/Sources/CCPets/UI/CCPetsUIStyle.m +57 -8
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +4 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +23 -28
- package/Sources/CCPets/UI/CCPetsUsageStore.m +2 -2
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +1 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +49 -11
- package/Sources/CCPets/Usage/CCPetsUsage.h +3 -2
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +15 -17
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +11 -29
- package/Sources/CCPets/Usage/QuotaDashboardView.m +128 -2
- package/THIRD_PARTY_NOTICES.md +7 -3
- package/THIRD_PARTY_NOTICES.zh-CN.md +5 -1
- package/bin/claude-with-pet +2 -0
- package/bin/codex-with-pet +2 -0
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +24 -2
- package/scripts/compile-cached.zsh +133 -0
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
#define LF(localized, values) CCPetsInterpolate(localized, values)
|
|
20
20
|
|
|
21
|
-
// 安装脚本在 App
|
|
21
|
+
// 安装脚本在 App 数据目录里记下本地包目录:装到 ~/Applications 的 App 是拷贝,
|
|
22
22
|
// 从自己的位置推不出包在哪。
|
|
23
23
|
static NSString *const PackageDirectoryMarker = @"package-dir";
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// 本地包目录。三种来源,按可靠程度:
|
|
26
26
|
// 1. 可执行文件在 <包目录>/.build/release/ 之下(命令行二进制,或构建出来的 App);
|
|
27
27
|
// 2. 安装脚本留下的记号文件(~/Applications 里的 App);
|
|
28
28
|
// 3. 退回按命令行二进制的相对位置推算(<包目录>/.build/release/cc-pets)。
|
|
@@ -39,11 +39,24 @@ static NSString *PackageDirectory(void) {
|
|
|
39
39
|
.stringByDeletingLastPathComponent;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// 先解析 npm link 等软链;Git worktree 的 .git 是文件,普通 checkout 则是目录。
|
|
43
|
+
// 无法确定来源时只称“本地包”,不把源码归档或任意目录猜作 npm 安装。
|
|
44
|
+
static NSString *PackageKind(void) {
|
|
45
|
+
NSString *directory = PackageDirectory().stringByResolvingSymlinksInPath;
|
|
46
|
+
if ([NSFileManager.defaultManager fileExistsAtPath:[directory stringByAppendingPathComponent:@".git"]]) {
|
|
47
|
+
return L(@"local source package");
|
|
48
|
+
}
|
|
49
|
+
if ([directory.stringByDeletingLastPathComponent.lastPathComponent isEqualToString:@"node_modules"]) {
|
|
50
|
+
return L(@"local npm package");
|
|
51
|
+
}
|
|
52
|
+
return L(@"local package");
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
static NSString *PetBinary(void) {
|
|
43
56
|
return [PackageDirectory() stringByAppendingPathComponent:@".build/release/cc-pets"];
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
//
|
|
59
|
+
// 只读本地 package.json,不表示 npm Registry 已发布该版本;读不到时退回编译版本。
|
|
47
60
|
static NSString *PackageVersion(void) {
|
|
48
61
|
NSData *data = [NSData dataWithContentsOfFile:[PackageDirectory() stringByAppendingPathComponent:@"package.json"]];
|
|
49
62
|
NSDictionary *package = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
@@ -114,7 +127,7 @@ static NSDictionary *ReadJSONFile(NSString *file) {
|
|
|
114
127
|
|
|
115
128
|
static NSArray<NSDictionary *> *PathGroups(NSDictionary *native) {
|
|
116
129
|
NSMutableArray *integrationItems = [NSMutableArray arrayWithArray:@[
|
|
117
|
-
@[
|
|
130
|
+
@[PackageKind(), PackageDirectory()],
|
|
118
131
|
@[L(@"Installed app"), InstalledApp()],
|
|
119
132
|
@[L(@"Agent profile registry"), CCPetsProfilesPath()],
|
|
120
133
|
@[L(@"Claude Code settings"), [[CCPetsHomeDirectory() stringByAppendingPathComponent:@".claude"]
|
|
@@ -391,12 +404,13 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
391
404
|
NSString *packageVersion = PackageVersion();
|
|
392
405
|
|
|
393
406
|
NSMutableArray<NSDictionary *> *program = [NSMutableArray arrayWithObject:
|
|
394
|
-
Result(@"info", LF(L(@"
|
|
395
|
-
(@{@"packageVersion": packageVersion, @"projectDir": CCPetsTildePath(PackageDirectory())})), nil)];
|
|
407
|
+
Result(@"info", LF(L(@"{packageKind} {packageVersion}: {projectDir}"),
|
|
408
|
+
(@{@"packageKind": PackageKind(), @"packageVersion": packageVersion, @"projectDir": CCPetsTildePath(PackageDirectory())})), nil)];
|
|
409
|
+
[program addObject:Result(@"info", L(@"These checks compare local versions. Published npm updates are checked separately."), nil)];
|
|
396
410
|
NSString *binaryVersion = @CC_PETS_VERSION;
|
|
397
411
|
if (![binaryVersion isEqualToString:packageVersion]) {
|
|
398
|
-
[program addObject:Result(@"warn", LF(L(@"Native binary {binaryVersion} doesn't match
|
|
399
|
-
(@{@"binaryVersion": binaryVersion, @"packageVersion": packageVersion})), @"cc-pets install")];
|
|
412
|
+
[program addObject:Result(@"warn", LF(L(@"Native binary {binaryVersion} doesn't match {packageKind} {packageVersion}"),
|
|
413
|
+
(@{@"binaryVersion": binaryVersion, @"packageKind": PackageKind(), @"packageVersion": packageVersion})), @"cc-pets install")];
|
|
400
414
|
} else {
|
|
401
415
|
[program addObject:Result(@"ok", LF(L(@"Native binary {binaryVersion}"), @{@"binaryVersion": binaryVersion}), nil)];
|
|
402
416
|
}
|
|
@@ -404,8 +418,8 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
404
418
|
if (!appVersion) {
|
|
405
419
|
[program addObject:Result(@"warn", LF(L(@"Installed app not found: {installedApp}"), @{@"installedApp": CCPetsTildePath(InstalledApp())}), @"cc-pets install")];
|
|
406
420
|
} else if (![appVersion isEqualToString:packageVersion]) {
|
|
407
|
-
[program addObject:Result(@"warn", LF(L(@"Installed app {appVersion} doesn't match
|
|
408
|
-
(@{@"appVersion": appVersion, @"packageVersion": packageVersion})), @"cc-pets install")];
|
|
421
|
+
[program addObject:Result(@"warn", LF(L(@"Installed app {appVersion} doesn't match {packageKind} {packageVersion}"),
|
|
422
|
+
(@{@"appVersion": appVersion, @"packageKind": PackageKind(), @"packageVersion": packageVersion})), @"cc-pets install")];
|
|
409
423
|
} else {
|
|
410
424
|
[program addObject:Result(@"ok", LF(L(@"Installed app {appVersion}"), @{@"appVersion": appVersion}), nil)];
|
|
411
425
|
}
|
|
@@ -508,8 +522,8 @@ NSString *CCPetsDoctorReport(NSArray<NSDictionary *> *sections) {
|
|
|
508
522
|
struct utsname system;
|
|
509
523
|
uname(&system);
|
|
510
524
|
NSMutableArray<NSString *> *lines = [NSMutableArray arrayWithObject:
|
|
511
|
-
LF(L(@"CC Pets diagnostics (
|
|
512
|
-
(@{@"packageVersion": PackageVersion(), @"platform": @"darwin", @"release": @(system.release)}))];
|
|
525
|
+
LF(L(@"CC Pets diagnostics ({packageKind} {packageVersion}, {platform} {release})"),
|
|
526
|
+
(@{@"packageKind": PackageKind(), @"packageVersion": PackageVersion(), @"platform": @"darwin", @"release": @(system.release)}))];
|
|
513
527
|
NSDictionary<NSString *, NSString *> *icons = @{@"ok": @"✅", @"warn": @"⚠️ ", @"fail": @"❌", @"info": @"ℹ️ "};
|
|
514
528
|
for (NSDictionary *section in sections) {
|
|
515
529
|
[lines addObject:[@"\n" stringByAppendingString:section[@"title"]]];
|
|
@@ -15,6 +15,8 @@ extern NSString *const PetInteractionEnabledKey;
|
|
|
15
15
|
extern NSString *const PetInteractionHeartThresholdKey;
|
|
16
16
|
extern NSString *const PetInteractionAnnoyedThresholdKey;
|
|
17
17
|
extern NSString *const PetInteractionIntervalKey;
|
|
18
|
+
// 启动保护按代理软件分别保存;增加软件时定义独立的布尔键。
|
|
19
|
+
extern NSString *const CCPetsShadowrocketLaunchCheckKey;
|
|
18
20
|
|
|
19
21
|
// 布尔设置。碎碎念这类"没写过就算开"的键在这里统一兜底,调用方不必各自判 nil。
|
|
20
22
|
BOOL CCPetsPrefBool(NSString *key);
|
|
@@ -10,6 +10,25 @@ NSString *const PetInteractionEnabledKey = @"CCPetsInteractionEnabled";
|
|
|
10
10
|
NSString *const PetInteractionHeartThresholdKey = @"CCPetsInteractionHeartThreshold";
|
|
11
11
|
NSString *const PetInteractionAnnoyedThresholdKey = @"CCPetsInteractionAnnoyedThreshold";
|
|
12
12
|
NSString *const PetInteractionIntervalKey = @"CCPetsInteractionInterval";
|
|
13
|
+
NSString *const CCPetsShadowrocketLaunchCheckKey = @"CCPetsLaunchProtection.Shadowrocket";
|
|
14
|
+
|
|
15
|
+
// 包装器运行的是裸二进制,默认 preferences domain 与 App bundle 不同。
|
|
16
|
+
// 启动保护的读取和写入统一走 CFPreferences 的同一个域、用户和主机。
|
|
17
|
+
// 不混用临时 suite 的写入与 standardUserDefaults 的快照回读,避免控件刷新后弹回关闭。
|
|
18
|
+
static NSString *LaunchPreferencesDomain(void) {
|
|
19
|
+
NSString *domain = NSProcessInfo.processInfo.environment[@"CC_PETS_PREFERENCES_DOMAIN"];
|
|
20
|
+
return domain.length ? domain : @"com.universewang.cc-pets";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static BOOL IsLaunchProtectionKey(NSString *key) {
|
|
24
|
+
return [key hasPrefix:@"CCPetsLaunchProtection."];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static id LaunchProtectionValue(NSString *key) {
|
|
28
|
+
return CFBridgingRelease(CFPreferencesCopyValue((__bridge CFStringRef)key,
|
|
29
|
+
(__bridge CFStringRef)LaunchPreferencesDomain(),
|
|
30
|
+
kCFPreferencesCurrentUser, kCFPreferencesAnyHost));
|
|
31
|
+
}
|
|
13
32
|
|
|
14
33
|
// 没有注册默认值、缺省又是开启的键。碎碎念从第一版起就是"读不到就算开",
|
|
15
34
|
// 改成 registerDefaults 的话 CLI 子命令(没走 applicationDidFinishLaunching)会读成关。
|
|
@@ -18,7 +37,13 @@ static BOOL DefaultsToEnabled(NSString *key) {
|
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
BOOL CCPetsPrefBool(NSString *key) {
|
|
21
|
-
id value =
|
|
40
|
+
id value = IsLaunchProtectionKey(key)
|
|
41
|
+
? LaunchProtectionValue(key)
|
|
42
|
+
: [NSUserDefaults.standardUserDefaults objectForKey:key];
|
|
43
|
+
// 兼容第一版总开关;一旦保存了 Shadowrocket 的独立开关(包括关闭),就以新值为准。
|
|
44
|
+
if (value == nil && [key isEqualToString:CCPetsShadowrocketLaunchCheckKey]) {
|
|
45
|
+
value = LaunchProtectionValue(@"CCPetsLaunchProxyCheck");
|
|
46
|
+
}
|
|
22
47
|
if (value == nil) return DefaultsToEnabled(key);
|
|
23
48
|
return [value respondsToSelector:@selector(boolValue)] ? [value boolValue] : NO;
|
|
24
49
|
}
|
|
@@ -33,7 +58,14 @@ void CCPetsPrefPostChange(NSString *key) {
|
|
|
33
58
|
void CCPetsPrefSetBool(NSString *key, BOOL value) {
|
|
34
59
|
if (key.length == 0) return;
|
|
35
60
|
BOOL changed = CCPetsPrefBool(key) != value;
|
|
36
|
-
|
|
61
|
+
if (IsLaunchProtectionKey(key)) {
|
|
62
|
+
CFStringRef domain = (__bridge CFStringRef)LaunchPreferencesDomain();
|
|
63
|
+
CFPreferencesSetValue((__bridge CFStringRef)key, value ? kCFBooleanTrue : kCFBooleanFalse,
|
|
64
|
+
domain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
65
|
+
CFPreferencesSynchronize(domain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
|
66
|
+
} else {
|
|
67
|
+
[NSUserDefaults.standardUserDefaults setBool:value forKey:key];
|
|
68
|
+
}
|
|
37
69
|
if (changed) CCPetsPrefPostChange(key);
|
|
38
70
|
}
|
|
39
71
|
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
// 一张卡片,rows 之间自动加分隔线。title 非 nil 时先加分组标题;footer 是卡片下方的小字。
|
|
33
33
|
// 返回卡片。
|
|
34
34
|
- (NSView *)addGroupWithTitle:(NSString *)title rows:(NSArray<NSView *> *)rows footer:(NSString *)footer;
|
|
35
|
+
// 替换 addGroupWithTitle 返回的卡片里的行(分隔线同样自动加),用于行数随数据变化的卡片。
|
|
36
|
+
+ (void)replaceRowsInCard:(NSView *)card withRows:(NSArray<NSView *> *)rows;
|
|
35
37
|
// 拉满宽度加到内容里。
|
|
36
38
|
- (void)addView:(NSView *)view;
|
|
37
39
|
// 卡片下方那种灰色小字。
|
|
@@ -206,13 +206,8 @@ static const CGFloat FormSideInset = 28;
|
|
|
206
206
|
[self.stack setCustomSpacing:8 afterView:header];
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
NSStackView *content = [NSStackView stackViewWithViews:@[]];
|
|
213
|
-
content.orientation = NSUserInterfaceLayoutOrientationVertical;
|
|
214
|
-
content.spacing = 0;
|
|
215
|
-
content.translatesAutoresizingMaskIntoConstraints = NO;
|
|
209
|
+
static void FillCardContent(NSStackView *content, NSArray<NSView *> *rows) {
|
|
210
|
+
for (NSView *view in content.arrangedSubviews.copy) [view removeFromSuperview];
|
|
216
211
|
for (NSView *row in rows) {
|
|
217
212
|
if (content.arrangedSubviews.count > 0) {
|
|
218
213
|
NSView *separator = [CCPetsFormBuilder separator];
|
|
@@ -224,6 +219,22 @@ static const CGFloat FormSideInset = 28;
|
|
|
224
219
|
[row.leadingAnchor constraintEqualToAnchor:content.leadingAnchor].active = YES;
|
|
225
220
|
[row.trailingAnchor constraintEqualToAnchor:content.trailingAnchor].active = YES;
|
|
226
221
|
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
+ (void)replaceRowsInCard:(NSView *)card withRows:(NSArray<NSView *> *)rows {
|
|
225
|
+
for (NSView *content in card.subviews) {
|
|
226
|
+
if ([content isKindOfClass:NSStackView.class]) { FillCardContent((NSStackView *)content, rows); return; }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
- (NSView *)addGroupWithTitle:(NSString *)title rows:(NSArray<NSView *> *)rows footer:(NSString *)footer {
|
|
231
|
+
if (title.length > 0) [self addGroupTitle:title note:nil];
|
|
232
|
+
|
|
233
|
+
NSStackView *content = [NSStackView stackViewWithViews:@[]];
|
|
234
|
+
content.orientation = NSUserInterfaceLayoutOrientationVertical;
|
|
235
|
+
content.spacing = 0;
|
|
236
|
+
content.translatesAutoresizingMaskIntoConstraints = NO;
|
|
237
|
+
FillCardContent(content, rows);
|
|
227
238
|
|
|
228
239
|
CCPetsCardView *card = [CCPetsCardView new];
|
|
229
240
|
card.translatesAutoresizingMaskIntoConstraints = NO;
|
|
@@ -2,17 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
extern NSString *const CCPetsPanelThemeKey;
|
|
4
4
|
NSString *CCPetsPanelTheme(void);
|
|
5
|
-
//
|
|
5
|
+
// 桌面小组件式玻璃背后压暗层的实际不透明度(百分比),0–45 之间连续可调,默认 25。
|
|
6
|
+
// 界面上统一换算成 0–100 的“强度”展示:100 对应实际 45。
|
|
6
7
|
// 主窗口用滑块连续调;右键菜单只列 CCPetsGlassDimLevels() 四档,勾选最接近当前值的那档。
|
|
7
8
|
extern NSString *const CCPetsGlassDimKey;
|
|
8
9
|
extern const NSInteger CCPetsGlassDimMaximum;
|
|
9
|
-
|
|
10
|
+
// 实际不透明度百分比(0–45,可带小数)。
|
|
11
|
+
double CCPetsGlassDimLevel(void);
|
|
12
|
+
// 展示用强度(0–100)。
|
|
13
|
+
NSInteger CCPetsGlassDimPercent(void);
|
|
14
|
+
// 强度(0–100)换算成实际不透明度百分比(0–45)。
|
|
15
|
+
double CCPetsGlassDimLevelForPercent(double percent);
|
|
16
|
+
// 菜单四档,单位是展示强度(0–100)。
|
|
10
17
|
NSArray<NSNumber *> *CCPetsGlassDimLevels(void);
|
|
11
|
-
// 四档里离
|
|
12
|
-
NSInteger CCPetsNearestGlassDimLevel(NSInteger
|
|
18
|
+
// 四档里离 percent 最近的一档;两档等距时取较小的。
|
|
19
|
+
NSInteger CCPetsNearestGlassDimLevel(NSInteger percent);
|
|
13
20
|
// 额度卡片衬底的不透明度,跟随压暗档位:卡片区域同时受背后压暗和衬底两层影响,
|
|
14
21
|
// 衬底固定的话选「通透」时卡片仍然很深。
|
|
15
22
|
CGFloat CCPetsGlassCardScrimAlpha(void);
|
|
23
|
+
// 同上,但按传入的实际压暗值(0–45)计算;设置页预览拖动滑块时用。
|
|
24
|
+
CGFloat CCPetsGlassCardScrimAlphaForLevel(double level);
|
|
25
|
+
|
|
26
|
+
// 宠物说话气泡的样式:真实气泡和设置页的 Liquid Glass 预览共用,改一处两边同步。
|
|
27
|
+
static const CGFloat CCPetsSpeechBubbleHeight = 38.0;
|
|
28
|
+
static const CGFloat CCPetsSpeechBubblePadding = 16.0;
|
|
29
|
+
static const CGFloat CCPetsSpeechBubbleFontSize = 13.0;
|
|
30
|
+
static const CGFloat CCPetsSpeechBubbleEdgeShadeHeight = 9.0;
|
|
31
|
+
static const CGFloat CCPetsSpeechBubbleEdgeShadeAlpha = 0.6;
|
|
32
|
+
// 玻璃上白字的贴字形投影(状态卡、气泡、额度面板一致)。
|
|
33
|
+
NSShadow *CCPetsGlassTextShadow(void);
|
|
16
34
|
// 运行系统和构建 SDK 都支持 NSGlassEffectView 时才为 YES。
|
|
17
35
|
BOOL CCPetsLiquidGlassAvailable(void);
|
|
18
36
|
|
|
@@ -27,9 +45,13 @@ BOOL CCPetsLiquidGlassAvailable(void);
|
|
|
27
45
|
// 胶囊形的状态卡、气泡比较矮,要在设置 usesWidgetGlass 之前调小。
|
|
28
46
|
@property(nonatomic) CGFloat edgeShadeHeight;
|
|
29
47
|
@property(nonatomic) CGFloat edgeShadeAlpha;
|
|
48
|
+
// 不看当前主题,始终用原生玻璃(设置页的 Liquid Glass 预览用);系统不支持时仍退回磨砂。
|
|
49
|
+
@property(nonatomic) BOOL forcesLiquidGlass;
|
|
30
50
|
- (instancetype)initWithFrame:(NSRect)frame material:(NSVisualEffectMaterial)material
|
|
31
51
|
appearance:(NSAppearanceName)appearance cornerRadius:(CGFloat)cornerRadius;
|
|
32
52
|
- (void)applyTheme;
|
|
33
53
|
// 只按当前档位更新压暗层透明度,不重建玻璃。
|
|
34
54
|
- (void)applyDimLevel;
|
|
55
|
+
// 按指定的实际压暗值(0–45)更新压暗层,不读偏好;预览拖动滑块时用。
|
|
56
|
+
- (void)applyDimLevel:(double)level;
|
|
35
57
|
@end
|
|
@@ -14,33 +14,54 @@ NSString *const CCPetsGlassDimKey = @"CCPetsGlassDim";
|
|
|
14
14
|
|
|
15
15
|
const NSInteger CCPetsGlassDimMaximum = 45;
|
|
16
16
|
|
|
17
|
-
NSArray<NSNumber *> *CCPetsGlassDimLevels(void) { return @[@0, @
|
|
17
|
+
NSArray<NSNumber *> *CCPetsGlassDimLevels(void) { return @[@0, @25, @50, @100]; }
|
|
18
18
|
|
|
19
19
|
// 档位来自对照实测:0 最通透但亮背景下小字看不清;25 在暗、亮壁纸上都基本可读;
|
|
20
20
|
// 45 最清楚但明显偏暗,再往上文字反而发闷,所以上限就是 45。没设置过时用 25;
|
|
21
|
-
// 超出范围的值(手改 defaults)夹回 0–45
|
|
22
|
-
|
|
21
|
+
// 超出范围的值(手改 defaults)夹回 0–45。界面按 0–100 展示,存的仍是实际值,可带小数
|
|
22
|
+
// (菜单的 25 / 50 档对应实际 11.25 / 22.5)。
|
|
23
|
+
double CCPetsGlassDimLevel(void) {
|
|
23
24
|
id stored = [NSUserDefaults.standardUserDefaults objectForKey:CCPetsGlassDimKey];
|
|
24
25
|
if (![stored isKindOfClass:NSNumber.class]) return 25;
|
|
25
26
|
double value = [stored doubleValue];
|
|
26
27
|
if (isnan(value)) return 25;
|
|
27
|
-
return MAX(
|
|
28
|
+
return MAX(0.0, MIN((double)CCPetsGlassDimMaximum, value));
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
NSInteger
|
|
31
|
+
NSInteger CCPetsGlassDimPercent(void) {
|
|
32
|
+
return lround(CCPetsGlassDimLevel() * 100.0 / CCPetsGlassDimMaximum);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
double CCPetsGlassDimLevelForPercent(double percent) {
|
|
36
|
+
return MAX(0.0, MIN(100.0, percent)) * CCPetsGlassDimMaximum / 100.0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
NSInteger CCPetsNearestGlassDimLevel(NSInteger percent) {
|
|
31
40
|
NSInteger nearest = 0;
|
|
32
41
|
for (NSNumber *candidate in CCPetsGlassDimLevels()) {
|
|
33
|
-
if (labs(candidate.integerValue -
|
|
42
|
+
if (labs(candidate.integerValue - percent) < labs(nearest - percent)) nearest = candidate.integerValue;
|
|
34
43
|
}
|
|
35
44
|
return nearest;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
// 衬底在四个档位上的取值是实测出来的(0.06 / 0.10 / 0.12 / 0.16),档位之间按直线插值,
|
|
39
48
|
// 滑块拖动时卡片深浅连续变化,不会在档位边界上跳一下。
|
|
49
|
+
NSShadow *CCPetsGlassTextShadow(void) {
|
|
50
|
+
NSShadow *shadow = [NSShadow new];
|
|
51
|
+
shadow.shadowColor = [NSColor colorWithWhite:0 alpha:0.45];
|
|
52
|
+
shadow.shadowBlurRadius = 2;
|
|
53
|
+
shadow.shadowOffset = NSMakeSize(0, -0.5);
|
|
54
|
+
return shadow;
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
CGFloat CCPetsGlassCardScrimAlpha(void) {
|
|
58
|
+
return CCPetsGlassCardScrimAlphaForLevel(CCPetsGlassDimLevel());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
CGFloat CCPetsGlassCardScrimAlphaForLevel(double level) {
|
|
41
62
|
static const double levels[] = {0, 15, 25, 45};
|
|
42
63
|
static const double alphas[] = {0.06, 0.10, 0.12, 0.16};
|
|
43
|
-
|
|
64
|
+
level = MAX(0.0, MIN((double)CCPetsGlassDimMaximum, level));
|
|
44
65
|
for (int index = 1; index < 4; index++) {
|
|
45
66
|
if (level > levels[index]) continue;
|
|
46
67
|
double fraction = (level - levels[index - 1]) / (levels[index] - levels[index - 1]);
|
|
@@ -144,7 +165,7 @@ BOOL CCPetsLiquidGlassAvailable(void) {
|
|
|
144
165
|
// 编译期和运行期双重保护,仍能用旧 SDK 构建并在 macOS 13 上运行。
|
|
145
166
|
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 260000
|
|
146
167
|
if (@available(macOS 26.0, *)) {
|
|
147
|
-
if ([CCPetsPanelTheme() isEqualToString:@"liquid"]) {
|
|
168
|
+
if (self.forcesLiquidGlass || [CCPetsPanelTheme() isEqualToString:@"liquid"]) {
|
|
148
169
|
NSGlassEffectView *glass = [[NSGlassEffectView alloc] initWithFrame:self.bounds];
|
|
149
170
|
glass.style = self.usesWidgetGlass
|
|
150
171
|
? NSGlassEffectViewStyleClear : NSGlassEffectViewStyleRegular;
|
|
@@ -236,11 +257,21 @@ static BOOL CCPetsExperimentalGlassVariantEnabled(void) {
|
|
|
236
257
|
#endif
|
|
237
258
|
|
|
238
259
|
- (void)applyDimLevel {
|
|
239
|
-
|
|
260
|
+
[self applyDimLevel:CCPetsGlassDimLevel()];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
- (void)applyDimLevel:(double)level {
|
|
264
|
+
CGFloat alpha = level / 100.0;
|
|
240
265
|
self.backdropDimView.layer.backgroundColor = [NSColor colorWithWhite:0 alpha:alpha].CGColor;
|
|
241
266
|
self.backdropDimView.hidden = alpha <= 0;
|
|
242
267
|
}
|
|
243
268
|
|
|
269
|
+
- (void)setForcesLiquidGlass:(BOOL)forcesLiquidGlass {
|
|
270
|
+
if (_forcesLiquidGlass == forcesLiquidGlass) return;
|
|
271
|
+
_forcesLiquidGlass = forcesLiquidGlass;
|
|
272
|
+
[self applyTheme];
|
|
273
|
+
}
|
|
274
|
+
|
|
244
275
|
- (void)setUsesWidgetGlass:(BOOL)usesWidgetGlass {
|
|
245
276
|
if (_usesWidgetGlass == usesWidgetGlass) return;
|
|
246
277
|
_usesWidgetGlass = usesWidgetGlass;
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
- (NSArray<NSDictionary *> *)petPickerOptions;
|
|
33
33
|
- (NSString *)currentPetID;
|
|
34
34
|
- (void)switchPetToID:(NSString *)petID;
|
|
35
|
+
// 删掉自己素材文件夹里的一只(builtin 的删不了);删的是当前那只会自动换到下一只。成功返回 YES。
|
|
36
|
+
- (BOOL)deletePetWithID:(NSString *)petID;
|
|
35
37
|
- (void)addClaudeProfile:(id)sender;
|
|
36
38
|
- (void)addCodexProfile:(id)sender;
|
|
37
39
|
- (void)repairAgentProfile:(NSMenuItem *)sender;
|