cc-pets 2.4.0 → 2.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +93 -14
- package/CC_BRIDGE.zh-CN.md +71 -11
- package/CHANGELOG.md +55 -0
- package/CHANGELOG.zh-CN.md +56 -1
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +116 -34
- package/README.zh-CN.md +99 -35
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +99 -26
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +51 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +120 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +24 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +24 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +33 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +24 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.m +18 -8
- package/Sources/CCPets/App/CCPetsVersion.h +4 -0
- package/Sources/CCPets/App/CCPetsVersion.m +34 -0
- package/Sources/CCPets/App/main.m +11 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +41 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +272 -50
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +341 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +227 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +35 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +310 -42
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +38 -8
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +11 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +217 -45
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +64 -5
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
- package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
- package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
- package/Sources/CCPets/Support/CCPetsPreferences.h +14 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +36 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +533 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +98 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +7 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +205 -8
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
- package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
- package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
- package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +6 -4
- package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
- package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
- package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
- package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
- package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
- package/THIRD_PARTY_NOTICES.md +5 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
- package/bin/agy-with-pet +82 -0
- package/bin/cc-pets +1 -1
- package/bin/claude-with-pet +15 -0
- package/bin/codex-with-pet +17 -2
- package/package.json +5 -3
- package/scripts/install-shell-integration.sh +5 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import "CCPetsL10n.h"
|
|
2
2
|
#import "CCPetsDoctor.h"
|
|
3
|
+
#import "CCPetsAntigravityConfig.h"
|
|
3
4
|
#import "CCPetsBridge.h"
|
|
4
5
|
#import "CCPetsBridgeSetup.h"
|
|
5
6
|
#import "CCPetsBridgeStore.h"
|
|
@@ -125,7 +126,17 @@ static NSDictionary *ReadJSONFile(NSString *file) {
|
|
|
125
126
|
|
|
126
127
|
#pragma mark - cc-pets paths
|
|
127
128
|
|
|
129
|
+
static NSString *ProfileHooksPath(NSDictionary *profile) {
|
|
130
|
+
NSString *provider = profile[@"provider"], *home = profile[@"home"];
|
|
131
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
132
|
+
return [home stringByAppendingPathComponent:@"config/hooks.json"];
|
|
133
|
+
}
|
|
134
|
+
return [home stringByAppendingPathComponent:
|
|
135
|
+
[provider isEqualToString:CCPetsProfileProviderClaude] ? @"settings.json" : @"hooks.json"];
|
|
136
|
+
}
|
|
137
|
+
|
|
128
138
|
static NSArray<NSDictionary *> *PathGroups(NSDictionary *native) {
|
|
139
|
+
NSString *agyHome = DefaultAntigravityConfigDirectory();
|
|
129
140
|
NSMutableArray *integrationItems = [NSMutableArray arrayWithArray:@[
|
|
130
141
|
@[PackageKind(), PackageDirectory()],
|
|
131
142
|
@[L(@"Installed app"), InstalledApp()],
|
|
@@ -134,13 +145,14 @@ static NSArray<NSDictionary *> *PathGroups(NSDictionary *native) {
|
|
|
134
145
|
stringByAppendingPathComponent:@"settings.json"]],
|
|
135
146
|
@[@"Codex Hooks", [[CCPetsHomeDirectory() stringByAppendingPathComponent:@".codex"]
|
|
136
147
|
stringByAppendingPathComponent:@"hooks.json"]],
|
|
148
|
+
@[L(@"Antigravity CLI hooks"), [agyHome stringByAppendingPathComponent:@"config/hooks.json"]],
|
|
149
|
+
@[L(@"Antigravity CLI MCP config"), [agyHome stringByAppendingPathComponent:@"config/mcp_config.json"]],
|
|
150
|
+
@[L(@"Antigravity CLI settings"), [agyHome stringByAppendingPathComponent:@"antigravity-cli/settings.json"]],
|
|
137
151
|
@[L(@"Shell config"), ShellRC()]
|
|
138
152
|
]];
|
|
139
153
|
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
140
154
|
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: profile[@"provider"];
|
|
141
|
-
|
|
142
|
-
[profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude] ? @"settings.json" : @"hooks.json"];
|
|
143
|
-
[integrationItems addObject:@[[NSString stringWithFormat:L(@"Agent profile: %@"), name], file]];
|
|
155
|
+
[integrationItems addObject:@[[NSString stringWithFormat:L(@"Agent profile: %@"), name], ProfileHooksPath(profile)]];
|
|
144
156
|
}
|
|
145
157
|
return @[
|
|
146
158
|
@{@"title": L(@"Settings (removed by --purge)"), @"items": @[@[L(@"Preferences"), native[@"preferences"]]]},
|
|
@@ -149,7 +161,7 @@ static NSArray<NSDictionary *> *PathGroups(NSDictionary *native) {
|
|
|
149
161
|
@[L(@"Shared lines"), native[@"phrases"]],
|
|
150
162
|
@[L(@"Per-pet lines"), native[@"petPhrases"]],
|
|
151
163
|
@[L(@"CC Bridge switch"), [CCBridgeHomeDirectory() stringByAppendingPathComponent:@"bridge-enabled"]],
|
|
152
|
-
@[@"
|
|
164
|
+
@[L(@"Agent shims"), CCPetsShimDirectory()]
|
|
153
165
|
]},
|
|
154
166
|
@{@"title": L(@"App data (removed by --purge; clean only clears the token cache and update log)"), @"items": @[
|
|
155
167
|
@[L(@"App data directory"), native[@"applicationSupport"]],
|
|
@@ -278,6 +290,19 @@ static NSArray<NSDictionary *> *HookChecks(NSString *name, NSString *configFile,
|
|
|
278
290
|
return results;
|
|
279
291
|
}
|
|
280
292
|
|
|
293
|
+
static NSDictionary *AntigravityHookCheck(NSDictionary *profile) {
|
|
294
|
+
NSString *name = profile[@"displayName"] ?: @"Antigravity CLI";
|
|
295
|
+
NSString *path = ProfileHooksPath(profile);
|
|
296
|
+
NSDictionary *read = ReadJSONFile(path);
|
|
297
|
+
if ([read[@"error"] isEqualToString:@"invalid"] || (read[@"value"] && ![read[@"value"] isKindOfClass:NSDictionary.class])) {
|
|
298
|
+
return Result(@"fail", LF(L(@"Can't parse {name} config: {configFile}"),
|
|
299
|
+
(@{@"name": name, @"configFile": CCPetsTildePath(path)})), L(@"Fix that JSON file, then run cc-pets install"));
|
|
300
|
+
}
|
|
301
|
+
return CCPetsAntigravityPetHooksInstalled(profile)
|
|
302
|
+
? Result(@"ok", LF(L(@"{name} hooks installed"), @{@"name": name}), nil)
|
|
303
|
+
: Result(@"fail", LF(L(@"{name} hooks not installed"), @{@"name": name}), @"cc-pets install");
|
|
304
|
+
}
|
|
305
|
+
|
|
281
306
|
static NSDictionary *StatusLineCheckAtHome(NSString *home) {
|
|
282
307
|
NSDictionary *value = ReadJSONFile([home stringByAppendingPathComponent:@"settings.json"])[@"value"];
|
|
283
308
|
NSDictionary *statusLine = [value isKindOfClass:NSDictionary.class] && [value[@"statusLine"] isKindOfClass:NSDictionary.class]
|
|
@@ -308,7 +333,8 @@ static NSArray<NSDictionary *> *ShimChecks(BOOL inApp) {
|
|
|
308
333
|
|
|
309
334
|
NSString *shimDirectory = CCPetsShimDirectory();
|
|
310
335
|
NSMutableArray<NSString *> *broken = [NSMutableArray array];
|
|
311
|
-
|
|
336
|
+
NSArray<NSString *> *names = @[@"codex", @"claude", @"agy"];
|
|
337
|
+
for (NSString *name in names) {
|
|
312
338
|
NSString *link = [NSFileManager.defaultManager destinationOfSymbolicLinkAtPath:[shimDirectory stringByAppendingPathComponent:name] error:nil];
|
|
313
339
|
if (!link) {
|
|
314
340
|
[broken addObject:LF(L(@"{name} (missing)"), @{@"name": name})];
|
|
@@ -335,17 +361,17 @@ static NSArray<NSDictionary *> *ShimChecks(BOOL inApp) {
|
|
|
335
361
|
NSUInteger index = [entries indexOfObject:shimDirectory];
|
|
336
362
|
NSString *sourceHint = LF(L(@"source {shellRC}, or open a new terminal"), @{@"shellRC": CCPetsTildePath(shellRC)});
|
|
337
363
|
if (index == NSNotFound) {
|
|
338
|
-
[results addObject:Result(@"warn", L(@"This terminal's PATH lacks the shim directory, so
|
|
364
|
+
[results addObject:Result(@"warn", L(@"This terminal's PATH lacks the shim directory, so the Agent launchers won't start the pet"), sourceHint)];
|
|
339
365
|
} else if (index > 0) {
|
|
340
366
|
NSString *shadowing = nil;
|
|
341
367
|
for (NSString *entry in [entries subarrayWithRange:NSMakeRange(0, index)]) {
|
|
342
|
-
for (NSString *name in
|
|
368
|
+
for (NSString *name in names) {
|
|
343
369
|
if (!shadowing && [NSFileManager.defaultManager fileExistsAtPath:[entry stringByAppendingPathComponent:name]]) shadowing = entry;
|
|
344
370
|
}
|
|
345
371
|
}
|
|
346
372
|
[results addObject:shadowing
|
|
347
373
|
? Result(@"warn", LF(L(@"{shadowing} comes before the shim directory in PATH and bypasses the pet"), @{@"shadowing": CCPetsTildePath(shadowing)}), sourceHint)
|
|
348
|
-
: Result(@"ok", L(@"The shim directory comes before the real
|
|
374
|
+
: Result(@"ok", L(@"The shim directory comes before the real Agent binaries in PATH"), nil)];
|
|
349
375
|
} else {
|
|
350
376
|
[results addObject:Result(@"ok", L(@"The shim directory is first in PATH"), nil)];
|
|
351
377
|
}
|
|
@@ -355,7 +381,7 @@ static NSArray<NSDictionary *> *ShimChecks(BOOL inApp) {
|
|
|
355
381
|
// searchPath:主窗口传登录 shell 的 PATH,终端里传 nil 用自身 PATH。
|
|
356
382
|
static NSString *FindRealBinary(NSString *name, NSString *variable, NSString *searchPath) {
|
|
357
383
|
NSString *real = CCPetsFindRealExecutableInPath(name, variable, searchPath ?: CCPetsEnvironmentValue(@"PATH"));
|
|
358
|
-
return real && [NSFileManager.defaultManager
|
|
384
|
+
return real && [NSFileManager.defaultManager isExecutableFileAtPath:real] ? real : nil;
|
|
359
385
|
}
|
|
360
386
|
|
|
361
387
|
static NSDictionary *RealBinaryCheck(NSString *name, NSString *variable, NSString *searchPath, BOOL inApp) {
|
|
@@ -401,6 +427,8 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
401
427
|
NSMutableArray<NSDictionary *> *sections = [NSMutableArray array];
|
|
402
428
|
BOOL claudeDetected = CCPetsClaudeCLIInstalled();
|
|
403
429
|
BOOL codexDetected = CCPetsCodexCLIInstalled();
|
|
430
|
+
BOOL agyDetected = CCPetsDirectoryExists([DefaultAntigravityConfigDirectory() stringByAppendingPathComponent:@"antigravity-cli"]) ||
|
|
431
|
+
CCPetsFindRealExecutable(@"agy", @"AGY_REAL_BIN") != nil;
|
|
404
432
|
NSString *packageVersion = PackageVersion();
|
|
405
433
|
|
|
406
434
|
NSMutableArray<NSDictionary *> *program = [NSMutableArray arrayWithObject:
|
|
@@ -432,19 +460,19 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
432
460
|
for (NSDictionary *profile in registeredProfiles) {
|
|
433
461
|
NSString *provider = profile[@"provider"];
|
|
434
462
|
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: provider;
|
|
435
|
-
NSString *file = [profile[@"home"] stringByAppendingPathComponent:
|
|
436
|
-
[provider isEqualToString:CCPetsProfileProviderClaude] ? @"settings.json" : @"hooks.json"];
|
|
437
463
|
NSUInteger bridgeHooks = 0;
|
|
438
|
-
NSMutableArray *checks
|
|
439
|
-
|
|
440
|
-
[
|
|
441
|
-
|
|
442
|
-
profileBridgeHooks[profile[@"id"]] = @(bridgeHooks);
|
|
443
|
-
if ([provider isEqualToString:CCPetsProfileProviderClaude]) {
|
|
444
|
-
[checks addObject:StatusLineCheckAtHome(profile[@"home"])];
|
|
464
|
+
NSMutableArray *checks;
|
|
465
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
466
|
+
checks = [NSMutableArray arrayWithObject:AntigravityHookCheck(profile)];
|
|
467
|
+
bridgeHooks = CCPetsAntigravityBridgeInstalled(profile);
|
|
445
468
|
} else {
|
|
446
|
-
|
|
469
|
+
BOOL claude = [provider isEqualToString:CCPetsProfileProviderClaude];
|
|
470
|
+
checks = [HookChecks(name, ProfileHooksPath(profile), claude ? CCPetsClaudeHookMarker : CCPetsCodexHookMarker,
|
|
471
|
+
claude ? CCPetsLegacyClaudeHookMarker : CCPetsLegacyCodexHookMarker, &bridgeHooks) mutableCopy];
|
|
472
|
+
if (claude) [checks addObject:StatusLineCheckAtHome(profile[@"home"])];
|
|
473
|
+
else [checks addObject:Result(@"info", L(@"Codex only runs CC Pets hooks after you trust them in /hooks (can't be checked automatically)"), nil)];
|
|
447
474
|
}
|
|
475
|
+
profileBridgeHooks[profile[@"id"]] = @(bridgeHooks);
|
|
448
476
|
for (NSUInteger index = 0; index < checks.count; index++) {
|
|
449
477
|
NSDictionary *check = checks[index];
|
|
450
478
|
if ([check[@"fix"] isEqualToString:@"cc-pets install"]) {
|
|
@@ -461,24 +489,41 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
461
489
|
}
|
|
462
490
|
|
|
463
491
|
// Finder 拉起的主窗口只有 launchd 的最小 PATH,nvm / Homebrew 下的 CLI 都不在里面,改用登录 shell 的。
|
|
464
|
-
NSString *searchPath = inApp && (codexDetected || claudeDetected) ? CCPetsLoginShellPath() : nil;
|
|
492
|
+
NSString *searchPath = inApp && (codexDetected || claudeDetected || agyDetected) ? CCPetsLoginShellPath() : nil;
|
|
465
493
|
NSMutableArray *shell = [ShimChecks(inApp) mutableCopy];
|
|
466
494
|
if (codexDetected) [shell addObject:RealBinaryCheck(@"codex", @"CODEX_REAL_BIN", searchPath, inApp)];
|
|
467
495
|
if (claudeDetected) [shell addObject:RealBinaryCheck(@"claude", @"CLAUDE_REAL_BIN", searchPath, inApp)];
|
|
496
|
+
if (agyDetected) [shell addObject:RealBinaryCheck(@"agy", @"AGY_REAL_BIN", searchPath, inApp)];
|
|
468
497
|
[sections addObject:@{@"title": L(@"Shell integration"), @"results": shell}];
|
|
469
498
|
|
|
470
499
|
if (!CCBridgeEnabled()) {
|
|
471
500
|
[sections addObject:@{@"title": @"CC Bridge", @"results": @[Result(@"info", L(@"Off (optional; turn on with cc-pets bridge enable)"), nil)]}];
|
|
472
501
|
} else {
|
|
473
502
|
NSMutableArray *bridge = [NSMutableArray arrayWithObject:Result(@"ok", L(@"Enabled"), nil)];
|
|
503
|
+
BOOL agyAppEnabled = [CCBridgeOptions()[@"antigravityApp"] boolValue];
|
|
474
504
|
for (NSDictionary *profile in registeredProfiles) {
|
|
475
505
|
NSString *name = profile[@"displayName"] ?: profile[@"slug"] ?: profile[@"provider"];
|
|
506
|
+
BOOL antigravity = [profile[@"provider"] isEqualToString:CCPetsProfileProviderAntigravity];
|
|
507
|
+
NSString *installed = antigravity ? L(@"CC Bridge hooks and MCP installed in %@") : L(@"CC Bridge hooks installed in %@");
|
|
508
|
+
NSString *missing = antigravity ? L(@"CC Bridge hooks or MCP missing in %@") : L(@"CC Bridge hooks missing in %@");
|
|
476
509
|
NSDictionary *result = [profileBridgeHooks[profile[@"id"]] unsignedIntegerValue] > 0
|
|
477
|
-
? Result(@"ok", [NSString stringWithFormat:
|
|
478
|
-
: Result(@"warn", [NSString stringWithFormat:
|
|
510
|
+
? Result(@"ok", [NSString stringWithFormat:installed, name], nil)
|
|
511
|
+
: Result(@"warn", [NSString stringWithFormat:missing, name], @"cc-pets bridge enable");
|
|
479
512
|
NSMutableDictionary *check = [result mutableCopy];
|
|
480
513
|
check[@"profileID"] = profile[@"id"];
|
|
514
|
+
if (antigravity && [result[@"level"] isEqualToString:@"warn"] &&
|
|
515
|
+
[AntigravityHookCheck(profile)[@"level"] isEqualToString:@"ok"]) {
|
|
516
|
+
check[@"repairProfileID"] = profile[@"id"];
|
|
517
|
+
}
|
|
481
518
|
[bridge addObject:check];
|
|
519
|
+
if (antigravity && agyAppEnabled && CCPetsProfileIsOfficialDefault(profile)) {
|
|
520
|
+
BOOL installedSidecar = CCPetsAntigravityAppSidecarInstalled(profile);
|
|
521
|
+
NSMutableDictionary *sidecar = [Result(installedSidecar ? @"ok" : @"warn",
|
|
522
|
+
installedSidecar ? L(@"Antigravity App Sidecar configured") : L(@"Antigravity App Sidecar needs repair"),
|
|
523
|
+
installedSidecar ? nil : @"cc-pets bridge configure --agy-app=on") mutableCopy];
|
|
524
|
+
if (!installedSidecar) sidecar[@"repairProfileID"] = profile[@"id"];
|
|
525
|
+
[bridge addObject:sidecar];
|
|
526
|
+
}
|
|
482
527
|
}
|
|
483
528
|
if (codexDetected) {
|
|
484
529
|
if ([CCBridgeOptions()[@"wake"] boolValue]) {
|
|
@@ -498,6 +543,9 @@ static NSArray<NSDictionary *> *DoctorSections(BOOL inApp) {
|
|
|
498
543
|
}
|
|
499
544
|
}
|
|
500
545
|
}
|
|
546
|
+
if (agyDetected && [CCBridgeOptions()[@"wake"] boolValue]) {
|
|
547
|
+
[bridge addObject:Result(@"info", L(@"Antigravity CLI reads Bridge messages on its next model invocation."), nil)];
|
|
548
|
+
}
|
|
501
549
|
[sections addObject:@{@"title": @"CC Bridge", @"results": bridge}];
|
|
502
550
|
}
|
|
503
551
|
|
|
@@ -561,13 +609,29 @@ static int RepairProfile(NSString *profileID) {
|
|
|
561
609
|
return 1;
|
|
562
610
|
}
|
|
563
611
|
BOOL claude = [profile[@"provider"] isEqualToString:CCPetsProfileProviderClaude];
|
|
612
|
+
BOOL antigravity = [profile[@"provider"] isEqualToString:CCPetsProfileProviderAntigravity];
|
|
613
|
+
BOOL repairAntigravityBridge = antigravity && CCBridgeEnabled();
|
|
614
|
+
BOOL repairAntigravityApp = repairAntigravityBridge && CCPetsProfileIsOfficialDefault(profile) &&
|
|
615
|
+
[CCBridgeOptions()[@"antigravityApp"] boolValue];
|
|
564
616
|
NSArray<NSString *> *files = claude ? CCPetsClaudeIntegrationFilesAtHome(profile[@"home"])
|
|
565
|
-
: @[
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
617
|
+
: @[ProfileHooksPath(profile)];
|
|
618
|
+
if (antigravity) {
|
|
619
|
+
NSString *home = profile[@"home"];
|
|
620
|
+
files = [files arrayByAddingObject:[home stringByAppendingPathComponent:@"antigravity-cli/settings.json"]];
|
|
621
|
+
if (repairAntigravityBridge) files = [files arrayByAddingObject:[home stringByAppendingPathComponent:@"config/mcp_config.json"]];
|
|
622
|
+
if (repairAntigravityApp) files = [files arrayByAddingObjectsFromArray:@[
|
|
623
|
+
[home stringByAppendingPathComponent:@"config/config.json"],
|
|
624
|
+
[home stringByAppendingPathComponent:@"config/sidecars/cc-pets-bridge/sidecar.json"]
|
|
625
|
+
]];
|
|
626
|
+
}
|
|
627
|
+
for (NSString *path in antigravity ? files : @[files.firstObject]) {
|
|
628
|
+
NSString *parseError = nil;
|
|
629
|
+
id config = antigravity ? CCPetsReadAntigravityConfig(path, &parseError) : CCPetsReadConfig(path, &parseError);
|
|
630
|
+
if (parseError || (config && ![config isKindOfClass:CCPetsJSONObject.class])) {
|
|
631
|
+
CCPetsPrintLine(stderr, [NSString stringWithFormat:@"%@: %@", CCPetsTildePath(path),
|
|
632
|
+
parseError ?: L(@"The Agent configuration must be a JSON object.")]);
|
|
633
|
+
return 1;
|
|
634
|
+
}
|
|
571
635
|
}
|
|
572
636
|
NSString *backup = [[ApplicationSupportDirectory() stringByAppendingPathComponent:@"diagnostic-backups"]
|
|
573
637
|
stringByAppendingPathComponent:NSUUID.UUID.UUIDString];
|
|
@@ -606,16 +670,41 @@ static int RepairProfile(NSString *profileID) {
|
|
|
606
670
|
return 1;
|
|
607
671
|
}
|
|
608
672
|
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"Configuration backup: %@"), CCPetsTildePath(backup)]);
|
|
609
|
-
int status = claude ? InstallClaudeHooksAtHome(binary, profile[@"home"])
|
|
610
|
-
: InstallCodexHooksAtHome(binary, profile[@"home"]);
|
|
611
|
-
if (status != 0) return status;
|
|
612
|
-
|
|
613
673
|
// 安装返回成功后重新读配置;未恢复的 Hooks / status line 不能清掉待修复状态。
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
674
|
+
NSMutableArray<NSDictionary *> *checks;
|
|
675
|
+
if (antigravity) {
|
|
676
|
+
@try {
|
|
677
|
+
NSArray *report = repairAntigravityBridge ? CCBridgeInstallForProfile(profile, CCBridgeOptions(), YES)
|
|
678
|
+
: CCPetsInstallAntigravityPetHooks(profile);
|
|
679
|
+
BOOL failed = NO;
|
|
680
|
+
for (NSString *line in report) {
|
|
681
|
+
BOOL errorLine = [line hasPrefix:@"ERROR: "];
|
|
682
|
+
CCPetsPrintLine(errorLine ? stderr : stdout, line);
|
|
683
|
+
failed |= errorLine;
|
|
684
|
+
}
|
|
685
|
+
if (failed) return 1;
|
|
686
|
+
} @catch (NSException *exception) {
|
|
687
|
+
CCPetsPrintLine(stderr, exception.reason ?: exception.name);
|
|
688
|
+
return 1;
|
|
689
|
+
}
|
|
690
|
+
checks = [NSMutableArray arrayWithObject:AntigravityHookCheck(profile)];
|
|
691
|
+
if (repairAntigravityBridge && !CCPetsAntigravityBridgeInstalled(profile)) {
|
|
692
|
+
[checks addObject:Result(@"fail", [NSString stringWithFormat:L(@"CC Bridge hooks or MCP missing in %@"),
|
|
693
|
+
profile[@"displayName"] ?: profileID], nil)];
|
|
694
|
+
}
|
|
695
|
+
if (repairAntigravityApp && !CCPetsAntigravityAppSidecarInstalled(profile)) {
|
|
696
|
+
[checks addObject:Result(@"fail", L(@"Antigravity App Sidecar needs repair"), nil)];
|
|
697
|
+
}
|
|
698
|
+
} else {
|
|
699
|
+
int status = claude ? InstallClaudeHooksAtHome(binary, profile[@"home"])
|
|
700
|
+
: InstallCodexHooksAtHome(binary, profile[@"home"]);
|
|
701
|
+
if (status != 0) return status;
|
|
702
|
+
NSUInteger bridgeHooks = 0;
|
|
703
|
+
checks = [HookChecks(profile[@"displayName"] ?: profileID, files.firstObject,
|
|
704
|
+
claude ? CCPetsClaudeHookMarker : CCPetsCodexHookMarker,
|
|
705
|
+
claude ? CCPetsLegacyClaudeHookMarker : CCPetsLegacyCodexHookMarker, &bridgeHooks) mutableCopy];
|
|
706
|
+
if (claude) [checks addObject:StatusLineCheckAtHome(profile[@"home"])];
|
|
707
|
+
}
|
|
619
708
|
for (NSDictionary *check in checks) {
|
|
620
709
|
if ([check[@"level"] isEqualToString:@"ok"]) continue;
|
|
621
710
|
CCPetsPrintLine(stderr, check[@"title"]);
|
|
@@ -20,6 +20,10 @@ NSString *DefaultClaudeConfigDirectory(void);
|
|
|
20
20
|
NSString *CurrentClaudeConfigDirectory(void);
|
|
21
21
|
// 桌宠端用:只看主账号的 Codex 目录,不受继承来的 CODEX_HOME 影响。
|
|
22
22
|
NSString *DefaultCodexHomeDirectory(void);
|
|
23
|
+
// Gemini 根目录,包含 Antigravity CLI 自己的 antigravity-cli/ 子目录。
|
|
24
|
+
NSString *DefaultAntigravityConfigDirectory(void);
|
|
25
|
+
// 桌面 App 固定使用官方 Gemini 根目录,不受 CLI 的目录覆盖影响。
|
|
26
|
+
NSString *DefaultAntigravityAppConfigDirectory(void);
|
|
23
27
|
NSString *ClaudeUsagePathForConfigDirectory(NSString *configDirectory);
|
|
24
28
|
// Token 会话摘要缓存的落盘位置,按 provider 与数据源目录分文件。
|
|
25
29
|
NSString *TokenSummaryCachePath(NSString *provider, NSString *sourceDirectory);
|
|
@@ -56,6 +60,7 @@ extern NSString *const SystemMemoryEnabledKey;
|
|
|
56
60
|
// 每个 Provider 独立保存额度卡展示模式,值为 "subscription" 或 "api"。
|
|
57
61
|
extern NSString *const CodexUsageDisplayModeKey;
|
|
58
62
|
extern NSString *const ClaudeUsageDisplayModeKey;
|
|
63
|
+
extern NSString *const AntigravityUsageDisplayModeKey;
|
|
59
64
|
// 曾经检测到过的 provider 集合。只增不减:探测有可能瞬时失败(配置目录被临时改名、
|
|
60
65
|
// 外置盘没挂上),而卡片突然消失比多显示一张空卡更像 bug。
|
|
61
66
|
extern NSString *const DetectedProvidersKey;
|
|
@@ -38,6 +38,20 @@ NSString *DefaultCodexHomeDirectory(void) {
|
|
|
38
38
|
return [NSHomeDirectory() stringByAppendingPathComponent:@".codex"];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
NSString *DefaultAntigravityConfigDirectory(void) {
|
|
42
|
+
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_ANTIGRAVITY_HOME"];
|
|
43
|
+
if (override.length > 0) return override.stringByStandardizingPath;
|
|
44
|
+
return DefaultAntigravityAppConfigDirectory();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 与账号登记(CCPetsProfiles 的官方 Home)一致地遵循 $HOME;NSHomeDirectory() 只看账户
|
|
48
|
+
// 记录,两边不一致时按目录查不到已登记的账号。
|
|
49
|
+
NSString *DefaultAntigravityAppConfigDirectory(void) {
|
|
50
|
+
NSString *home = NSProcessInfo.processInfo.environment[@"HOME"];
|
|
51
|
+
if (!home.isAbsolutePath) home = NSHomeDirectory();
|
|
52
|
+
return [home stringByAppendingPathComponent:@".gemini"];
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
// 额度是按账号的。一台机器上可以有多个配置目录(例如 ~/.claude 和 ~/.claude-nw),
|
|
42
56
|
// 各自是不同账号、不同额度周期。共用一个文件的话两边的 statusline 会互相覆盖,
|
|
43
57
|
// 面板就会把 A 账号的剩余百分比配上 B 账号的用量。因此按配置目录分文件。
|
|
@@ -235,6 +249,7 @@ NSString *const SystemTemperatureEnabledKey = @"CCPetsSystemTemperatureEnabled";
|
|
|
235
249
|
NSString *const SystemMemoryEnabledKey = @"CCPetsSystemMemoryEnabled";
|
|
236
250
|
NSString *const CodexUsageDisplayModeKey = @"CCPetsCodexUsageDisplayMode";
|
|
237
251
|
NSString *const ClaudeUsageDisplayModeKey = @"CCPetsClaudeUsageDisplayMode";
|
|
252
|
+
NSString *const AntigravityUsageDisplayModeKey = @"CCPetsAntigravityUsageDisplayMode";
|
|
238
253
|
NSString *const DetectedProvidersKey = @"CCPetsDetectedProviders";
|
|
239
254
|
const NSTimeInterval AgentStatusInactivityInterval = 60.0;
|
|
240
255
|
// 客户端进程已经消失、但状态气泡还停在它最后一条事件上时,多等这么久再清场。
|
|
@@ -18,11 +18,24 @@ extern NSString *const PetInteractionIntervalKey;
|
|
|
18
18
|
// 启动保护按代理软件分别保存;增加软件时定义独立的布尔键。
|
|
19
19
|
extern NSString *const CCPetsShadowrocketLaunchCheckKey;
|
|
20
20
|
|
|
21
|
+
// 显示位置:仅桌宠(默认)/ 桌宠 + 菜单栏 / 仅菜单栏。字符串而不是整数,以后加模式不错位。
|
|
22
|
+
extern NSString *const CCPetsDisplayModeKey;
|
|
23
|
+
extern NSString *const CCPetsDisplayModePet;
|
|
24
|
+
extern NSString *const CCPetsDisplayModeBoth;
|
|
25
|
+
extern NSString *const CCPetsDisplayModeMenuBar;
|
|
26
|
+
// 菜单栏图标旁常驻显示最低的 5 小时剩余额度。默认关;低于 20% 时不论开关都会显示。
|
|
27
|
+
extern NSString *const CCPetsMenuBarShowsPercentKey;
|
|
28
|
+
// 悬停额度卡使用稳定的 Provider key 保存顺序,空数组表示自动排序。
|
|
29
|
+
extern NSString *const CCPetsQuotaCardOrderKey;
|
|
30
|
+
NSArray<NSString *> *CCPetsQuotaCardOrder(void);
|
|
31
|
+
// 规整后的显示位置:没写过或写了未知值都按仅桌宠处理。
|
|
32
|
+
NSString *CCPetsDisplayMode(void);
|
|
33
|
+
|
|
21
34
|
// 布尔设置。碎碎念这类"没写过就算开"的键在这里统一兜底,调用方不必各自判 nil。
|
|
22
35
|
BOOL CCPetsPrefBool(NSString *key);
|
|
23
36
|
void CCPetsPrefSetBool(NSString *key, BOOL value);
|
|
24
37
|
|
|
25
|
-
//
|
|
38
|
+
// 写字符串、数字或额度卡顺序。数值键会先钳到合法范围(宠物缩放、点击互动阈值与间隔);
|
|
26
39
|
// 规整后不合法(NaN 之类)时不写,返回 NO。value 为 nil 表示删除该键,交回默认值。
|
|
27
40
|
BOOL CCPetsPrefSetObject(NSString *key, id value);
|
|
28
41
|
|
|
@@ -11,6 +11,38 @@ NSString *const PetInteractionHeartThresholdKey = @"CCPetsInteractionHeartThresh
|
|
|
11
11
|
NSString *const PetInteractionAnnoyedThresholdKey = @"CCPetsInteractionAnnoyedThreshold";
|
|
12
12
|
NSString *const PetInteractionIntervalKey = @"CCPetsInteractionInterval";
|
|
13
13
|
NSString *const CCPetsShadowrocketLaunchCheckKey = @"CCPetsLaunchProtection.Shadowrocket";
|
|
14
|
+
NSString *const CCPetsDisplayModeKey = @"CCPetsDisplayMode";
|
|
15
|
+
NSString *const CCPetsDisplayModePet = @"pet";
|
|
16
|
+
NSString *const CCPetsDisplayModeBoth = @"both";
|
|
17
|
+
NSString *const CCPetsDisplayModeMenuBar = @"menubar";
|
|
18
|
+
NSString *const CCPetsMenuBarShowsPercentKey = @"CCPetsMenuBarShowsPercent";
|
|
19
|
+
NSString *const CCPetsQuotaCardOrderKey = @"CCPetsQuotaCardOrder";
|
|
20
|
+
|
|
21
|
+
static NSArray<NSString *> *DisplayModes(void) {
|
|
22
|
+
return @[CCPetsDisplayModePet, CCPetsDisplayModeBoth, CCPetsDisplayModeMenuBar];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
NSString *CCPetsDisplayMode(void) {
|
|
26
|
+
id value = [NSUserDefaults.standardUserDefaults objectForKey:CCPetsDisplayModeKey];
|
|
27
|
+
return [value isKindOfClass:NSString.class] && [DisplayModes() containsObject:value]
|
|
28
|
+
? value : CCPetsDisplayModePet;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static NSArray<NSString *> *NormalizedQuotaCardOrder(id value) {
|
|
32
|
+
if (![value isKindOfClass:NSArray.class]) return nil;
|
|
33
|
+
NSCharacterSet *invalid = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyz0123456789-"].invertedSet;
|
|
34
|
+
NSMutableOrderedSet<NSString *> *order = [NSMutableOrderedSet orderedSet];
|
|
35
|
+
for (id entry in value) {
|
|
36
|
+
if (![entry isKindOfClass:NSString.class]) continue;
|
|
37
|
+
NSString *key = [[entry stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] lowercaseString];
|
|
38
|
+
if (key.length > 0 && [key rangeOfCharacterFromSet:invalid].location == NSNotFound) [order addObject:key];
|
|
39
|
+
}
|
|
40
|
+
return order.array;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
NSArray<NSString *> *CCPetsQuotaCardOrder(void) {
|
|
44
|
+
return NormalizedQuotaCardOrder([NSUserDefaults.standardUserDefaults objectForKey:CCPetsQuotaCardOrderKey]) ?: @[];
|
|
45
|
+
}
|
|
14
46
|
|
|
15
47
|
// 包装器运行的是裸二进制,默认 preferences domain 与 App bundle 不同。
|
|
16
48
|
// 启动保护的读取和写入统一走 CFPreferences 的同一个域、用户和主机。
|
|
@@ -79,6 +111,7 @@ static NSNumber *ClampedNumber(id value, double minimum, double maximum) {
|
|
|
79
111
|
// 下限与右键菜单原先各 setter 里的钳制逐条对应,改这里等于改菜单行为。
|
|
80
112
|
id CCPetsPrefNormalizedValue(NSString *key, id value) {
|
|
81
113
|
if (value == nil) return nil;
|
|
114
|
+
if ([key isEqualToString:CCPetsQuotaCardOrderKey]) return NormalizedQuotaCardOrder(value);
|
|
82
115
|
if ([key isEqualToString:CCPetsPetScaleKey]) {
|
|
83
116
|
NSNumber *scale = ClampedNumber(value, CCPetsPetMinimumScale, CCPetsPetMaximumScale);
|
|
84
117
|
// 滑动条连续拖动会给出 0.8734 这种值,按百分比取整,免得 defaults 里存一串小数。
|
|
@@ -96,6 +129,9 @@ id CCPetsPrefNormalizedValue(NSString *key, id value) {
|
|
|
96
129
|
return count ? @(count.integerValue) : nil;
|
|
97
130
|
}
|
|
98
131
|
if ([key isEqualToString:PetInteractionIntervalKey]) return ClampedNumber(value, 0.4, 3.0);
|
|
132
|
+
if ([key isEqualToString:CCPetsDisplayModeKey]) {
|
|
133
|
+
return [value isKindOfClass:NSString.class] && [DisplayModes() containsObject:value] ? value : nil;
|
|
134
|
+
}
|
|
99
135
|
if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class]) return value;
|
|
100
136
|
return nil;
|
|
101
137
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
#import "CCPetsMenuBarSummary.h"
|
|
3
|
+
|
|
4
|
+
// 菜单栏图标:描边的终端窗口,颜色随状态变化;符号只有等待审批时换成 •••,其余都是 >_:
|
|
5
|
+
//
|
|
6
|
+
// 待机 原色(template,系统按菜单栏明暗显示白或黑) >_
|
|
7
|
+
// 工作中 系统蓝 >_
|
|
8
|
+
// 审批 系统橙 •••
|
|
9
|
+
// 完成 系统绿 >_
|
|
10
|
+
// 失败 系统红 >_
|
|
11
|
+
//
|
|
12
|
+
// 单色线条:16pt 下双色、渐变和发光都看不出来,template 也只认单色。框内透出菜单栏底色。
|
|
13
|
+
extern const NSSize CCPetsMenuBarIconSize;
|
|
14
|
+
|
|
15
|
+
// 每次调用都会新建图片,调用方按色调缓存(系统色是动态色,绘制时按菜单栏外观解析,缓存不会过期)。
|
|
16
|
+
NSImage *CCPetsMenuBarIconImage(CCPetsMenuBarIconTone tone);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#import "CCPetsMenuBarIcon.h"
|
|
2
|
+
|
|
3
|
+
const NSSize CCPetsMenuBarIconSize = {18, 16};
|
|
4
|
+
|
|
5
|
+
// 线宽 1.6pt:Retina 下约 3 像素,和系统菜单栏图标的笔画分量接近。
|
|
6
|
+
static const CGFloat IconLineWidth = 1.6;
|
|
7
|
+
|
|
8
|
+
// 用系统色而不是状态卡的颜色:系统色按菜单栏明暗各有一版,深色菜单栏上取更亮的那版;
|
|
9
|
+
// 状态卡的工作蓝 (0.33, 0.53, 0.78) 是为浅色玻璃调的,放在深色菜单栏上发灰看不清。
|
|
10
|
+
static NSColor *ToneColor(CCPetsMenuBarIconTone tone) {
|
|
11
|
+
switch (tone) {
|
|
12
|
+
case CCPetsMenuBarIconToneWorking: return NSColor.systemBlueColor;
|
|
13
|
+
case CCPetsMenuBarIconToneAttention: return NSColor.systemOrangeColor;
|
|
14
|
+
case CCPetsMenuBarIconToneCompleted: return NSColor.systemGreenColor;
|
|
15
|
+
case CCPetsMenuBarIconToneFailed: return NSColor.systemRedColor;
|
|
16
|
+
default: return NSColor.blackColor;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static NSBezierPath *StrokePath(void) {
|
|
21
|
+
NSBezierPath *path = [NSBezierPath bezierPath];
|
|
22
|
+
path.lineWidth = IconLineWidth;
|
|
23
|
+
path.lineCapStyle = NSLineCapStyleRound;
|
|
24
|
+
path.lineJoinStyle = NSLineJoinStyleRound;
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 窗口里的符号,以窗口中心 (9, 8) 为基准:只有等待审批换成 •••(唯一需要用户动手的状态),
|
|
29
|
+
// 其余都是 >_,靠颜色区分。
|
|
30
|
+
static void DrawGlyph(CCPetsMenuBarIconTone tone) {
|
|
31
|
+
NSBezierPath *path = StrokePath();
|
|
32
|
+
switch (tone) {
|
|
33
|
+
case CCPetsMenuBarIconToneAttention:
|
|
34
|
+
for (NSInteger i = -1; i <= 1; i++) {
|
|
35
|
+
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(9 + i * 3.2 - 1.05, 8 - 1.05, 2.1, 2.1)] fill];
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
default:
|
|
39
|
+
[path moveToPoint:NSMakePoint(5.0, 10.5)];
|
|
40
|
+
[path lineToPoint:NSMakePoint(8.0, 8.0)];
|
|
41
|
+
[path lineToPoint:NSMakePoint(5.0, 5.5)];
|
|
42
|
+
[path moveToPoint:NSMakePoint(9.4, 5.7)];
|
|
43
|
+
[path lineToPoint:NSMakePoint(13.6, 5.7)];
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
[path stroke];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static void DrawTerminal(CCPetsMenuBarIconTone tone) {
|
|
50
|
+
// 窗口:坐标按描边中线给,四周留出半个线宽,描边不会被画布裁掉。
|
|
51
|
+
NSBezierPath *frame = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(1.8, 2.3, 14.4, 11.4)
|
|
52
|
+
xRadius:3 yRadius:3];
|
|
53
|
+
frame.lineWidth = IconLineWidth;
|
|
54
|
+
[frame stroke];
|
|
55
|
+
DrawGlyph(tone);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
NSImage *CCPetsMenuBarIconImage(CCPetsMenuBarIconTone tone) {
|
|
59
|
+
NSImage *image = [NSImage imageWithSize:CCPetsMenuBarIconSize flipped:NO drawingHandler:^BOOL(NSRect rect) {
|
|
60
|
+
NSColor *color = ToneColor(tone);
|
|
61
|
+
[color setStroke];
|
|
62
|
+
[color setFill];
|
|
63
|
+
DrawTerminal(tone);
|
|
64
|
+
return YES;
|
|
65
|
+
}];
|
|
66
|
+
// 待机交给系统着色;有状态时要保留彩色,template 会被重新染成黑白。
|
|
67
|
+
image.template = tone == CCPetsMenuBarIconToneNone;
|
|
68
|
+
image.accessibilityDescription = @"CC Pets";
|
|
69
|
+
return image;
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
@class CCPetsStatusItemController;
|
|
4
|
+
|
|
5
|
+
// 菜单栏图标左键弹出的玻璃面板:宠物与当前状态、在线会话、各账号额度、今日用量。
|
|
6
|
+
//
|
|
7
|
+
// 刻意只放「扫一眼」的信息:趋势、本机 Token 明细、系统指标留给宠物旁的悬停面板和主窗口。
|
|
8
|
+
// 材质、白字投影和额度配色与悬停面板一致,并跟随面板主题(经典 / Liquid Glass)。
|
|
9
|
+
// 面板不抢焦点(抢了会把前台终端的焦点夺走),因此不支持方向键;Esc 只在本 App 处于前台时有效,
|
|
10
|
+
// 点面板以外任何地方即收起,和 CCPetsGlassMenu 同一套做法。
|
|
11
|
+
@interface CCPetsMenuBarPanel : NSObject
|
|
12
|
+
- (instancetype)initWithOwner:(CCPetsStatusItemController *)owner;
|
|
13
|
+
@property(nonatomic, readonly, getter=isShown) BOOL shown;
|
|
14
|
+
- (void)showBelowButton:(NSStatusBarButton *)button;
|
|
15
|
+
// 数据变了:面板开着就就地重排,顶边不动。
|
|
16
|
+
- (void)reload;
|
|
17
|
+
- (void)dismiss;
|
|
18
|
+
@end
|