cc-pets 0.2.13 → 0.2.15
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/CHANGELOG.md +3 -1
- package/README.md +7 -2
- package/Sources/CCPets/main.m +267 -0
- package/package.json +1 -1
- package/scripts/configure-updater.mjs +42 -0
- package/scripts/install-shell-integration.sh +1 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
- 鼠标悬停口袋时展开额度详情面板,用两张卡分别显示 Codex、Claude 的剩余 5 小时额度、周额度和精确到秒的周重置时间
|
|
11
11
|
- reset 时间自动转换为 Mac 当前系统时区,例如 `Jul 22 3pm America/Los_Angeles` 在上海时区显示为 `7/23 06:00:00`
|
|
12
12
|
- 支持待机、左右拖动、身体两侧感应、头部/脚部悬停和点击反馈动画
|
|
13
|
-
-
|
|
13
|
+
- 支持拖动桌宠位置,右键刷新用量、检查更新或退出
|
|
14
14
|
- 响应 Codex 与 Claude Code Agent 的思考、工具调用、审批、子 Agent、完成和失败状态
|
|
15
15
|
- 使用原生 AppKit,运行时不依赖 Electron
|
|
16
16
|
|
|
@@ -52,7 +52,7 @@ Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`mod
|
|
|
52
52
|
| 按住并向右拖动 | 播放向右拖行动画,同时移动桌宠 |
|
|
53
53
|
| 按住并向左拖动 | 播放向左拖行动画,同时移动桌宠 |
|
|
54
54
|
| 鼠标移开或拖动结束 | 恢复默认待机动画 |
|
|
55
|
-
| 右键桌宠 |
|
|
55
|
+
| 右键桌宠 | 切换已有桌宠、刷新用量、检查更新或退出 |
|
|
56
56
|
|
|
57
57
|
右键菜单中的“切换桌宠”会动态扫描 `~/.petdex/pets/`、`~/.codex/pets/` 以及包内素材。
|
|
58
58
|
外部桌宠使用目录名作为菜单名称,内置桌宠使用素材文件名(不显示扩展名)。选择后立即
|
|
@@ -132,6 +132,11 @@ npm 的安装后脚本会自动构建原生应用、安装两套 Agent Hooks,
|
|
|
132
132
|
同时会将标准 macOS 应用安装到 `~/Applications/CC Pets.app`,可从 Finder 或 Launchpad 启动,
|
|
133
133
|
不需要管理员权限。npm 升级时会同步更新该应用。
|
|
134
134
|
|
|
135
|
+
安装完成后也可以右键桌宠并选择“检查更新…”。应用会查询 npm Registry,发现新版本后请求确认,
|
|
136
|
+
随后在后台复用首次安装时记录的 Node.js/npm 完成升级;用户无需打开终端。升级会同步更新原生应用、
|
|
137
|
+
Codex/Claude Hooks 和 shell 集成,并自动重启正在运行的桌宠。自动更新不会请求管理员权限;如果原来的
|
|
138
|
+
全局 npm 目录不可写或 Node.js/npm 已被移动,应用会保留旧版本并显示更新日志和手动升级命令。
|
|
139
|
+
|
|
135
140
|
### 从旧版升级
|
|
136
141
|
|
|
137
142
|
从使用 `codex-pet` 命令的旧版升级时,直接安装新版即可:
|
package/Sources/CCPets/main.m
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#import <sys/stat.h>
|
|
8
8
|
#import <fcntl.h>
|
|
9
9
|
#import <signal.h>
|
|
10
|
+
#import <unistd.h>
|
|
10
11
|
|
|
11
12
|
static NSString *PetStateDirectory(void) {
|
|
12
13
|
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_STATE_DIR"];
|
|
@@ -24,6 +25,64 @@ static NSString *ClaudeUsagePath(void) {
|
|
|
24
25
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
static NSArray<NSNumber *> *StableVersionComponents(NSString *version) {
|
|
29
|
+
if (![version isKindOfClass:NSString.class]) return nil;
|
|
30
|
+
NSArray<NSString *> *parts = [version componentsSeparatedByString:@"."];
|
|
31
|
+
if (parts.count != 3) return nil;
|
|
32
|
+
NSCharacterSet *nonDigits = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"].invertedSet;
|
|
33
|
+
NSMutableArray<NSNumber *> *components = [NSMutableArray arrayWithCapacity:3];
|
|
34
|
+
for (NSString *part in parts) {
|
|
35
|
+
if (part.length == 0 || part.length > 9 ||
|
|
36
|
+
(part.length > 1 && [part hasPrefix:@"0"]) ||
|
|
37
|
+
[part rangeOfCharacterFromSet:nonDigits].location != NSNotFound) return nil;
|
|
38
|
+
[components addObject:@(part.longLongValue)];
|
|
39
|
+
}
|
|
40
|
+
return components;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static NSComparisonResult CompareStableVersions(NSString *left, NSString *right, BOOL *valid) {
|
|
44
|
+
NSArray<NSNumber *> *leftParts = StableVersionComponents(left);
|
|
45
|
+
NSArray<NSNumber *> *rightParts = StableVersionComponents(right);
|
|
46
|
+
if (!leftParts || !rightParts) {
|
|
47
|
+
if (valid) *valid = NO;
|
|
48
|
+
return NSOrderedSame;
|
|
49
|
+
}
|
|
50
|
+
if (valid) *valid = YES;
|
|
51
|
+
for (NSUInteger index = 0; index < 3; index++) {
|
|
52
|
+
long long leftValue = leftParts[index].longLongValue;
|
|
53
|
+
long long rightValue = rightParts[index].longLongValue;
|
|
54
|
+
if (leftValue < rightValue) return NSOrderedAscending;
|
|
55
|
+
if (leftValue > rightValue) return NSOrderedDescending;
|
|
56
|
+
}
|
|
57
|
+
return NSOrderedSame;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static int RestartAfterPID(pid_t pid, NSString *appPath, BOOL managed) {
|
|
61
|
+
for (NSUInteger attempt = 0; attempt < 300; attempt++) {
|
|
62
|
+
if (pid <= 1 || (kill(pid, 0) != 0 && errno == ESRCH)) break;
|
|
63
|
+
usleep(100000);
|
|
64
|
+
}
|
|
65
|
+
if (pid > 1 && (kill(pid, 0) == 0 || errno == EPERM)) {
|
|
66
|
+
fprintf(stderr, "等待旧版 CC Pets 退出超时。\n");
|
|
67
|
+
return EXIT_FAILURE;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
NSString *openPath = NSProcessInfo.processInfo.environment[@"CC_PETS_OPEN_PATH"];
|
|
71
|
+
if (openPath.length == 0) openPath = @"/usr/bin/open";
|
|
72
|
+
NSTask *task = [NSTask new];
|
|
73
|
+
task.executableURL = [NSURL fileURLWithPath:openPath];
|
|
74
|
+
NSMutableArray<NSString *> *arguments = [NSMutableArray arrayWithObjects:@"-g", appPath, nil];
|
|
75
|
+
if (managed) [arguments addObjectsFromArray:@[@"--args", @"--managed"]];
|
|
76
|
+
task.arguments = arguments;
|
|
77
|
+
NSError *error = nil;
|
|
78
|
+
if (![task launchAndReturnError:&error]) {
|
|
79
|
+
fprintf(stderr, "无法重新启动 CC Pets: %s\n", error.localizedDescription.UTF8String);
|
|
80
|
+
return EXIT_FAILURE;
|
|
81
|
+
}
|
|
82
|
+
[task waitUntilExit];
|
|
83
|
+
return task.terminationStatus == EXIT_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
84
|
+
}
|
|
85
|
+
|
|
27
86
|
static int RecordClaudeUsage(void) {
|
|
28
87
|
NSData *input = [NSFileHandle.fileHandleWithStandardInput readDataToEndOfFile];
|
|
29
88
|
NSDictionary *payload = input.length > 0 ? [NSJSONSerialization JSONObjectWithData:input options:0 error:nil] : nil;
|
|
@@ -560,6 +619,8 @@ static NSDictionary *LatestUsage(void) {
|
|
|
560
619
|
[menu addItem:NSMenuItem.separatorItem];
|
|
561
620
|
NSMenuItem *refreshItem = [menu addItemWithTitle:@"刷新用量" action:@selector(refreshUsage:) keyEquivalent:@"r"];
|
|
562
621
|
refreshItem.target = NSApp.delegate;
|
|
622
|
+
NSMenuItem *updateItem = [menu addItemWithTitle:@"检查更新…" action:@selector(checkForUpdates:) keyEquivalent:@""];
|
|
623
|
+
updateItem.target = NSApp.delegate;
|
|
563
624
|
[menu addItem:NSMenuItem.separatorItem];
|
|
564
625
|
NSMenuItem *quitItem = [menu addItemWithTitle:@"退出桌宠" action:@selector(terminate:) keyEquivalent:@"q"];
|
|
565
626
|
quitItem.target = NSApp;
|
|
@@ -918,6 +979,9 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
918
979
|
@property NSMutableData *agentEventPartialLine;
|
|
919
980
|
@property dispatch_source_t agentEventSource;
|
|
920
981
|
@property BOOL agentEventReaderInitialized;
|
|
982
|
+
@property BOOL checkingForUpdate;
|
|
983
|
+
@property BOOL updating;
|
|
984
|
+
@property NSTask *updateTask;
|
|
921
985
|
- (void)showQuotaDashboard;
|
|
922
986
|
- (void)positionQuotaDashboard;
|
|
923
987
|
- (void)scheduleQuotaDashboardHide;
|
|
@@ -925,6 +989,193 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
925
989
|
@end
|
|
926
990
|
|
|
927
991
|
@implementation AppDelegate
|
|
992
|
+
- (NSString *)applicationSupportDirectory {
|
|
993
|
+
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_APPLICATION_SUPPORT_DIR"];
|
|
994
|
+
if (override.length > 0) return override.stringByStandardizingPath;
|
|
995
|
+
NSString *root = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject;
|
|
996
|
+
return [root stringByAppendingPathComponent:@"CC Pets"];
|
|
997
|
+
}
|
|
998
|
+
- (void)showUpdateAlertWithTitle:(NSString *)title message:(NSString *)message {
|
|
999
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
1000
|
+
NSAlert *alert = [NSAlert new];
|
|
1001
|
+
alert.messageText = title;
|
|
1002
|
+
alert.informativeText = message;
|
|
1003
|
+
[alert addButtonWithTitle:@"好"];
|
|
1004
|
+
[alert runModal];
|
|
1005
|
+
}
|
|
1006
|
+
- (NSDictionary *)updaterConfiguration {
|
|
1007
|
+
NSString *path = [[self applicationSupportDirectory] stringByAppendingPathComponent:@"updater.json"];
|
|
1008
|
+
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
1009
|
+
NSDictionary *configuration = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
1010
|
+
return [configuration isKindOfClass:NSDictionary.class] ? configuration : nil;
|
|
1011
|
+
}
|
|
1012
|
+
- (BOOL)restartAfterUpdateToVersion:(NSString *)version configuration:(NSDictionary *)configuration {
|
|
1013
|
+
NSString *appPath = [configuration[@"appPath"] isKindOfClass:NSString.class]
|
|
1014
|
+
? [configuration[@"appPath"] stringByStandardizingPath] : nil;
|
|
1015
|
+
if (appPath.length == 0 &&
|
|
1016
|
+
[NSBundle.mainBundle.bundlePath.pathExtension.lowercaseString isEqualToString:@"app"]) {
|
|
1017
|
+
appPath = NSBundle.mainBundle.bundlePath.stringByStandardizingPath;
|
|
1018
|
+
}
|
|
1019
|
+
if (appPath.length == 0) {
|
|
1020
|
+
appPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Applications"]
|
|
1021
|
+
stringByAppendingPathComponent:@"CC Pets.app"];
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
NSString *infoPath = [appPath stringByAppendingPathComponent:@"Contents/Info.plist"];
|
|
1025
|
+
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:infoPath];
|
|
1026
|
+
NSString *installedVersion = [info[@"CFBundleShortVersionString"] isKindOfClass:NSString.class]
|
|
1027
|
+
? info[@"CFBundleShortVersionString"] : nil;
|
|
1028
|
+
NSString *executablePath = [appPath stringByAppendingPathComponent:@"Contents/MacOS/cc-pets"];
|
|
1029
|
+
if (![installedVersion isEqualToString:version] ||
|
|
1030
|
+
![NSFileManager.defaultManager isExecutableFileAtPath:executablePath]) return NO;
|
|
1031
|
+
|
|
1032
|
+
NSTask *restartTask = [NSTask new];
|
|
1033
|
+
restartTask.executableURL = [NSURL fileURLWithPath:executablePath];
|
|
1034
|
+
restartTask.arguments = @[
|
|
1035
|
+
@"--restart-after-pid",
|
|
1036
|
+
[NSString stringWithFormat:@"%d", NSProcessInfo.processInfo.processIdentifier],
|
|
1037
|
+
appPath,
|
|
1038
|
+
self.managedByCLI ? @"--managed" : @"--standalone"
|
|
1039
|
+
];
|
|
1040
|
+
NSError *error = nil;
|
|
1041
|
+
if (![restartTask launchAndReturnError:&error]) return NO;
|
|
1042
|
+
[NSApp terminate:nil];
|
|
1043
|
+
return YES;
|
|
1044
|
+
}
|
|
1045
|
+
- (void)startUpdateToVersion:(NSString *)version {
|
|
1046
|
+
if (self.updating) return;
|
|
1047
|
+
NSDictionary *configuration = [self updaterConfiguration];
|
|
1048
|
+
NSString *nodePath = [configuration[@"nodePath"] isKindOfClass:NSString.class]
|
|
1049
|
+
? [configuration[@"nodePath"] stringByStandardizingPath] : nil;
|
|
1050
|
+
NSString *npmCliPath = [configuration[@"npmCliPath"] isKindOfClass:NSString.class]
|
|
1051
|
+
? [configuration[@"npmCliPath"] stringByStandardizingPath] : nil;
|
|
1052
|
+
BOOL nodeExecutable = nodePath.isAbsolutePath &&
|
|
1053
|
+
[NSFileManager.defaultManager isExecutableFileAtPath:nodePath];
|
|
1054
|
+
BOOL npmCliExists = npmCliPath.isAbsolutePath &&
|
|
1055
|
+
[NSFileManager.defaultManager isReadableFileAtPath:npmCliPath];
|
|
1056
|
+
if (!nodeExecutable || !npmCliExists) {
|
|
1057
|
+
[self showUpdateAlertWithTitle:@"无法自动更新"
|
|
1058
|
+
message:@"没有找到安装 CC Pets 时使用的 Node.js/npm。请先手动执行一次:\n\n"
|
|
1059
|
+
"npm install -g cc-pets@latest --allow-scripts=cc-pets --prefer-online"];
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
NSString *supportDirectory = [self applicationSupportDirectory];
|
|
1064
|
+
NSError *directoryError = nil;
|
|
1065
|
+
[NSFileManager.defaultManager createDirectoryAtPath:supportDirectory
|
|
1066
|
+
withIntermediateDirectories:YES attributes:nil error:&directoryError];
|
|
1067
|
+
if (directoryError) {
|
|
1068
|
+
[self showUpdateAlertWithTitle:@"无法自动更新" message:directoryError.localizedDescription];
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
NSString *logPath = [supportDirectory stringByAppendingPathComponent:@"update.log"];
|
|
1072
|
+
[NSFileManager.defaultManager createFileAtPath:logPath contents:nil attributes:@{
|
|
1073
|
+
NSFilePosixPermissions: @(S_IRUSR | S_IWUSR)
|
|
1074
|
+
}];
|
|
1075
|
+
NSFileHandle *logHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
|
|
1076
|
+
if (!logHandle) {
|
|
1077
|
+
[self showUpdateAlertWithTitle:@"无法自动更新" message:@"无法创建更新日志。"];
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
NSTask *task = [NSTask new];
|
|
1082
|
+
task.executableURL = [NSURL fileURLWithPath:nodePath];
|
|
1083
|
+
task.arguments = @[
|
|
1084
|
+
npmCliPath,
|
|
1085
|
+
@"install",
|
|
1086
|
+
@"--global",
|
|
1087
|
+
[@"cc-pets@" stringByAppendingString:version],
|
|
1088
|
+
@"--allow-scripts=cc-pets",
|
|
1089
|
+
@"--prefer-online"
|
|
1090
|
+
];
|
|
1091
|
+
task.currentDirectoryURL = [NSURL fileURLWithPath:NSHomeDirectory()];
|
|
1092
|
+
task.standardOutput = logHandle;
|
|
1093
|
+
task.standardError = logHandle;
|
|
1094
|
+
self.updating = YES;
|
|
1095
|
+
self.updateTask = task;
|
|
1096
|
+
__weak typeof(self) weakSelf = self;
|
|
1097
|
+
task.terminationHandler = ^(NSTask *finishedTask) {
|
|
1098
|
+
[logHandle closeFile];
|
|
1099
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1100
|
+
typeof(self) strongSelf = weakSelf;
|
|
1101
|
+
if (!strongSelf) return;
|
|
1102
|
+
strongSelf.updating = NO;
|
|
1103
|
+
strongSelf.updateTask = nil;
|
|
1104
|
+
if (finishedTask.terminationStatus == EXIT_SUCCESS) {
|
|
1105
|
+
if ([strongSelf restartAfterUpdateToVersion:version configuration:configuration]) return;
|
|
1106
|
+
[strongSelf showUpdateAlertWithTitle:@"更新完成"
|
|
1107
|
+
message:@"CC Pets 已更新,但没有找到可自动启动的新版应用,请手动重新启动一次。"];
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
1111
|
+
NSAlert *alert = [NSAlert new];
|
|
1112
|
+
alert.messageText = @"更新失败";
|
|
1113
|
+
alert.informativeText = [NSString stringWithFormat:
|
|
1114
|
+
@"旧版本仍可继续使用。错误详情已写入:\n%@", logPath];
|
|
1115
|
+
[alert addButtonWithTitle:@"打开日志"];
|
|
1116
|
+
[alert addButtonWithTitle:@"关闭"];
|
|
1117
|
+
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
|
1118
|
+
[NSWorkspace.sharedWorkspace openURL:[NSURL fileURLWithPath:logPath]];
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1122
|
+
NSError *launchError = nil;
|
|
1123
|
+
if (![task launchAndReturnError:&launchError]) {
|
|
1124
|
+
self.updating = NO;
|
|
1125
|
+
self.updateTask = nil;
|
|
1126
|
+
[logHandle closeFile];
|
|
1127
|
+
[self showUpdateAlertWithTitle:@"无法启动更新" message:launchError.localizedDescription];
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
[self showUpdateAlertWithTitle:@"正在更新"
|
|
1131
|
+
message:[NSString stringWithFormat:@"正在下载并安装 CC Pets %@。完成后桌宠会自动重启。", version]];
|
|
1132
|
+
}
|
|
1133
|
+
- (void)checkForUpdates:(id)sender {
|
|
1134
|
+
if (self.checkingForUpdate || self.updating) return;
|
|
1135
|
+
self.checkingForUpdate = YES;
|
|
1136
|
+
NSURL *url = [NSURL URLWithString:@"https://registry.npmjs.org/cc-pets/latest"];
|
|
1137
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
|
|
1138
|
+
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
|
|
1139
|
+
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
|
|
1140
|
+
__weak typeof(self) weakSelf = self;
|
|
1141
|
+
NSURLSessionDataTask *task = [NSURLSession.sharedSession dataTaskWithRequest:request
|
|
1142
|
+
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
1143
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1144
|
+
typeof(self) strongSelf = weakSelf;
|
|
1145
|
+
if (!strongSelf) return;
|
|
1146
|
+
strongSelf.checkingForUpdate = NO;
|
|
1147
|
+
NSHTTPURLResponse *httpResponse = [response isKindOfClass:NSHTTPURLResponse.class]
|
|
1148
|
+
? (NSHTTPURLResponse *)response : nil;
|
|
1149
|
+
NSDictionary *metadata = data
|
|
1150
|
+
? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
1151
|
+
NSString *latestVersion = [metadata[@"version"] isKindOfClass:NSString.class]
|
|
1152
|
+
? metadata[@"version"] : nil;
|
|
1153
|
+
BOOL valid = NO;
|
|
1154
|
+
NSComparisonResult comparison = CompareStableVersions(@CC_PETS_VERSION, latestVersion, &valid);
|
|
1155
|
+
if (error || httpResponse.statusCode != 200 || !valid) {
|
|
1156
|
+
NSString *message = error.localizedDescription ?: @"npm Registry 返回了无效的版本信息,请稍后重试。";
|
|
1157
|
+
[strongSelf showUpdateAlertWithTitle:@"检查更新失败" message:message];
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (comparison != NSOrderedAscending) {
|
|
1161
|
+
[strongSelf showUpdateAlertWithTitle:@"已是最新版本"
|
|
1162
|
+
message:[NSString stringWithFormat:@"当前版本:%@", @CC_PETS_VERSION]];
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
1166
|
+
NSAlert *alert = [NSAlert new];
|
|
1167
|
+
alert.messageText = @"发现新版本";
|
|
1168
|
+
alert.informativeText = [NSString stringWithFormat:
|
|
1169
|
+
@"当前版本:%@\n最新版本:%@\n\n是否立即更新?", @CC_PETS_VERSION, latestVersion];
|
|
1170
|
+
[alert addButtonWithTitle:@"立即更新"];
|
|
1171
|
+
[alert addButtonWithTitle:@"稍后"];
|
|
1172
|
+
if ([alert runModal] == NSAlertFirstButtonReturn) {
|
|
1173
|
+
[strongSelf startUpdateToVersion:latestVersion];
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
}];
|
|
1177
|
+
[task resume];
|
|
1178
|
+
}
|
|
928
1179
|
- (NSDictionary *)petManifestInDirectory:(NSString *)directory {
|
|
929
1180
|
NSString *jsonPath = [directory stringByAppendingPathComponent:@"pet.json"];
|
|
930
1181
|
NSData *jsonData = [NSData dataWithContentsOfFile:jsonPath];
|
|
@@ -1372,6 +1623,22 @@ int main(int argc, const char *argv[]) {
|
|
|
1372
1623
|
printf("cc-pets %s\n", CC_PETS_VERSION);
|
|
1373
1624
|
return EXIT_SUCCESS;
|
|
1374
1625
|
}
|
|
1626
|
+
if (argc > 3 && strcmp(argv[1], "--compare-versions") == 0) {
|
|
1627
|
+
BOOL valid = NO;
|
|
1628
|
+
NSComparisonResult comparison = CompareStableVersions(
|
|
1629
|
+
[NSString stringWithUTF8String:argv[2]],
|
|
1630
|
+
[NSString stringWithUTF8String:argv[3]],
|
|
1631
|
+
&valid);
|
|
1632
|
+
if (!valid) return 2;
|
|
1633
|
+
printf("%ld\n", (long)comparison);
|
|
1634
|
+
return EXIT_SUCCESS;
|
|
1635
|
+
}
|
|
1636
|
+
if (argc > 3 && strcmp(argv[1], "--restart-after-pid") == 0) {
|
|
1637
|
+
pid_t pid = (pid_t)strtol(argv[2], NULL, 10);
|
|
1638
|
+
NSString *appPath = [NSString stringWithUTF8String:argv[3]];
|
|
1639
|
+
BOOL managed = argc > 4 && strcmp(argv[4], "--managed") == 0;
|
|
1640
|
+
return RestartAfterPID(pid, appPath, managed);
|
|
1641
|
+
}
|
|
1375
1642
|
if (argc > 1 && strcmp(argv[1], "--hook") == 0) return RecordHookEvent();
|
|
1376
1643
|
if (argc > 1 && strcmp(argv[1], "--claude-usage") == 0) return RecordClaudeUsage();
|
|
1377
1644
|
if (argc > 2 && strcmp(argv[1], "--render-dashboard") == 0) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
const nodeCandidate = process.env.npm_node_execpath || process.execPath;
|
|
8
|
+
const npmCandidate = process.env.npm_execpath;
|
|
9
|
+
|
|
10
|
+
if (!nodeCandidate || !npmCandidate) {
|
|
11
|
+
console.warn("未记录自动更新配置:npm 没有提供 node/npm-cli 路径。");
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let nodePath;
|
|
16
|
+
let npmCliPath;
|
|
17
|
+
try {
|
|
18
|
+
nodePath = fs.realpathSync(nodeCandidate);
|
|
19
|
+
npmCliPath = fs.realpathSync(npmCandidate);
|
|
20
|
+
} catch {
|
|
21
|
+
console.warn("未记录自动更新配置:node/npm-cli 路径不存在。");
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!path.isAbsolute(nodePath) || !path.isAbsolute(npmCliPath)) {
|
|
26
|
+
console.warn("未记录自动更新配置:node/npm-cli 路径不是绝对路径。");
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const supportDirectory = process.env.CC_PETS_APPLICATION_SUPPORT_DIR ||
|
|
31
|
+
path.join(os.homedir(), "Library", "Application Support", "CC Pets");
|
|
32
|
+
const applicationsDirectory = process.env.CC_PETS_APPLICATIONS_DIR ||
|
|
33
|
+
path.join(os.homedir(), "Applications");
|
|
34
|
+
const configPath = path.join(supportDirectory, "updater.json");
|
|
35
|
+
fs.mkdirSync(supportDirectory, {recursive: true, mode: 0o700});
|
|
36
|
+
fs.writeFileSync(configPath, `${JSON.stringify({
|
|
37
|
+
schemaVersion: 2,
|
|
38
|
+
nodePath,
|
|
39
|
+
npmCliPath,
|
|
40
|
+
appPath: path.join(applicationsDirectory, "CC Pets.app")
|
|
41
|
+
}, null, 2)}\n`, {mode: 0o600});
|
|
42
|
+
fs.chmodSync(configPath, 0o600);
|
|
@@ -18,6 +18,7 @@ node "${PROJECT_DIR}/scripts/install-codex-hooks.mjs" "${PROJECT_DIR}/.build/rel
|
|
|
18
18
|
node "${PROJECT_DIR}/scripts/install-claude-hooks.mjs" \
|
|
19
19
|
"${PROJECT_DIR}/.build/release/cc-pets" \
|
|
20
20
|
"${PROJECT_DIR}/bin/claude-statusline-with-pet"
|
|
21
|
+
node "${PROJECT_DIR}/scripts/configure-updater.mjs"
|
|
21
22
|
|
|
22
23
|
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
23
24
|
PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/cc-pets"
|