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
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
#import "CCPetsFormBuilder.h"
|
|
6
6
|
#import "CCPetsGlassView.h"
|
|
7
7
|
#import "CCPetsImageLoader.h"
|
|
8
|
+
#import "CCPetsIDEIntegration.h"
|
|
9
|
+
#import "CCPetsTerminalIntegration.h"
|
|
10
|
+
#import "CCPetsVSCodeIntegration.h"
|
|
8
11
|
#import "CCPetsL10n.h"
|
|
9
12
|
#import "CCPetsPaths.h"
|
|
10
13
|
#import "CCPetsPetSize.h"
|
|
@@ -14,6 +17,8 @@
|
|
|
14
17
|
#import "CCPetsUsageMode.h"
|
|
15
18
|
#import "CCPetsUIStyle.h"
|
|
16
19
|
#import <QuartzCore/QuartzCore.h>
|
|
20
|
+
#include <fcntl.h>
|
|
21
|
+
#include <unistd.h>
|
|
17
22
|
|
|
18
23
|
// 定义在 CCPetsAppDelegate+Speech.m;那边的头文件是 AppDelegate 私有的,这里单独 extern。
|
|
19
24
|
extern NSString *const PetSpeechFrequencyKey;
|
|
@@ -375,6 +380,13 @@ static void RevealFolder(NSString *path) {
|
|
|
375
380
|
@property(nonatomic) NSMutableDictionary<NSString *, CCPetsTileView *> *petTiles;
|
|
376
381
|
@property(nonatomic) NSMutableDictionary<NSString *, CCPetsSpriteView *> *petSprites;
|
|
377
382
|
@property(nonatomic) NSMutableDictionary<NSString *, NSImage *> *sheetCache;
|
|
383
|
+
// 自己素材文件夹里的宠物才有:卡片右上角的删除按钮和右键菜单项。当前这只不让删,和桌宠右键菜单一致。
|
|
384
|
+
@property(nonatomic) NSMutableDictionary<NSString *, NSButton *> *petDeleteButtons;
|
|
385
|
+
@property(nonatomic) NSMutableDictionary<NSString *, NSMenuItem *> *petDeleteItems;
|
|
386
|
+
// 列表现在画的是哪几只(按 id 次序)。外面增删了宠物,对不上就重排。
|
|
387
|
+
@property(nonatomic) NSArray<NSString *> *renderedPetIDs;
|
|
388
|
+
// 盯着自己的素材文件夹:桌宠右键菜单删除、`cc-pets pet add/remove`、Finder 里拖进拖出都会改它。
|
|
389
|
+
@property(nonatomic) dispatch_source_t petsWatcher;
|
|
378
390
|
@property(nonatomic) NSTextField *sampleLine;
|
|
379
391
|
@end
|
|
380
392
|
|
|
@@ -395,16 +407,70 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
395
407
|
self.petTiles = [NSMutableDictionary dictionary];
|
|
396
408
|
self.petSprites = [NSMutableDictionary dictionary];
|
|
397
409
|
self.sheetCache = [NSMutableDictionary dictionary];
|
|
410
|
+
self.petDeleteButtons = [NSMutableDictionary dictionary];
|
|
411
|
+
self.petDeleteItems = [NSMutableDictionary dictionary];
|
|
398
412
|
[super loadView];
|
|
399
413
|
// 切宠物不走 defaults 写入口(选中项记在桌宠自己身上),靠名片通知得知换了。
|
|
400
414
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(petDidChange:)
|
|
401
415
|
name:CCPetsPetCardDidChangeNotification object:nil];
|
|
416
|
+
// 文件夹一开始可能不存在(监视不上),回到窗口时再对一次,兜住这种情况。
|
|
417
|
+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidBecomeKey:)
|
|
418
|
+
name:NSWindowDidBecomeKeyNotification object:nil];
|
|
419
|
+
[self startWatchingPetsDirectory];
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
- (void)dealloc {
|
|
423
|
+
[self stopWatchingPetsDirectory];
|
|
402
424
|
}
|
|
403
425
|
|
|
404
426
|
- (void)petDidChange:(NSNotification *)notification {
|
|
427
|
+
// 删掉当前那只时 AppDelegate 会换到下一只并发这条通知,此时列表也少了一只。
|
|
428
|
+
[self reloadPickerIfChanged];
|
|
405
429
|
[self updatePetSelection];
|
|
406
430
|
}
|
|
407
431
|
|
|
432
|
+
- (void)windowDidBecomeKey:(NSNotification *)notification {
|
|
433
|
+
if (notification.object != self.view.window) return;
|
|
434
|
+
if (!self.petsWatcher) [self startWatchingPetsDirectory];
|
|
435
|
+
[self reloadPickerIfChanged];
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
- (void)startWatchingPetsDirectory {
|
|
439
|
+
[self stopWatchingPetsDirectory];
|
|
440
|
+
int descriptor = open(OwnPetsDirectory().fileSystemRepresentation, O_EVTONLY);
|
|
441
|
+
if (descriptor < 0) return;
|
|
442
|
+
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, (uintptr_t)descriptor,
|
|
443
|
+
DISPATCH_VNODE_WRITE | DISPATCH_VNODE_DELETE | DISPATCH_VNODE_RENAME, dispatch_get_main_queue());
|
|
444
|
+
__weak typeof(self) weakSelf = self;
|
|
445
|
+
dispatch_source_set_event_handler(source, ^{
|
|
446
|
+
typeof(self) page = weakSelf;
|
|
447
|
+
if (!page) return;
|
|
448
|
+
// 文件夹本身被删或改名,旧描述符就废了,重新打开。
|
|
449
|
+
if (dispatch_source_get_data(source) & (DISPATCH_VNODE_DELETE | DISPATCH_VNODE_RENAME)) {
|
|
450
|
+
[page startWatchingPetsDirectory];
|
|
451
|
+
}
|
|
452
|
+
// `pet add` 会连着改好几次(临时目录、改名),合并成一次重排。
|
|
453
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:page selector:@selector(reloadPickerIfChanged) object:nil];
|
|
454
|
+
[page performSelector:@selector(reloadPickerIfChanged) withObject:nil afterDelay:0.3];
|
|
455
|
+
});
|
|
456
|
+
dispatch_source_set_cancel_handler(source, ^{ close(descriptor); });
|
|
457
|
+
self.petsWatcher = source;
|
|
458
|
+
dispatch_resume(source);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
- (void)stopWatchingPetsDirectory {
|
|
462
|
+
if (!self.petsWatcher) return;
|
|
463
|
+
dispatch_source_cancel(self.petsWatcher);
|
|
464
|
+
self.petsWatcher = nil;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
- (void)reloadPickerIfChanged {
|
|
468
|
+
NSMutableArray<NSString *> *ids = [NSMutableArray array];
|
|
469
|
+
for (NSDictionary *option in [self.actions petPickerOptions] ?: @[]) [ids addObject:option[@"id"]];
|
|
470
|
+
if (self.renderedPetIDs && [ids isEqualToArray:self.renderedPetIDs]) return;
|
|
471
|
+
[self rebuildPicker];
|
|
472
|
+
}
|
|
473
|
+
|
|
408
474
|
- (void)buildContent {
|
|
409
475
|
__weak typeof(self) weakSelf = self;
|
|
410
476
|
|
|
@@ -499,7 +565,10 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
499
565
|
}
|
|
500
566
|
[self.petTiles removeAllObjects];
|
|
501
567
|
[self.petSprites removeAllObjects];
|
|
568
|
+
[self.petDeleteButtons removeAllObjects];
|
|
569
|
+
[self.petDeleteItems removeAllObjects];
|
|
502
570
|
NSArray<NSDictionary *> *options = [self.actions petPickerOptions] ?: @[];
|
|
571
|
+
self.renderedPetIDs = [options valueForKey:@"id"];
|
|
503
572
|
NSMutableArray<NSView *> *tiles = [NSMutableArray array];
|
|
504
573
|
__weak typeof(self) weakSelf = self;
|
|
505
574
|
for (NSDictionary *option in options) {
|
|
@@ -511,6 +580,7 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
511
580
|
tile.toolTip = option[@"name"];
|
|
512
581
|
self.petTiles[petID] = tile;
|
|
513
582
|
self.petSprites[petID] = sprite;
|
|
583
|
+
if (![option[@"builtin"] boolValue]) [self attachDeleteControlsToTile:tile option:option];
|
|
514
584
|
[tiles addObject:tile];
|
|
515
585
|
[self loadSheetForOption:option intoSprite:sprite];
|
|
516
586
|
}
|
|
@@ -538,6 +608,62 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
538
608
|
[self updatePetSelection];
|
|
539
609
|
}
|
|
540
610
|
|
|
611
|
+
- (void)attachDeleteControlsToTile:(CCPetsTileView *)tile option:(NSDictionary *)option {
|
|
612
|
+
NSString *petID = option[@"id"];
|
|
613
|
+
NSString *name = option[@"name"];
|
|
614
|
+
__weak typeof(self) weakSelf = self;
|
|
615
|
+
void (^confirm)(void) = ^{ [weakSelf confirmDeletePetWithID:petID name:name]; };
|
|
616
|
+
|
|
617
|
+
NSButton *trash = [NSButton buttonWithImage:[NSImage imageWithSystemSymbolName:@"trash"
|
|
618
|
+
accessibilityDescription:L(@"Delete pet")] target:nil action:nil];
|
|
619
|
+
trash.bordered = NO;
|
|
620
|
+
trash.contentTintColor = CCPetsSecondaryInkColor();
|
|
621
|
+
trash.toolTip = L(@"Delete pet");
|
|
622
|
+
[self bind:trash to:^(id sender) { confirm(); }];
|
|
623
|
+
trash.translatesAutoresizingMaskIntoConstraints = NO;
|
|
624
|
+
[tile addSubview:trash];
|
|
625
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
626
|
+
[trash.topAnchor constraintEqualToAnchor:tile.topAnchor constant:6],
|
|
627
|
+
[trash.trailingAnchor constraintEqualToAnchor:tile.trailingAnchor constant:-6],
|
|
628
|
+
[trash.widthAnchor constraintEqualToConstant:20],
|
|
629
|
+
[trash.heightAnchor constraintEqualToConstant:20],
|
|
630
|
+
]];
|
|
631
|
+
tile.hoverAccessoryView = trash;
|
|
632
|
+
|
|
633
|
+
// 右键菜单:键盘 / 旁白用户摸不到悬停按钮,也给他们一条路。
|
|
634
|
+
CCPetsSettingsHandler *handler = [CCPetsSettingsHandler new];
|
|
635
|
+
handler.block = ^(id sender) { confirm(); };
|
|
636
|
+
[self.handlers addObject:handler];
|
|
637
|
+
NSMenu *menu = [NSMenu new];
|
|
638
|
+
menu.autoenablesItems = NO;
|
|
639
|
+
NSMenuItem *item = [menu addItemWithTitle:L(@"Delete pet") action:@selector(invoke:) keyEquivalent:@""];
|
|
640
|
+
item.target = handler;
|
|
641
|
+
tile.menu = menu;
|
|
642
|
+
|
|
643
|
+
self.petDeleteButtons[petID] = trash;
|
|
644
|
+
self.petDeleteItems[petID] = item;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
- (void)confirmDeletePetWithID:(NSString *)petID name:(NSString *)name {
|
|
648
|
+
if ([petID isEqualToString:[self.actions currentPetID]]) return;
|
|
649
|
+
NSAlert *alert = [NSAlert new];
|
|
650
|
+
alert.alertStyle = NSAlertStyleWarning;
|
|
651
|
+
alert.messageText = [NSString stringWithFormat:L(@"Delete “%@”?"), name ?: @""];
|
|
652
|
+
alert.informativeText = L(@"This can't be undone. Continue?");
|
|
653
|
+
NSButton *deleteButton = [alert addButtonWithTitle:L(@"Delete")];
|
|
654
|
+
deleteButton.hasDestructiveAction = YES;
|
|
655
|
+
[alert addButtonWithTitle:L(@"Cancel")];
|
|
656
|
+
__weak typeof(self) weakSelf = self;
|
|
657
|
+
void (^finish)(NSModalResponse) = ^(NSModalResponse response) {
|
|
658
|
+
if (response != NSAlertFirstButtonReturn) return;
|
|
659
|
+
// 删除失败时 AppDelegate 自己会弹错误,这里只管成功后重排列表。
|
|
660
|
+
if ([weakSelf.actions deletePetWithID:petID]) [weakSelf rebuildPicker];
|
|
661
|
+
};
|
|
662
|
+
NSWindow *window = self.view.window;
|
|
663
|
+
if (window) [alert beginSheetModalForWindow:window completionHandler:finish];
|
|
664
|
+
else finish([alert runModal]);
|
|
665
|
+
}
|
|
666
|
+
|
|
541
667
|
- (CCPetsTileView *)tileWithTop:(NSView *)top title:(NSString *)title subtitle:(NSString *)subtitle {
|
|
542
668
|
CCPetsTileView *tile = [CCPetsTileView new];
|
|
543
669
|
NSTextField *name = CCPetsLabel(title, 12, NSFontWeightSemibold, CCPetsInkColor());
|
|
@@ -596,6 +722,12 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
596
722
|
tile.selected = selected;
|
|
597
723
|
// 只让选中的那只动,其余停在第一帧。
|
|
598
724
|
self.petSprites[petID].playing = selected;
|
|
725
|
+
NSButton *trash = self.petDeleteButtons[petID];
|
|
726
|
+
if (trash) {
|
|
727
|
+
trash.hidden = YES;
|
|
728
|
+
tile.hoverAccessoryView = selected ? nil : trash;
|
|
729
|
+
self.petDeleteItems[petID].enabled = !selected;
|
|
730
|
+
}
|
|
599
731
|
}];
|
|
600
732
|
}
|
|
601
733
|
|
|
@@ -640,10 +772,17 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
640
772
|
#pragma mark - 通用
|
|
641
773
|
|
|
642
774
|
@interface CCPetsGeneralPage ()
|
|
643
|
-
@property(nonatomic)
|
|
775
|
+
@property(nonatomic) CCPetsGlassView *glassPreview;
|
|
644
776
|
@property(nonatomic, copy) NSArray<NSDictionary *> *usageProfiles;
|
|
777
|
+
// 终端跳转只用一张卡片,行随检测结果重建;未运行 / 不支持的折叠到末尾一行。
|
|
778
|
+
@property(nonatomic) NSView *terminalJumpCard;
|
|
779
|
+
@property(nonatomic) BOOL terminalJumpShowAll;
|
|
780
|
+
@property(nonatomic, copy) NSArray *terminalJumpSnapshot;
|
|
781
|
+
@property(nonatomic) NSTimer *ideStatusTimer;
|
|
782
|
+
@property(nonatomic) BOOL ideStatusRefreshing;
|
|
645
783
|
@end
|
|
646
784
|
|
|
785
|
+
// 汇总预览外的玻璃:被拉宽时圆角跟着内容一起等比放大,和真实面板的比例一致。
|
|
647
786
|
@implementation CCPetsGeneralPage
|
|
648
787
|
|
|
649
788
|
- (void)loadView {
|
|
@@ -655,6 +794,299 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
655
794
|
- (void)viewWillAppear {
|
|
656
795
|
[super viewWillAppear];
|
|
657
796
|
[self reloadValues];
|
|
797
|
+
[self refreshIDEIntegration];
|
|
798
|
+
[self.ideStatusTimer invalidate];
|
|
799
|
+
__weak typeof(self) weakSelf = self;
|
|
800
|
+
self.ideStatusTimer = [NSTimer scheduledTimerWithTimeInterval:5 repeats:YES block:^(NSTimer *timer) {
|
|
801
|
+
[weakSelf refreshIDEIntegration];
|
|
802
|
+
}];
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
- (void)viewDidDisappear {
|
|
806
|
+
[super viewDidDisappear];
|
|
807
|
+
[self.ideStatusTimer invalidate];
|
|
808
|
+
self.ideStatusTimer = nil;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
- (void)refreshIDEIntegration {
|
|
812
|
+
if (self.ideStatusRefreshing) return;
|
|
813
|
+
self.ideStatusRefreshing = YES;
|
|
814
|
+
__weak typeof(self) weakSelf = self;
|
|
815
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
|
|
816
|
+
NSArray *snapshot = @[CCPetsTerminalIntegrationSnapshot(), CCPetsIDEIntegrationSnapshot(),
|
|
817
|
+
CCPetsVSCodeIntegrationSnapshot()];
|
|
818
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
819
|
+
CCPetsGeneralPage *page = weakSelf;
|
|
820
|
+
if (!page) return;
|
|
821
|
+
page.ideStatusRefreshing = NO;
|
|
822
|
+
// 每 5 秒刷新一次,状态没变就不重建,免得行闪烁、按钮丢焦点。
|
|
823
|
+
if ([snapshot isEqual:page.terminalJumpSnapshot]) return;
|
|
824
|
+
page.terminalJumpSnapshot = snapshot;
|
|
825
|
+
[page applyTerminalJumpSnapshot:snapshot];
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// 右侧的状态小标:可选的彩色圆点 + 灰字。
|
|
831
|
+
- (NSTextField *)terminalJumpBadge:(NSString *)text dotColor:(NSColor *)color {
|
|
832
|
+
NSMutableAttributedString *value = [NSMutableAttributedString new];
|
|
833
|
+
NSFont *font = [NSFont systemFontOfSize:NSFont.smallSystemFontSize];
|
|
834
|
+
if (color) {
|
|
835
|
+
[value appendAttributedString:[[NSAttributedString alloc] initWithString:@"● "
|
|
836
|
+
attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: color}]];
|
|
837
|
+
}
|
|
838
|
+
[value appendAttributedString:[[NSAttributedString alloc] initWithString:text
|
|
839
|
+
attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: CCPetsSecondaryInkColor()}]];
|
|
840
|
+
NSTextField *label = [NSTextField labelWithAttributedString:value];
|
|
841
|
+
[label setContentCompressionResistancePriority:NSLayoutPriorityRequired
|
|
842
|
+
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
843
|
+
return label;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
- (NSView *)scriptTerminalRow:(NSDictionary *)terminal {
|
|
847
|
+
__weak typeof(self) weakSelf = self;
|
|
848
|
+
NSString *state = terminal[@"state"];
|
|
849
|
+
NSString *bundleID = terminal[@"bundleID"];
|
|
850
|
+
BOOL ghostty = [terminal[@"group"] isEqualToString:@"ghostty"];
|
|
851
|
+
NSString *title = [bundleID isEqualToString:@"com.apple.Terminal"] ? L(@"macOS Terminal") : terminal[@"name"];
|
|
852
|
+
if (ghostty && [terminal[@"version"] length]) title = [NSString stringWithFormat:@"%@ %@", title, terminal[@"version"]];
|
|
853
|
+
NSString *granted = ghostty ? L(@"Selects the tab and split by TTY")
|
|
854
|
+
: ([bundleID isEqualToString:@"com.googlecode.iterm2"] ? L(@"Selects the session by TTY") : L(@"Selects the tab by TTY"));
|
|
855
|
+
NSString *subtitle;
|
|
856
|
+
NSArray<NSView *> *controls;
|
|
857
|
+
if ([state isEqualToString:@"granted"]) {
|
|
858
|
+
subtitle = granted;
|
|
859
|
+
controls = @[[self terminalJumpBadge:L(@"Allowed") dotColor:NSColor.systemGreenColor]];
|
|
860
|
+
} else if ([state isEqualToString:@"denied"]) {
|
|
861
|
+
subtitle = L(@"Automation denied — the jump only brings the app forward");
|
|
862
|
+
controls = @[[self smallButtonWithTitle:L(@"Open System Settings…") action:^{ CCPetsOpenAutomationSettings(); }]];
|
|
863
|
+
} else if ([state isEqualToString:@"notDetermined"]) {
|
|
864
|
+
subtitle = L(@"macOS asks for permission on the first jump");
|
|
865
|
+
controls = @[[self smallButtonWithTitle:L(@"Allow…") action:^{
|
|
866
|
+
CCPetsRequestTerminalAutomation(bundleID, ^{ [weakSelf refreshIDEIntegration]; });
|
|
867
|
+
}]];
|
|
868
|
+
} else if ([state isEqualToString:@"unsupported"]) {
|
|
869
|
+
subtitle = L(@"Requires Ghostty 1.4 or later for exact jumps");
|
|
870
|
+
controls = @[[self terminalJumpBadge:L(@"Needs 1.4+") dotColor:nil]];
|
|
871
|
+
} else {
|
|
872
|
+
subtitle = L(@"Open the app to check automation permission");
|
|
873
|
+
controls = @[[self terminalJumpBadge:L(@"Not running") dotColor:nil]];
|
|
874
|
+
}
|
|
875
|
+
return [CCPetsFormBuilder rowWithTitle:title subtitle:subtitle controls:controls];
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
- (NSView *)jetBrainsRow:(NSDictionary *)ide {
|
|
879
|
+
__weak typeof(self) weakSelf = self;
|
|
880
|
+
NSString *state = ide[@"state"];
|
|
881
|
+
NSString *title = ide[@"name"];
|
|
882
|
+
NSString *version = ide[@"version"];
|
|
883
|
+
if (version.length && ![title containsString:version]) title = [NSString stringWithFormat:@"%@ %@", title, version];
|
|
884
|
+
BOOL automatic = [ide[@"autoInstall"] boolValue];
|
|
885
|
+
void (^install)(void) = ^{
|
|
886
|
+
CCPetsPromptInstallIDEPlugin(ide, ^{
|
|
887
|
+
weakSelf.terminalJumpSnapshot = nil;
|
|
888
|
+
[weakSelf refreshIDEIntegration];
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
NSString *subtitle;
|
|
892
|
+
NSArray<NSView *> *controls;
|
|
893
|
+
if ([state isEqualToString:@"connected"]) {
|
|
894
|
+
subtitle = L(@"Selects the terminal tab through the plugin");
|
|
895
|
+
controls = @[[self terminalJumpBadge:L(@"Connected") dotColor:NSColor.systemGreenColor]];
|
|
896
|
+
} else if ([state isEqualToString:@"installed"]) {
|
|
897
|
+
subtitle = L(@"Installed — open a project or restart the IDE to connect");
|
|
898
|
+
controls = @[[self terminalJumpBadge:L(@"Waiting to connect") dotColor:NSColor.systemOrangeColor]];
|
|
899
|
+
} else if ([state isEqualToString:@"pendingRestart"]) {
|
|
900
|
+
subtitle = [NSString stringWithFormat:L(@"Plugin %@ is in place — restart the IDE to load it"), ide[@"pluginVersion"] ?: @""];
|
|
901
|
+
controls = @[[self terminalJumpBadge:L(@"Restart needed") dotColor:NSColor.systemOrangeColor]];
|
|
902
|
+
} else if ([state isEqualToString:@"outdated"]) {
|
|
903
|
+
subtitle = [NSString stringWithFormat:L(@"Plugin %@ installed — %@ available"),
|
|
904
|
+
ide[@"pluginVersion"] ?: @"?", ide[@"bundledVersion"] ?: @"?"];
|
|
905
|
+
controls = @[[self smallButtonWithTitle:automatic ? L(@"Update") : L(@"Update…") action:install]];
|
|
906
|
+
} else if ([state isEqualToString:@"disabled"]) {
|
|
907
|
+
subtitle = L(@"Plugin disabled — enable it in the IDE's Plugins settings");
|
|
908
|
+
controls = @[[self terminalJumpBadge:L(@"Plugin disabled") dotColor:nil]];
|
|
909
|
+
} else if ([state isEqualToString:@"unsupported"]) {
|
|
910
|
+
subtitle = L(@"Requires version 2026.2 or 2026.3");
|
|
911
|
+
controls = @[[self terminalJumpBadge:L(@"Unsupported") dotColor:nil]];
|
|
912
|
+
} else {
|
|
913
|
+
subtitle = automatic ? L(@"Plugin not detected") : L(@"Plugin not detected — custom plugin folder, install manually");
|
|
914
|
+
controls = @[[self smallButtonWithTitle:automatic ? L(@"Install") : L(@"Install Plugin…") action:install]];
|
|
915
|
+
}
|
|
916
|
+
return [CCPetsFormBuilder rowWithTitle:title subtitle:subtitle controls:controls];
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
- (NSView *)vscodeRow:(NSDictionary *)app {
|
|
920
|
+
__weak typeof(self) weakSelf = self;
|
|
921
|
+
NSString *state = app[@"state"];
|
|
922
|
+
NSString *title = app[@"name"];
|
|
923
|
+
NSString *version = app[@"version"];
|
|
924
|
+
if (version.length && ![title containsString:version]) title = [NSString stringWithFormat:@"%@ %@", title, version];
|
|
925
|
+
BOOL automatic = [app[@"autoInstall"] boolValue];
|
|
926
|
+
void (^install)(void) = ^{
|
|
927
|
+
CCPetsPromptInstallVSCodeExtension(app, ^{
|
|
928
|
+
weakSelf.terminalJumpSnapshot = nil;
|
|
929
|
+
[weakSelf refreshIDEIntegration];
|
|
930
|
+
});
|
|
931
|
+
};
|
|
932
|
+
NSString *subtitle;
|
|
933
|
+
NSArray<NSView *> *controls;
|
|
934
|
+
if ([state isEqualToString:@"connected"]) {
|
|
935
|
+
subtitle = L(@"Selects the terminal through the extension");
|
|
936
|
+
controls = @[[self terminalJumpBadge:L(@"Connected") dotColor:NSColor.systemGreenColor]];
|
|
937
|
+
} else if ([state isEqualToString:@"installed"]) {
|
|
938
|
+
subtitle = [app[@"running"] boolValue] ? L(@"Installed — reload a window to connect")
|
|
939
|
+
: L(@"Installed — connects when the app starts");
|
|
940
|
+
controls = @[[self terminalJumpBadge:L(@"Waiting to connect") dotColor:NSColor.systemOrangeColor]];
|
|
941
|
+
} else if ([state isEqualToString:@"pendingRestart"]) {
|
|
942
|
+
subtitle = [NSString stringWithFormat:L(@"Extension %@ is in place — reload open windows to load it"), app[@"pluginVersion"] ?: @""];
|
|
943
|
+
controls = @[[self terminalJumpBadge:L(@"Reload needed") dotColor:NSColor.systemOrangeColor]];
|
|
944
|
+
} else if ([state isEqualToString:@"outdated"]) {
|
|
945
|
+
subtitle = [NSString stringWithFormat:L(@"Extension %@ installed — %@ available"),
|
|
946
|
+
app[@"pluginVersion"] ?: @"?", app[@"bundledVersion"] ?: @"?"];
|
|
947
|
+
controls = @[[self smallButtonWithTitle:automatic ? L(@"Update") : L(@"Update…") action:install]];
|
|
948
|
+
} else if ([state isEqualToString:@"disabled"]) {
|
|
949
|
+
subtitle = L(@"Extension disabled — enable it in the Extensions view");
|
|
950
|
+
controls = @[[self terminalJumpBadge:L(@"Plugin disabled") dotColor:nil]];
|
|
951
|
+
} else if ([state isEqualToString:@"unsupported"]) {
|
|
952
|
+
subtitle = L(@"Requires VS Code 1.80 or later");
|
|
953
|
+
controls = @[[self terminalJumpBadge:L(@"Unsupported") dotColor:nil]];
|
|
954
|
+
} else {
|
|
955
|
+
subtitle = automatic ? L(@"Extension not detected") : L(@"Extension not detected — no command line tool, install manually");
|
|
956
|
+
controls = @[[self smallButtonWithTitle:automatic ? L(@"Install") : L(@"Install Extension…") action:install]];
|
|
957
|
+
}
|
|
958
|
+
return [CCPetsFormBuilder rowWithTitle:title subtitle:subtitle controls:controls];
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// 排序档位:0 正在工作,1 需要用户处理,2 可安装,3 未运行 / 不支持(默认折叠)。
|
|
962
|
+
static NSInteger TerminalJumpRank(NSDictionary *item) {
|
|
963
|
+
NSString *state = item[@"state"];
|
|
964
|
+
if ([state isEqualToString:@"connected"] || [state isEqualToString:@"granted"]) return 0;
|
|
965
|
+
if ([@[@"pendingRestart", @"installed", @"outdated", @"denied", @"notDetermined", @"disabled"] containsObject:state]) return 1;
|
|
966
|
+
// 插件缺失:应用开着时提示安装,没开就折叠。
|
|
967
|
+
if ([state isEqualToString:@"missing"]) return [item[@"running"] boolValue] ? 2 : 3;
|
|
968
|
+
return 3;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// 产品名之外的部分作为版本标签,例如 "IntelliJ IDEA 2026.3 EAP" → "2026.3 EAP"。
|
|
972
|
+
static NSString *TerminalJumpVersionLabel(NSDictionary *item, NSString *product) {
|
|
973
|
+
NSString *name = item[@"name"];
|
|
974
|
+
if (product.length && [name hasPrefix:product]) {
|
|
975
|
+
NSString *rest = [[name substringFromIndex:product.length]
|
|
976
|
+
stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
|
|
977
|
+
if (rest.length) return rest;
|
|
978
|
+
}
|
|
979
|
+
return [item[@"version"] length] ? item[@"version"] : name;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// 合并行里单个版本的简短状态。
|
|
983
|
+
static NSString *TerminalJumpShortState(NSDictionary *item, BOOL vscode) {
|
|
984
|
+
NSString *state = item[@"state"];
|
|
985
|
+
if ([state isEqualToString:@"connected"]) return L(@"Connected");
|
|
986
|
+
if ([state isEqualToString:@"installed"]) return L(@"Waiting to connect");
|
|
987
|
+
if ([state isEqualToString:@"pendingRestart"]) return vscode ? L(@"Reload needed") : L(@"Restart needed");
|
|
988
|
+
if ([state isEqualToString:@"outdated"]) return L(@"Update available");
|
|
989
|
+
if ([state isEqualToString:@"disabled"]) return L(@"Plugin disabled");
|
|
990
|
+
if ([state isEqualToString:@"unsupported"]) return L(@"Unsupported");
|
|
991
|
+
return L(@"Plugin not detected");
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// 同一 JetBrains 产品的多个版本合成一行:副标题逐个列出版本状态,只给需要操作的版本放按钮。
|
|
995
|
+
- (NSView *)mergedIDERow:(NSArray<NSDictionary *> *)items product:(NSString *)product {
|
|
996
|
+
__weak typeof(self) weakSelf = self;
|
|
997
|
+
NSMutableArray<NSString *> *parts = [NSMutableArray array];
|
|
998
|
+
NSMutableArray<NSView *> *buttons = [NSMutableArray array];
|
|
999
|
+
for (NSDictionary *ide in items) {
|
|
1000
|
+
NSString *label = TerminalJumpVersionLabel(ide, product);
|
|
1001
|
+
[parts addObject:[NSString stringWithFormat:@"%@ %@", label, TerminalJumpShortState(ide, NO)]];
|
|
1002
|
+
NSString *state = ide[@"state"];
|
|
1003
|
+
BOOL outdated = [state isEqualToString:@"outdated"];
|
|
1004
|
+
if (!outdated && !([state isEqualToString:@"missing"] && [ide[@"running"] boolValue])) continue;
|
|
1005
|
+
BOOL automatic = [ide[@"autoInstall"] boolValue];
|
|
1006
|
+
NSString *base = outdated ? L(@"Update") : L(@"Install");
|
|
1007
|
+
NSString *title = [NSString stringWithFormat:@"%@ %@%@", base, label, automatic ? @"" : @"…"];
|
|
1008
|
+
[buttons addObject:[self smallButtonWithTitle:title action:^{
|
|
1009
|
+
CCPetsPromptInstallIDEPlugin(ide, ^{
|
|
1010
|
+
weakSelf.terminalJumpSnapshot = nil;
|
|
1011
|
+
[weakSelf refreshIDEIntegration];
|
|
1012
|
+
});
|
|
1013
|
+
}]];
|
|
1014
|
+
}
|
|
1015
|
+
NSArray<NSView *> *controls = buttons;
|
|
1016
|
+
if (buttons.count == 0) {
|
|
1017
|
+
// 没有可操作项时显示最好的那个状态(items 已按档位排好)。
|
|
1018
|
+
NSInteger rank = TerminalJumpRank(items.firstObject);
|
|
1019
|
+
NSColor *dot = rank == 0 ? NSColor.systemGreenColor : (rank == 1 &&
|
|
1020
|
+
![items.firstObject[@"state"] isEqualToString:@"disabled"] ? NSColor.systemOrangeColor : nil);
|
|
1021
|
+
controls = @[[self terminalJumpBadge:TerminalJumpShortState(items.firstObject, NO) dotColor:dot]];
|
|
1022
|
+
}
|
|
1023
|
+
return [CCPetsFormBuilder rowWithTitle:product subtitle:[parts componentsJoinedByString:@" · "] controls:controls];
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
- (void)applyTerminalJumpSnapshot:(NSArray *)snapshot {
|
|
1027
|
+
// 每个条目 = 卡片里的一行:{rank, title, build}。JetBrains 同产品多版本先合并。
|
|
1028
|
+
NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];
|
|
1029
|
+
__weak typeof(self) weakSelf = self;
|
|
1030
|
+
for (NSDictionary *terminal in snapshot[0]) {
|
|
1031
|
+
NSString *name = [terminal[@"bundleID"] isEqualToString:@"com.apple.Terminal"] ? L(@"macOS Terminal") : terminal[@"name"];
|
|
1032
|
+
[entries addObject:@{@"rank": @(TerminalJumpRank(terminal)), @"title": name ?: @"",
|
|
1033
|
+
@"build": ^NSView *{ return [weakSelf scriptTerminalRow:terminal]; }}];
|
|
1034
|
+
}
|
|
1035
|
+
NSMutableDictionary<NSString *, NSMutableArray *> *products = [NSMutableDictionary dictionary];
|
|
1036
|
+
NSMutableArray<NSString *> *productOrder = [NSMutableArray array];
|
|
1037
|
+
for (NSDictionary *ide in snapshot[1]) {
|
|
1038
|
+
NSString *key = [ide[@"productName"] length] ? ide[@"productName"] : ide[@"name"];
|
|
1039
|
+
if (!products[key]) { products[key] = [NSMutableArray array]; [productOrder addObject:key]; }
|
|
1040
|
+
[products[key] addObject:ide];
|
|
1041
|
+
}
|
|
1042
|
+
NSComparator byRank = ^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
|
|
1043
|
+
return [@(TerminalJumpRank(a)) compare:@(TerminalJumpRank(b))];
|
|
1044
|
+
};
|
|
1045
|
+
for (NSString *product in productOrder) {
|
|
1046
|
+
NSArray *items = [products[product] sortedArrayWithOptions:NSSortStable usingComparator:byRank];
|
|
1047
|
+
NSDictionary *only = items.count == 1 ? items.firstObject : nil;
|
|
1048
|
+
[entries addObject:@{@"rank": @(TerminalJumpRank(items.firstObject)), @"title": product,
|
|
1049
|
+
@"build": only ? ^NSView *{ return [weakSelf jetBrainsRow:only]; }
|
|
1050
|
+
: ^NSView *{ return [weakSelf mergedIDERow:items product:product]; }}];
|
|
1051
|
+
}
|
|
1052
|
+
for (NSDictionary *app in snapshot[2]) {
|
|
1053
|
+
[entries addObject:@{@"rank": @(TerminalJumpRank(app)), @"title": app[@"name"] ?: @"",
|
|
1054
|
+
@"build": ^NSView *{ return [weakSelf vscodeRow:app]; }}];
|
|
1055
|
+
}
|
|
1056
|
+
NSArray *sorted = [entries sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
|
|
1057
|
+
return [a[@"rank"] compare:b[@"rank"]];
|
|
1058
|
+
}];
|
|
1059
|
+
|
|
1060
|
+
// 默认只显示需要关注的行,最多 5 行;其余收进末尾的“显示全部”。
|
|
1061
|
+
static const NSUInteger visibleLimit = 5;
|
|
1062
|
+
NSMutableArray<NSDictionary *> *prominent = [NSMutableArray array];
|
|
1063
|
+
NSMutableArray<NSDictionary *> *folded = [NSMutableArray array];
|
|
1064
|
+
for (NSDictionary *entry in sorted) {
|
|
1065
|
+
BOOL keep = [entry[@"rank"] integerValue] < 3 && prominent.count < visibleLimit;
|
|
1066
|
+
[(keep ? prominent : folded) addObject:entry];
|
|
1067
|
+
}
|
|
1068
|
+
NSMutableArray<NSView *> *rows = [NSMutableArray array];
|
|
1069
|
+
for (NSDictionary *entry in self.terminalJumpShowAll ? sorted : prominent) {
|
|
1070
|
+
[rows addObject:((NSView *(^)(void))entry[@"build"])()];
|
|
1071
|
+
}
|
|
1072
|
+
if (folded.count && !self.terminalJumpShowAll) {
|
|
1073
|
+
NSArray *names = [folded valueForKey:@"title"];
|
|
1074
|
+
NSString *title = [NSString stringWithFormat:L(@"%lu hidden"), (unsigned long)folded.count];
|
|
1075
|
+
[rows addObject:[CCPetsFormBuilder rowWithTitle:title subtitle:[names componentsJoinedByString:L(@", ")]
|
|
1076
|
+
controls:@[[self smallButtonWithTitle:L(@"Show All") action:^{
|
|
1077
|
+
weakSelf.terminalJumpShowAll = YES;
|
|
1078
|
+
if (weakSelf.terminalJumpSnapshot) [weakSelf applyTerminalJumpSnapshot:weakSelf.terminalJumpSnapshot];
|
|
1079
|
+
}]]]];
|
|
1080
|
+
} else if (folded.count) {
|
|
1081
|
+
[rows addObject:[CCPetsFormBuilder rowWithTitle:@"" controls:@[[self smallButtonWithTitle:L(@"Show Less") action:^{
|
|
1082
|
+
weakSelf.terminalJumpShowAll = NO;
|
|
1083
|
+
if (weakSelf.terminalJumpSnapshot) [weakSelf applyTerminalJumpSnapshot:weakSelf.terminalJumpSnapshot];
|
|
1084
|
+
}]]]];
|
|
1085
|
+
}
|
|
1086
|
+
if (rows.count == 0) {
|
|
1087
|
+
[rows addObject:[CCPetsFormBuilder rowWithTitle:L(@"No supported terminal detected") controls:@[]]];
|
|
1088
|
+
}
|
|
1089
|
+
[CCPetsFormBuilder replaceRowsInCard:self.terminalJumpCard withRows:rows];
|
|
658
1090
|
}
|
|
659
1091
|
|
|
660
1092
|
- (NSArray<NSDictionary *> *)currentUsageProfiles {
|
|
@@ -682,10 +1114,9 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
682
1114
|
}
|
|
683
1115
|
|
|
684
1116
|
- (NSString *)pageSubtitle {
|
|
685
|
-
return
|
|
1117
|
+
return @"";
|
|
686
1118
|
}
|
|
687
1119
|
|
|
688
|
-
// 主题卡片上方的小预览:三条横线代表面板里的文字行。
|
|
689
1120
|
- (NSView *)themePreviewLiquid:(BOOL)liquid {
|
|
690
1121
|
NSView *preview = [NSView new];
|
|
691
1122
|
preview.wantsLayer = YES;
|
|
@@ -703,6 +1134,27 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
703
1134
|
} else {
|
|
704
1135
|
preview.layer.backgroundColor = [NSColor colorWithSRGBRed:0.12 green:0.14 blue:0.16 alpha:1].CGColor;
|
|
705
1136
|
}
|
|
1137
|
+
// Liquid Glass:玻璃铺满预览区,线条放在玻璃上;压暗调的是玻璃背后的压暗层,和桌宠浮层一致。
|
|
1138
|
+
NSView *container = preview;
|
|
1139
|
+
if (liquid) {
|
|
1140
|
+
CCPetsGlassView *glass = [[CCPetsGlassView alloc] initWithFrame:NSMakeRect(0, 0, 200, 62)
|
|
1141
|
+
material:NSVisualEffectMaterialUnderWindowBackground appearance:NSAppearanceNameDarkAqua cornerRadius:6];
|
|
1142
|
+
// 预览很矮,上下暗带调小;必须在 usesWidgetGlass 之前设。
|
|
1143
|
+
glass.edgeShadeHeight = 6;
|
|
1144
|
+
glass.edgeShadeAlpha = 0.45;
|
|
1145
|
+
glass.forcesLiquidGlass = YES;
|
|
1146
|
+
glass.usesWidgetGlass = YES;
|
|
1147
|
+
glass.translatesAutoresizingMaskIntoConstraints = NO;
|
|
1148
|
+
[preview addSubview:glass];
|
|
1149
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
1150
|
+
[glass.leadingAnchor constraintEqualToAnchor:preview.leadingAnchor],
|
|
1151
|
+
[glass.trailingAnchor constraintEqualToAnchor:preview.trailingAnchor],
|
|
1152
|
+
[glass.topAnchor constraintEqualToAnchor:preview.topAnchor],
|
|
1153
|
+
[glass.bottomAnchor constraintEqualToAnchor:preview.bottomAnchor],
|
|
1154
|
+
]];
|
|
1155
|
+
self.glassPreview = glass;
|
|
1156
|
+
container = glass.contentView;
|
|
1157
|
+
}
|
|
706
1158
|
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
1159
|
NSView *previous = nil;
|
|
708
1160
|
for (NSUInteger index = 0; index < bars.count; index++) {
|
|
@@ -714,49 +1166,36 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
714
1166
|
? [NSColor colorWithSRGBRed:0.31 green:0.83 blue:0.90 alpha:1].CGColor
|
|
715
1167
|
: [NSColor colorWithWhite:1 alpha:[bars[index][1] doubleValue]].CGColor;
|
|
716
1168
|
bar.translatesAutoresizingMaskIntoConstraints = NO;
|
|
717
|
-
[
|
|
1169
|
+
[container addSubview:bar];
|
|
718
1170
|
[NSLayoutConstraint activateConstraints:@[
|
|
719
|
-
[bar.leadingAnchor constraintEqualToAnchor:
|
|
720
|
-
[bar.widthAnchor constraintEqualToAnchor:
|
|
1171
|
+
[bar.leadingAnchor constraintEqualToAnchor:container.leadingAnchor constant:10],
|
|
1172
|
+
[bar.widthAnchor constraintEqualToAnchor:container.widthAnchor multiplier:[bars[index][0] doubleValue]
|
|
721
1173
|
constant:-20 * [bars[index][0] doubleValue]],
|
|
722
1174
|
[bar.heightAnchor constraintEqualToConstant:4],
|
|
723
1175
|
previous ? [bar.topAnchor constraintEqualToAnchor:previous.bottomAnchor constant:5]
|
|
724
|
-
: [bar.topAnchor constraintEqualToAnchor:
|
|
1176
|
+
: [bar.topAnchor constraintEqualToAnchor:container.topAnchor constant:18],
|
|
725
1177
|
]];
|
|
726
1178
|
previous = bar;
|
|
727
1179
|
}
|
|
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
1180
|
return preview;
|
|
743
1181
|
}
|
|
744
1182
|
|
|
745
|
-
|
|
1183
|
+
// accessory:卡片底部的附加行(Liquid Glass 卡片里放压暗滑块),可为 nil。
|
|
1184
|
+
- (CCPetsTileView *)themeTileLiquid:(BOOL)liquid accessory:(NSView *)accessory {
|
|
746
1185
|
CCPetsTileView *tile = [CCPetsTileView new];
|
|
747
1186
|
NSView *preview = [self themePreviewLiquid:liquid];
|
|
748
1187
|
NSTextField *title = CCPetsLabel(liquid ? @"Liquid Glass" : L(@"Classic"), 13, NSFontWeightSemibold, CCPetsInkColor());
|
|
749
1188
|
NSMutableArray<NSView *> *views = [NSMutableArray arrayWithObjects:preview, title, nil];
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
1189
|
+
// 两张卡片结构对齐:预览 → 标题 → 说明 → 底部一行(经典是说明文字,Liquid Glass 是压暗滑块)。
|
|
1190
|
+
NSTextField *note = CCPetsLabel(liquid ? L(@"macOS 26 or later") : L(@"Works on all macOS versions"),
|
|
1191
|
+
11, NSFontWeightRegular, CCPetsTertiaryInkColor());
|
|
1192
|
+
[views addObject:note];
|
|
1193
|
+
if (accessory) [views addObject:accessory];
|
|
755
1194
|
for (NSView *view in views) {
|
|
756
1195
|
view.translatesAutoresizingMaskIntoConstraints = NO;
|
|
757
1196
|
[tile addSubview:view];
|
|
758
1197
|
}
|
|
759
|
-
NSView *last = note ?: title;
|
|
1198
|
+
NSView *last = accessory ?: note ?: title;
|
|
760
1199
|
[NSLayoutConstraint activateConstraints:@[
|
|
761
1200
|
[preview.topAnchor constraintEqualToAnchor:tile.topAnchor constant:10],
|
|
762
1201
|
[preview.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:10],
|
|
@@ -772,40 +1211,51 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
772
1211
|
[NSLayoutConstraint activateConstraints:@[
|
|
773
1212
|
[note.topAnchor constraintEqualToAnchor:title.bottomAnchor constant:1],
|
|
774
1213
|
[note.leadingAnchor constraintEqualToAnchor:title.leadingAnchor],
|
|
775
|
-
[note.bottomAnchor constraintEqualToAnchor:tile.bottomAnchor constant:-10],
|
|
776
1214
|
]];
|
|
777
1215
|
}
|
|
1216
|
+
if (accessory) {
|
|
1217
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
1218
|
+
[accessory.topAnchor constraintEqualToAnchor:(note ?: title).bottomAnchor constant:8],
|
|
1219
|
+
[accessory.leadingAnchor constraintEqualToAnchor:tile.leadingAnchor constant:12],
|
|
1220
|
+
[accessory.trailingAnchor constraintEqualToAnchor:tile.trailingAnchor constant:-12],
|
|
1221
|
+
]];
|
|
1222
|
+
// 附加行里是滑块这类控件,不该显示卡片的手形指针。
|
|
1223
|
+
if (liquid) tile.cursorExclusionView = accessory;
|
|
1224
|
+
}
|
|
1225
|
+
// 内容更多的 Liquid Glass 卡片决定高度,经典卡片通过等高约束跟随,多出的高度留在下面。
|
|
1226
|
+
if (liquid) [last.bottomAnchor constraintEqualToAnchor:tile.bottomAnchor constant:-10].active = YES;
|
|
778
1227
|
return tile;
|
|
779
1228
|
}
|
|
780
1229
|
|
|
781
1230
|
- (void)buildContent {
|
|
782
1231
|
__weak typeof(self) weakSelf = self;
|
|
783
1232
|
|
|
784
|
-
|
|
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
|
-
// 浮层外观:两张主题卡片 + 玻璃压暗滑块。
|
|
1233
|
+
// 浮层外观:两张主题卡片,压暗滑块放在 Liquid Glass 卡片里,拖动时上方预览实时变化。
|
|
806
1234
|
[self.form addGroupTitle:L(@"Panel Appearance") note:nil];
|
|
807
|
-
|
|
808
|
-
|
|
1235
|
+
// 滑块按 0–100 的强度展示,实际压暗仍是 0–45(换算在 CCPetsGlassDimLevelForPercent)。
|
|
1236
|
+
NSSlider *dim = [NSSlider sliderWithValue:0 minValue:0 maxValue:100 target:nil action:nil];
|
|
1237
|
+
dim.continuous = YES;
|
|
1238
|
+
dim.controlSize = NSControlSizeSmall;
|
|
1239
|
+
CCPetsApplyAccent(dim);
|
|
1240
|
+
[dim setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
1241
|
+
NSTextField *dimLabel = [self sliderValueLabel];
|
|
1242
|
+
NSTextField *dimTitle = CCPetsLabel(L(@"Dimming"), 11, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
1243
|
+
NSStackView *dimRow = [NSStackView stackViewWithViews:@[dimTitle, dim, dimLabel]];
|
|
1244
|
+
dimRow.orientation = NSUserInterfaceLayoutOrientationHorizontal;
|
|
1245
|
+
dimRow.alignment = NSLayoutAttributeCenterY;
|
|
1246
|
+
dimRow.spacing = 8;
|
|
1247
|
+
dimRow.toolTip = L(@"Raise it when a bright wallpaper makes text hard to read");
|
|
1248
|
+
dim.toolTip = dimRow.toolTip;
|
|
1249
|
+
|
|
1250
|
+
NSTextField *classicDetail = CCPetsLabel(L(@"Opaque dark background for better readability"),
|
|
1251
|
+
11, NSFontWeightRegular, CCPetsSecondaryInkColor());
|
|
1252
|
+
classicDetail.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
1253
|
+
[classicDetail setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow
|
|
1254
|
+
forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
1255
|
+
NSStackView *classicRow = [NSStackView stackViewWithViews:@[classicDetail]];
|
|
1256
|
+
classicRow.alignment = NSLayoutAttributeCenterY;
|
|
1257
|
+
CCPetsTileView *classic = [self themeTileLiquid:NO accessory:classicRow];
|
|
1258
|
+
CCPetsTileView *liquid = [self themeTileLiquid:YES accessory:dimRow];
|
|
809
1259
|
classic.onClick = ^{ [weakSelf.actions updatePanelTheme:@"classic"]; };
|
|
810
1260
|
BOOL liquidAvailable = CCPetsLiquidGlassAvailable();
|
|
811
1261
|
if (liquidAvailable) liquid.onClick = ^{ [weakSelf.actions updatePanelTheme:@"liquid"]; };
|
|
@@ -814,31 +1264,68 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
814
1264
|
themes.distribution = NSStackViewDistributionFillEqually;
|
|
815
1265
|
themes.alignment = NSLayoutAttributeTop;
|
|
816
1266
|
themes.spacing = 10;
|
|
817
|
-
|
|
1267
|
+
themes.translatesAutoresizingMaskIntoConstraints = NO;
|
|
1268
|
+
// 两张卡片只占整行宽度的 70%,靠左排,避免比其他设置行更抢眼。
|
|
1269
|
+
NSView *themeRow = [NSView new];
|
|
1270
|
+
[themeRow addSubview:themes];
|
|
1271
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
1272
|
+
[themes.leadingAnchor constraintEqualToAnchor:themeRow.leadingAnchor],
|
|
1273
|
+
[themes.topAnchor constraintEqualToAnchor:themeRow.topAnchor],
|
|
1274
|
+
[themes.bottomAnchor constraintEqualToAnchor:themeRow.bottomAnchor],
|
|
1275
|
+
[themes.widthAnchor constraintEqualToAnchor:themeRow.widthAnchor multiplier:0.7],
|
|
1276
|
+
]];
|
|
1277
|
+
[self.form addView:themeRow];
|
|
818
1278
|
[classic.heightAnchor constraintEqualToAnchor:liquid.heightAnchor].active = YES;
|
|
1279
|
+
// 底部一行和滑块那行等高,文字与“压暗”对齐。两张卡片进了同一个父视图后才能互相约束。
|
|
1280
|
+
[classicRow.heightAnchor constraintEqualToAnchor:dimRow.heightAnchor].active = YES;
|
|
819
1281
|
|
|
820
|
-
NSSlider *dim = [self sliderWithMinimum:0 maximum:CCPetsGlassDimMaximum width:200];
|
|
821
|
-
NSTextField *dimLabel = [self sliderValueLabel];
|
|
822
1282
|
[self bind:dim to:^(NSSlider *sender) {
|
|
823
1283
|
NSInteger value = (NSInteger)lround(sender.doubleValue);
|
|
824
1284
|
dimLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)value];
|
|
825
|
-
[weakSelf showGlassDim:value];
|
|
1285
|
+
[weakSelf showGlassDim:CCPetsGlassDimLevelForPercent(value)];
|
|
826
1286
|
[weakSelf.actions updateGlassDimLevel:@(value)];
|
|
827
1287
|
}];
|
|
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
1288
|
[self.reloaders addObject:^{
|
|
831
1289
|
BOOL isLiquid = [CCPetsPanelTheme() isEqualToString:@"liquid"] && liquidAvailable;
|
|
832
1290
|
classic.selected = !isLiquid;
|
|
833
1291
|
liquid.selected = isLiquid;
|
|
834
|
-
NSInteger
|
|
835
|
-
dim.doubleValue =
|
|
836
|
-
dimLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)
|
|
1292
|
+
NSInteger percent = CCPetsGlassDimPercent();
|
|
1293
|
+
dim.doubleValue = percent;
|
|
1294
|
+
dimLabel.stringValue = [NSString stringWithFormat:@"%ld%%", (long)percent];
|
|
837
1295
|
// 压暗只作用于原生玻璃,经典主题下没有这层。
|
|
838
1296
|
dim.enabled = isLiquid;
|
|
839
|
-
[weakSelf showGlassDim:
|
|
1297
|
+
[weakSelf showGlassDim:CCPetsGlassDimLevel()];
|
|
840
1298
|
}];
|
|
841
|
-
|
|
1299
|
+
|
|
1300
|
+
NSMutableArray<NSArray *> *languages = [NSMutableArray arrayWithObject:@[L(@"System Default"), CCPetsLanguageSystem]];
|
|
1301
|
+
for (NSString *language in CCPetsSupportedLanguages()) {
|
|
1302
|
+
[languages addObject:@[CCPetsLanguageDisplayName(language), language]];
|
|
1303
|
+
}
|
|
1304
|
+
NSPopUpButton *language = [self popUpWithOptions:languages
|
|
1305
|
+
selected:^id { return CCPetsLanguagePreference(); }
|
|
1306
|
+
action:^(NSString *value) {
|
|
1307
|
+
if ([value isEqualToString:CCPetsLanguagePreference()]) return;
|
|
1308
|
+
// 主窗口收到语言变更会重建本页,别在控件自己的 action 里把它拆掉。
|
|
1309
|
+
dispatch_async(dispatch_get_main_queue(), ^{ CCPetsSetLanguagePreference(value); });
|
|
1310
|
+
}];
|
|
1311
|
+
NSSegmentedControl *appearance = [self segmentedWithOptions:@[
|
|
1312
|
+
@[L(@"System Default"), @"system"], @[L(@"Light"), @"light"], @[L(@"Dark"), @"dark"]]
|
|
1313
|
+
selected:^id { return CCPetsMainWindowAppearancePreference(); }
|
|
1314
|
+
action:^(NSString *value) { CCPetsPrefSetObject(CCPetsMainWindowAppearanceKey, value); }];
|
|
1315
|
+
[self.form addGroupWithTitle:nil rows:@[
|
|
1316
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Language") controls:@[language]],
|
|
1317
|
+
[CCPetsFormBuilder rowWithTitle:L(@"Window Appearance")
|
|
1318
|
+
subtitle:L(@"Only this window; the pet's panels follow Panel Appearance above") controls:@[appearance]],
|
|
1319
|
+
] footer:nil];
|
|
1320
|
+
|
|
1321
|
+
[self.form addGroupWithTitle:L(@"Launch Protection") rows:@[
|
|
1322
|
+
[self switchRowWithTitle:@"Shadowrocket"
|
|
1323
|
+
subtitle:L(@"Block Claude / Codex when Shadowrocket is disconnected or the exit is in an unsupported region")
|
|
1324
|
+
key:CCPetsShadowrocketLaunchCheckKey
|
|
1325
|
+
apply:^(id<CCPetsSettingsActions> actions, BOOL enabled) {
|
|
1326
|
+
CCPetsPrefSetBool(CCPetsShadowrocketLaunchCheckKey, enabled);
|
|
1327
|
+
}],
|
|
1328
|
+
] footer:L(@"Off by default. Checks each service's exit IP and region through CC Pets wrappers; does not validate your account or API key.")];
|
|
842
1329
|
|
|
843
1330
|
// 悬停面板:每家一个胶囊,点一下在订阅额度和 Token 用量之间切换,和右键菜单同一个样子。
|
|
844
1331
|
[self.form addGroupTitle:L(@"Hover Panel") note:L(@"Click a pill to switch")];
|
|
@@ -892,6 +1379,13 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
892
1379
|
[panelRows addObject:[CCPetsFormBuilder rowWithTitle:L(@"System Status") controls:@[metrics]]];
|
|
893
1380
|
[self.form addGroupWithTitle:nil rows:panelRows footer:nil];
|
|
894
1381
|
|
|
1382
|
+
// 终端跳转:一张卡片,行在 refreshIDEIntegration 拿到检测结果后填入。
|
|
1383
|
+
[self.form addGroupTitle:L(@"Terminal Jump") note:L(@"Click an agent card to return to its terminal")
|
|
1384
|
+
info:L(@"Terminal, iTerm2 and Ghostty are located by TTY through AppleScript and need CC Pets allowed under System Settings → Privacy & Security → Automation. JetBrains IDEs need the CC Pets Terminal plugin (2026.2 / 2026.3, local Reworked terminal), installed in each IDE separately. VS Code and its forks such as Cursor and Windsurf need the CC Pets Terminal extension, installed in each app separately; remote windows are not supported. Other terminals such as Warp are only brought forward.")];
|
|
1385
|
+
NSView *checking = [CCPetsFormBuilder rowWithTitle:L(@"Checking…") controls:@[]];
|
|
1386
|
+
self.terminalJumpCard = [self.form addGroupWithTitle:nil rows:@[checking] footer:nil];
|
|
1387
|
+
self.terminalJumpSnapshot = nil;
|
|
1388
|
+
|
|
895
1389
|
[self.form addGroupWithTitle:L(@"Data") rows:@[
|
|
896
1390
|
[CCPetsFormBuilder rowWithTitle:L(@"Pet sprites folder") subtitle:[self displayPath:OwnPetsDirectory()]
|
|
897
1391
|
controls:@[[self smallButtonWithTitle:L(@"Show in Finder") action:^{ RevealFolder(OwnPetsDirectory()); }]]],
|
|
@@ -910,8 +1404,9 @@ static const NSUInteger PetPickerColumns = 4;
|
|
|
910
1404
|
return (NSTextField *)titles.arrangedSubviews.lastObject;
|
|
911
1405
|
}
|
|
912
1406
|
|
|
913
|
-
|
|
914
|
-
|
|
1407
|
+
// level 是实际不透明度百分比(0–45)。
|
|
1408
|
+
- (void)showGlassDim:(double)level {
|
|
1409
|
+
[self.glassPreview applyDimLevel:level];
|
|
915
1410
|
}
|
|
916
1411
|
|
|
917
1412
|
@end
|