cc-pets 2.4.0 → 2.5.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 +46 -9
- package/CC_BRIDGE.zh-CN.md +29 -6
- 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 +69 -16
- package/README.zh-CN.md +54 -19
- package/Resources/zh-Hans.lproj/Localizable.strings +35 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +47 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +109 -14
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +8 -6
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +13 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +6 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +5 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +4 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +4 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.m +4 -2
- package/Sources/CCPets/Bridge/CCPetsBridge.m +34 -12
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +100 -33
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +317 -89
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +210 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +28 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +222 -35
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +1 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +6 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +54 -5
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +9 -1
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +10 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +18 -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 +528 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +95 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +4 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +16 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +5 -3
- package/package.json +1 -1
|
@@ -18,6 +18,50 @@ static BOOL ProcessInfoForPID(pid_t pid, struct kinfo_proc *info) {
|
|
|
18
18
|
return sysctl(name, 4, info, &length, NULL, 0) == 0 && length > 0;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
BOOL IsCodexDesktopFocusTarget(NSDictionary *target) {
|
|
22
|
+
if (![target isKindOfClass:NSDictionary.class]) return NO;
|
|
23
|
+
return [target[@"bundleID"] isEqual:@"com.openai.codex"] &&
|
|
24
|
+
(![target[@"tty"] isKindOfClass:NSString.class] || [target[@"tty"] length] == 0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
BOOL CodexDesktopFocusTargetIsLive(NSDictionary *target, NSTimeInterval eventTime) {
|
|
28
|
+
if (!IsCodexDesktopFocusTarget(target) || !(eventTime > 0)) return NO;
|
|
29
|
+
for (NSRunningApplication *app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.openai.codex"]) {
|
|
30
|
+
if (!app.terminated && app.launchDate && app.launchDate.timeIntervalSince1970 <= eventTime) return YES;
|
|
31
|
+
}
|
|
32
|
+
return NO;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
BOOL CodexDesktopApplicationIsRunning(void) {
|
|
36
|
+
for (NSRunningApplication *app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.openai.codex"]) {
|
|
37
|
+
if (!app.terminated) return YES;
|
|
38
|
+
}
|
|
39
|
+
return NO;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
NSNumber *CodexPersistentThreadStatus(NSString *thread, NSString *codexHome) {
|
|
43
|
+
if (thread.length == 0 || !codexHome.isAbsolutePath) return nil;
|
|
44
|
+
sqlite3 *db = NULL;
|
|
45
|
+
NSString *path = [codexHome stringByAppendingPathComponent:@"state_5.sqlite"];
|
|
46
|
+
if (sqlite3_open_v2(path.fileSystemRepresentation, &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX, NULL) != SQLITE_OK) {
|
|
47
|
+
if (db) sqlite3_close(db);
|
|
48
|
+
return nil;
|
|
49
|
+
}
|
|
50
|
+
sqlite3_busy_timeout(db, 10);
|
|
51
|
+
sqlite3_stmt *statement = NULL;
|
|
52
|
+
NSNumber *result = nil;
|
|
53
|
+
// 索引不可读或版本改变时返回未知,不能把错误当作“会话已退出”。
|
|
54
|
+
if (sqlite3_prepare_v2(db, "SELECT archived FROM threads WHERE id = ? LIMIT 1", -1, &statement, NULL) == SQLITE_OK) {
|
|
55
|
+
sqlite3_bind_text(statement, 1, thread.UTF8String, -1, SQLITE_TRANSIENT);
|
|
56
|
+
int step = sqlite3_step(statement);
|
|
57
|
+
if (step == SQLITE_ROW) result = @(sqlite3_column_int(statement, 0) == 0);
|
|
58
|
+
else if (step == SQLITE_DONE) result = @NO;
|
|
59
|
+
}
|
|
60
|
+
sqlite3_finalize(statement);
|
|
61
|
+
sqlite3_close(db);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
21
65
|
// 包装脚本没被走到时(用户直接跑 codex / claude,或终端窗口早于 shim 安装就已打开)
|
|
22
66
|
// 环境里没有 CC_PETS_TERMINAL_*。记录端自己是 Agent 的子进程,控制终端就是 Agent
|
|
23
67
|
// 所在的那个 tty,直接问内核即可——stdin 是 JSON 管道,isatty 这类办法在这里没用。
|
|
@@ -275,7 +319,7 @@ BOOL ActivateTerminalFocusTarget(NSDictionary *target) {
|
|
|
275
319
|
// 能确定的只有两头:codex-with-pet 启动时知道自己的终端、工作目录和时刻;hook 知道会话 ID,
|
|
276
320
|
// 会话记录(rollout)的第一行又记着会话的工作目录和创建时刻。CLI 启动后可能还要等网络
|
|
277
321
|
// 初始化,不能按包装脚本的启动先后猜测归属。多个候选时读取本机 TUI 就绪日志的 PID,
|
|
278
|
-
//
|
|
322
|
+
// 仅在会话创建前后一秒内存在唯一就绪候选时配对;信息不足就留空,之后的 Hook 可再试。
|
|
279
323
|
static const NSUInteger CodexLaunchThreadLimit = 32;
|
|
280
324
|
static const NSTimeInterval CodexClientReadyWindow = 1.0;
|
|
281
325
|
|
|
@@ -433,7 +477,10 @@ static NSDictionary *CodexThreadMeta(NSString *thread, NSDictionary *payload, NS
|
|
|
433
477
|
return result;
|
|
434
478
|
}
|
|
435
479
|
|
|
436
|
-
// Codex
|
|
480
|
+
// Codex 的本机日志记录每个 TUI 的就绪时刻和带 PID 的 process_uuid。
|
|
481
|
+
// 初始会话可能先于首帧就绪(0.167.1 实测晚约 1.56ms 才记录就绪),不能要求就绪
|
|
482
|
+
// 一定早于会话创建。前后使用同一窄窗口,并在整个窗口内检查唯一性,避免两侧各有
|
|
483
|
+
// 一个候选时误配;SQL 的秒级范围与下面的精确时间过滤必须使用相同的上下界。
|
|
437
484
|
// 只读这一类元数据,不读取提示词、输出或 HTTP 日志。内部日志格式改变、日志尚未落盘、
|
|
438
485
|
// 多个客户端同时就绪时都不能猜测;sqlite 的读锁等待和返回条数也有上限。
|
|
439
486
|
static int CodexLogQueryExpired(void *context) {
|
|
@@ -459,15 +506,17 @@ static NSString *ReadyCodexLaunch(NSDictionary<NSString *, NSDictionary *> *laun
|
|
|
459
506
|
"AND feedback_log_body LIKE 'tui startup initial frame scheduled%' LIMIT 128";
|
|
460
507
|
NSMutableSet<NSString *> *matches = [NSMutableSet set];
|
|
461
508
|
BOOL complete = NO;
|
|
509
|
+
NSTimeInterval earliestReadyAt = createdAt.doubleValue - CodexClientReadyWindow;
|
|
510
|
+
NSTimeInterval latestReadyAt = createdAt.doubleValue + CodexClientReadyWindow;
|
|
462
511
|
if (sqlite3_prepare_v2(database, query, -1, &statement, NULL) == SQLITE_OK) {
|
|
463
|
-
sqlite3_bind_int64(statement, 1, (sqlite3_int64)floor(
|
|
464
|
-
sqlite3_bind_int64(statement, 2, (sqlite3_int64)ceil(
|
|
512
|
+
sqlite3_bind_int64(statement, 1, (sqlite3_int64)floor(earliestReadyAt));
|
|
513
|
+
sqlite3_bind_int64(statement, 2, (sqlite3_int64)ceil(latestReadyAt));
|
|
465
514
|
int result;
|
|
466
515
|
NSUInteger rows = 0;
|
|
467
516
|
while ((result = sqlite3_step(statement)) == SQLITE_ROW) {
|
|
468
517
|
rows++;
|
|
469
518
|
double readyAt = sqlite3_column_int64(statement, 0) + sqlite3_column_int64(statement, 1) / 1e9;
|
|
470
|
-
if (readyAt
|
|
519
|
+
if (readyAt < earliestReadyAt || readyAt > latestReadyAt) continue;
|
|
471
520
|
const unsigned char *value = sqlite3_column_text(statement, 2);
|
|
472
521
|
NSString *process = value ? @((const char *)value) : @"";
|
|
473
522
|
for (NSString *key in candidates) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import "CCPetsPhrasesEditor.h"
|
|
2
2
|
#import "CCPetsL10n.h"
|
|
3
3
|
#import "CCPetsPhrases.h"
|
|
4
|
+
#import "CCPetsPreferences.h"
|
|
4
5
|
#import "CCPetsUIStyle.h"
|
|
5
6
|
|
|
6
7
|
static void (^PetPhrasesSpeakHandler)(NSString *);
|
|
@@ -491,6 +492,12 @@ static void (^PetPhrasesSpeakHandler)(NSString *);
|
|
|
491
492
|
[self showStatus:[NSString stringWithFormat:L(@"[%@] has no usable lines."), tag] warning:YES];
|
|
492
493
|
return;
|
|
493
494
|
}
|
|
495
|
+
// 「仅菜单栏」时桌宠藏着,说了也看不见;照实告诉用户,句子本身仍然显示出来。
|
|
496
|
+
if ([CCPetsDisplayMode() isEqualToString:CCPetsDisplayModeMenuBar]) {
|
|
497
|
+
[self showStatus:[NSString stringWithFormat:L(@"The pet is hidden (menu bar only). Line: %@"), text]
|
|
498
|
+
warning:YES];
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
494
501
|
if (PetPhrasesSpeakHandler) PetPhrasesSpeakHandler(text);
|
|
495
502
|
[self showStatus:[NSString stringWithFormat:L(@"Trying: %1$@%2$@"), text,
|
|
496
503
|
fellBack ? L(@" (from the shared lines)") : @""] warning:NO];
|
|
@@ -490,6 +490,11 @@ static const NSInteger PetMenuDeleteButtonTag = 1002;
|
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
- (void)rightMouseDown:(NSEvent *)event {
|
|
493
|
+
[NSMenu popUpContextMenu:[self buildContextMenu] withEvent:event forView:self];
|
|
494
|
+
[self finishContextMenu];
|
|
495
|
+
}
|
|
496
|
+
// 菜单栏图标的右键菜单也是这一份,所以建菜单和收尾分开,不和 NSEvent 绑在一起。
|
|
497
|
+
- (NSMenu *)buildContextMenu {
|
|
493
498
|
NSArray<NSDictionary *> *availablePets = self.petOptionsRequested ? self.petOptionsRequested() : @[];
|
|
494
499
|
NSMenu *menu = [NSMenu new];
|
|
495
500
|
menu.minimumWidth = 194.0;
|
|
@@ -590,7 +595,10 @@ static const NSInteger PetMenuDeleteButtonTag = 1002;
|
|
|
590
595
|
openItem.target = NSApp.delegate;
|
|
591
596
|
NSMenuItem *quitItem = [menu addItemWithTitle:L(@"Quit CC Pets") action:@selector(terminate:) keyEquivalent:@"q"];
|
|
592
597
|
quitItem.target = NSApp;
|
|
593
|
-
|
|
598
|
+
return menu;
|
|
599
|
+
}
|
|
600
|
+
// 菜单收起后:收掉悬停说明和宠物预览浮窗。
|
|
601
|
+
- (void)finishContextMenu {
|
|
594
602
|
[MenuHint cancel];
|
|
595
603
|
self.activePetSwitchMenu = nil;
|
|
596
604
|
[self.petMenuPreviewPanel orderOut:nil];
|
|
@@ -42,5 +42,12 @@
|
|
|
42
42
|
- (instancetype)initWithFrame:(NSRect)frame sheet:(NSImage *)sheet rowCount:(NSInteger)rowCount;
|
|
43
43
|
- (void)applySheet:(NSImage *)sheet petID:(NSString *)petID rowCount:(NSInteger)rowCount;
|
|
44
44
|
- (void)handleAgentEvent:(NSString *)event tool:(NSString *)tool failed:(BOOL)failed;
|
|
45
|
+
- (void)resetAgentToIdle;
|
|
45
46
|
- (void)playRow:(NSInteger)row throughFrame:(NSInteger)last oneShot:(BOOL)oneShot;
|
|
46
47
|
@end
|
|
48
|
+
|
|
49
|
+
// 右键菜单(现建)与菜单收起后的收尾,实现在 PetView+Menu.m。桌宠右键和菜单栏图标右键共用。
|
|
50
|
+
@interface PetView (Menu)
|
|
51
|
+
- (NSMenu *)buildContextMenu;
|
|
52
|
+
- (void)finishContextMenu;
|
|
53
|
+
@end
|
|
@@ -374,7 +374,18 @@ static const NSTimeInterval PetBreathPeriod = 3.6;
|
|
|
374
374
|
NSUInteger hold = self.frameHolds[index].unsignedIntegerValue;
|
|
375
375
|
return hold > 0 ? hold : 1;
|
|
376
376
|
}
|
|
377
|
+
- (void)resetAgentToIdle {
|
|
378
|
+
[self noteActivity];
|
|
379
|
+
self.agentActive = NO;
|
|
380
|
+
if (self.microActive) [self endMicroBehavior];
|
|
381
|
+
[self playRow:0 throughFrame:5 oneShot:NO];
|
|
382
|
+
}
|
|
377
383
|
- (void)handleAgentEvent:(NSString *)event tool:(NSString *)tool failed:(BOOL)failed {
|
|
384
|
+
// 会话退出不代表任务成功;直接恢复待机,不播放完成动作。
|
|
385
|
+
if ([event isEqualToString:@"SessionEnd"]) {
|
|
386
|
+
[self resetAgentToIdle];
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
378
389
|
[self noteActivity];
|
|
379
390
|
[self bumpExertion];
|
|
380
391
|
if ([event isEqualToString:@"SessionStart"]) {
|
|
@@ -418,7 +429,7 @@ static const NSTimeInterval PetBreathPeriod = 3.6;
|
|
|
418
429
|
self.agentActive = YES;
|
|
419
430
|
[self playRow:4 throughFrame:4 oneShot:YES];
|
|
420
431
|
} else if ([event isEqualToString:@"Stop"] || [event isEqualToString:@"SubagentStop"] ||
|
|
421
|
-
[event isEqualToString:@"TaskCompleted"]
|
|
432
|
+
[event isEqualToString:@"TaskCompleted"]) {
|
|
422
433
|
self.agentActive = YES;
|
|
423
434
|
[self playRow:3 throughFrame:3 oneShot:YES];
|
|
424
435
|
}
|
|
@@ -18,6 +18,16 @@ 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
|
+
// 规整后的显示位置:没写过或写了未知值都按仅桌宠处理。
|
|
29
|
+
NSString *CCPetsDisplayMode(void);
|
|
30
|
+
|
|
21
31
|
// 布尔设置。碎碎念这类"没写过就算开"的键在这里统一兜底,调用方不必各自判 nil。
|
|
22
32
|
BOOL CCPetsPrefBool(NSString *key);
|
|
23
33
|
void CCPetsPrefSetBool(NSString *key, BOOL value);
|
|
@@ -11,6 +11,21 @@ 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
|
+
|
|
20
|
+
static NSArray<NSString *> *DisplayModes(void) {
|
|
21
|
+
return @[CCPetsDisplayModePet, CCPetsDisplayModeBoth, CCPetsDisplayModeMenuBar];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
NSString *CCPetsDisplayMode(void) {
|
|
25
|
+
id value = [NSUserDefaults.standardUserDefaults objectForKey:CCPetsDisplayModeKey];
|
|
26
|
+
return [value isKindOfClass:NSString.class] && [DisplayModes() containsObject:value]
|
|
27
|
+
? value : CCPetsDisplayModePet;
|
|
28
|
+
}
|
|
14
29
|
|
|
15
30
|
// 包装器运行的是裸二进制,默认 preferences domain 与 App bundle 不同。
|
|
16
31
|
// 启动保护的读取和写入统一走 CFPreferences 的同一个域、用户和主机。
|
|
@@ -96,6 +111,9 @@ id CCPetsPrefNormalizedValue(NSString *key, id value) {
|
|
|
96
111
|
return count ? @(count.integerValue) : nil;
|
|
97
112
|
}
|
|
98
113
|
if ([key isEqualToString:PetInteractionIntervalKey]) return ClampedNumber(value, 0.4, 3.0);
|
|
114
|
+
if ([key isEqualToString:CCPetsDisplayModeKey]) {
|
|
115
|
+
return [value isKindOfClass:NSString.class] && [DisplayModes() containsObject:value] ? value : nil;
|
|
116
|
+
}
|
|
99
117
|
if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class]) return value;
|
|
100
118
|
return nil;
|
|
101
119
|
}
|
|
@@ -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
|