cc-pets 0.2.14 → 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 CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  本项目遵循语义化版本号。
4
4
 
5
- ## [未发布]
5
+ ## [0.2.15] - 2026-07-24
6
6
 
7
7
  - 支持 Codex/PetDex `spriteVersionNumber: 2` 的 `8×11` 精灵图布局及十六向鼠标跟随。
8
8
  - 新增右键“检查更新…”,可在应用内确认并完成 npm 版本升级,无需手动打开终端。
9
+ - 自动更新成功后由独立进程等待旧桌宠退出并启动新版,避免旧进程继续报告可更新。
9
10
 
10
11
  ## [0.2.0] - 2026-07-22
11
12
 
@@ -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"];
@@ -56,6 +57,32 @@ static NSComparisonResult CompareStableVersions(NSString *left, NSString *right,
56
57
  return NSOrderedSame;
57
58
  }
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
+
59
86
  static int RecordClaudeUsage(void) {
60
87
  NSData *input = [NSFileHandle.fileHandleWithStandardInput readDataToEndOfFile];
61
88
  NSDictionary *payload = input.length > 0 ? [NSJSONSerialization JSONObjectWithData:input options:0 error:nil] : nil;
@@ -982,6 +1009,39 @@ static int RenderQuotaDashboard(NSString *path) {
982
1009
  NSDictionary *configuration = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
983
1010
  return [configuration isKindOfClass:NSDictionary.class] ? configuration : nil;
984
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
+ }
985
1045
  - (void)startUpdateToVersion:(NSString *)version {
986
1046
  if (self.updating) return;
987
1047
  NSDictionary *configuration = [self updaterConfiguration];
@@ -1042,8 +1102,9 @@ static int RenderQuotaDashboard(NSString *path) {
1042
1102
  strongSelf.updating = NO;
1043
1103
  strongSelf.updateTask = nil;
1044
1104
  if (finishedTask.terminationStatus == EXIT_SUCCESS) {
1105
+ if ([strongSelf restartAfterUpdateToVersion:version configuration:configuration]) return;
1045
1106
  [strongSelf showUpdateAlertWithTitle:@"更新完成"
1046
- message:@"CC Pets 已更新。如果桌宠没有自动重启,请重新启动一次。"];
1107
+ message:@"CC Pets 已更新,但没有找到可自动启动的新版应用,请手动重新启动一次。"];
1047
1108
  return;
1048
1109
  }
1049
1110
  [NSApp activateIgnoringOtherApps:YES];
@@ -1572,6 +1633,12 @@ int main(int argc, const char *argv[]) {
1572
1633
  printf("%ld\n", (long)comparison);
1573
1634
  return EXIT_SUCCESS;
1574
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
+ }
1575
1642
  if (argc > 1 && strcmp(argv[1], "--hook") == 0) return RecordHookEvent();
1576
1643
  if (argc > 1 && strcmp(argv[1], "--claude-usage") == 0) return RecordClaudeUsage();
1577
1644
  if (argc > 2 && strcmp(argv[1], "--render-dashboard") == 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-pets",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
5
  "author": "wangxinyusqn",
6
6
  "license": "MIT",
@@ -29,11 +29,14 @@ if (!path.isAbsolute(nodePath) || !path.isAbsolute(npmCliPath)) {
29
29
 
30
30
  const supportDirectory = process.env.CC_PETS_APPLICATION_SUPPORT_DIR ||
31
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");
32
34
  const configPath = path.join(supportDirectory, "updater.json");
33
35
  fs.mkdirSync(supportDirectory, {recursive: true, mode: 0o700});
34
36
  fs.writeFileSync(configPath, `${JSON.stringify({
35
- schemaVersion: 1,
37
+ schemaVersion: 2,
36
38
  nodePath,
37
- npmCliPath
39
+ npmCliPath,
40
+ appPath: path.join(applicationsDirectory, "CC Pets.app")
38
41
  }, null, 2)}\n`, {mode: 0o600});
39
42
  fs.chmodSync(configPath, 0o600);