easy-claude 0.2.3 → 0.2.5

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
@@ -1,5 +1,17 @@
1
1
  # 更新记录
2
2
 
3
+ ## v0.2.5(2026-10-19)
4
+
5
+ - 菜单新增“更新版本”:后台复用 update,防重复点击;成功后自动重开浮窗,失败保留当前浮窗并提示,设置保持不变。
6
+
7
+ ## 0.2.4 — 2026-10-19
8
+
9
+ ### 修复
10
+
11
+ - update先在线刷新latest并比较版本,按明确版本号安装,防止旧缓存降级;相同或更高的本地版本不安装,检查失败明确报错。
12
+ - 保留上一版新增的update、show自动重开和绿色时段延长至18:00。
13
+
14
+
3
15
  ## 0.2.3 — 2026-10-19
4
16
 
5
17
  ### 新增
package/README.md CHANGED
@@ -4,16 +4,12 @@
4
4
 
5
5
  需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
6
6
 
7
- ## v0.2.3 新增与调整
7
+ ## v0.2.5 更新说明
8
8
 
9
- - **命令更新**:新增 `easy-claude update`,从官方 npm 更新当前全局安装。
10
- - **自动重开**:`easy-claude show` 会先退出自身旧浮窗,再打开新版;设置保持不变。
9
+ - 菜单新增“更新版本”,后台检查并安装最新正式版,更新期间防止重复点击。
10
+ - 更新成功后自动重开新版浮窗,保留时区、城市、位置和显示选择;失败时保留当前浮窗并提示原因。
11
11
 
12
- - 统一时间颜色:所选城市当地时间 **00:00–09:00 红色、09:00–18:00 绿色、18:00–24:00 橙色**,绿色时段延长到18:00。
13
- - 09:00转绿、18:00转橙、午夜转红,自动适应目标时区夏令时。
14
- - 保留已有时区、城市、位置和显示选择;额度圆环颜色阈值保持原有规则。
15
-
16
- 完整版本说明见 [CHANGELOG](CHANGELOG.md)。
12
+ 历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
17
13
 
18
14
  ## 安装与使用
19
15
 
@@ -74,3 +70,5 @@ npm run build:overlay
74
70
 
75
71
 
76
72
  命令更新:`easy-claude update`,更新完成后运行 `easy-claude show`,会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
73
+
74
+ 菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
@@ -225,6 +225,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
225
225
  var status: NSStatusItem?
226
226
  var timer: Timer?
227
227
  var query: Process?
228
+ var updater: Process?
228
229
  var snapshot: Snapshot?
229
230
  var error: String?
230
231
  var lastAttempt = Date.distantPast
@@ -410,6 +411,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
410
411
  zoneItem.submenu = zones
411
412
  menu.addItem(zoneItem)
412
413
  menu.addItem(.separator())
414
+ menu.addItem(item(updater == nil ? "更新版本" : "正在更新…", updater == nil ? #selector(updateVersion) : nil))
413
415
  menu.addItem(item("退出浮窗", #selector(quit)))
414
416
  return menu
415
417
  }
@@ -468,6 +470,54 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
468
470
  UserDefaults.standard.removeObject(forKey: "bottomInset")
469
471
  tick()
470
472
  }
473
+ @objc func updateVersion() {
474
+ guard updater == nil else { return }
475
+ let cli = URL(fileURLWithPath: script).deletingLastPathComponent()
476
+ .appendingPathComponent("overlay-update.js")
477
+ let process = Process()
478
+ process.executableURL = URL(fileURLWithPath: node)
479
+ process.arguments = [cli.path]
480
+ var env = ProcessInfo.processInfo.environment
481
+ env["PATH"] = searchPath
482
+ process.environment = env
483
+ // npm 输出可能超过管道容量,写临时文件以免等待退出时死锁。
484
+ let output = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
485
+ guard FileManager.default.createFile(atPath: output.path, contents: nil,
486
+ attributes: [.posixPermissions: 0o600]), let handle = try? FileHandle(forWritingTo: output) else {
487
+ showUpdateResult("无法创建更新日志,请检查临时目录权限。")
488
+ return
489
+ }
490
+ process.standardOutput = handle
491
+ process.standardError = handle
492
+ process.terminationHandler = { [weak self] process in
493
+ try? handle.close()
494
+ let data = (try? Data(contentsOf: output)) ?? Data()
495
+ try? FileManager.default.removeItem(at: output)
496
+ let message = String(decoding: data.suffix(4096), as: UTF8.self)
497
+ Task { @MainActor in
498
+ guard let self else { return }
499
+ self.updater = nil
500
+ self.showUpdateResult(process.terminationStatus == 0
501
+ ? message : "更新失败,请检查网络或安装目录权限。\n" + message)
502
+ }
503
+ }
504
+ updater = process
505
+ do { try process.run() }
506
+ catch {
507
+ updater = nil
508
+ try? handle.close()
509
+ try? FileManager.default.removeItem(at: output)
510
+ showUpdateResult("无法启动更新,请重新运行 easy-claude show。")
511
+ }
512
+ }
513
+ func showUpdateResult(_ message: String) {
514
+ let alert = NSAlert()
515
+ alert.messageText = "更新版本"
516
+ alert.informativeText = message
517
+ alert.addButton(withTitle: "好")
518
+ NSApp.activate(ignoringOtherApps: true)
519
+ alert.runModal()
520
+ }
471
521
  @objc func quit() { NSApp.terminate(nil) }
472
522
  func applicationWillTerminate(_ notification: Notification) {
473
523
  timer?.invalidate()
@@ -5,7 +5,7 @@
5
5
  <key>CFBundleIdentifier</key><string>com.unionschool.easy-claude.overlay</string>
6
6
  <key>CFBundleName</key><string>Easy Claude Overlay</string>
7
7
  <key>CFBundlePackageType</key><string>APPL</string>
8
- <key>CFBundleShortVersionString</key><string>0.2.3</string>
8
+ <key>CFBundleShortVersionString</key><string>0.2.5</string>
9
9
  <key>LSMinimumSystemVersion</key><string>14.0</string>
10
10
  <key>LSUIElement</key><true/>
11
11
  <key>NSHighResolutionCapable</key><true/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-claude",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Claude Code quota rings and transparent world clock for Claude desktop",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,12 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { updatePackage } from './update.js';
3
+
4
+ export async function updateAndShow({ update = updatePackage,
5
+ show = async () => (await import('./overlay.js')).launchOverlay() } = {}) {
6
+ await update('easy-claude');
7
+ await show();
8
+ }
9
+
10
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
11
+ updateAndShow().catch(error => { console.error(error.message); process.exitCode = 1; });
12
+ }
package/src/update.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { access, realpath } from 'node:fs/promises';
2
+ import { readFileSync } from 'node:fs';
2
3
  import { dirname, basename, join, delimiter } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
- import { spawn } from 'node:child_process';
5
+ import { spawn, execFile } from 'node:child_process';
6
+ import { promisify } from 'node:util';
7
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
5
8
 
6
9
  export function installedPrefix(root, platform = process.platform) {
7
10
  const modules = dirname(root.replace(/[\\/]$/, ''));
@@ -10,6 +13,15 @@ export function installedPrefix(root, platform = process.platform) {
10
13
  return basename(parent) === 'lib' ? dirname(parent) : platform === 'win32' ? parent : null;
11
14
  }
12
15
 
16
+ export function isNewer(latest, current) {
17
+ if (!/^\d+\.\d+\.\d+$/.test(latest) || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(current)) {
18
+ throw new Error('无法识别正式版本号,未执行更新。');
19
+ }
20
+ const a = latest.split('.').map(Number), b = current.split('-')[0].split('.').map(Number);
21
+ for (let i = 0; i < 3; i++) { if (a[i] !== b[i]) return a[i] > b[i]; }
22
+ return current.includes('-');
23
+ }
24
+
13
25
  async function findNpmCli() {
14
26
  const directories = [dirname(process.execPath), ...(process.env.PATH ?? '').split(delimiter)];
15
27
  for (const directory of directories.filter(Boolean)) {
@@ -22,6 +34,14 @@ async function findNpmCli() {
22
34
  throw new Error('未找到 npm,请先安装 Node.js/npm,再使用 npm i -g 更新。');
23
35
  }
24
36
 
37
+ async function readLatest(npmCli, name) {
38
+ try {
39
+ const { stdout } = await promisify(execFile)(process.execPath, [npmCli, 'view', name, 'dist-tags.latest',
40
+ '--json', '--prefer-online', '--registry=https://registry.npmjs.org'], { timeout: 30000, maxBuffer: 4096 });
41
+ return JSON.parse(stdout);
42
+ } catch { throw new Error('无法在线检查 npm 最新版本,请检查网络后重试。'); }
43
+ }
44
+
25
45
  function runNpm(command, args) {
26
46
  return new Promise((resolve, reject) => {
27
47
  const child = spawn(command, args, { stdio: 'inherit', shell: false });
@@ -34,12 +54,19 @@ function runNpm(command, args) {
34
54
  }
35
55
 
36
56
  export async function updatePackage(name, { root = fileURLToPath(new URL('../', import.meta.url)),
37
- getNpmCli = findNpmCli, run = runNpm, platform = process.platform } = {}) {
57
+ getNpmCli = findNpmCli, getLatest = readLatest, currentVersion = version,
58
+ run = runNpm, platform = process.platform } = {}) {
38
59
  if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
39
60
  const npmCli = await getNpmCli();
61
+ const latest = await getLatest(npmCli, name);
62
+ if (!isNewer(latest, currentVersion)) {
63
+ console.log(`${name} 当前 ${currentVersion},npm 最新 ${latest},无需更新。`);
64
+ return;
65
+ }
40
66
  const prefix = installedPrefix(root, platform);
67
+ // 先在线检查再锁定版本,避免安装阶段复用旧 latest 缓存而降级。
41
68
  const args = [npmCli, 'install', '--global', ...(prefix ? ['--prefix', prefix] : []),
42
- '--registry=https://registry.npmjs.org', `${name}@latest`];
69
+ '--prefer-online', '--registry=https://registry.npmjs.org', `${name}@${latest}`];
43
70
  await run(process.execPath, args);
44
- console.log(`${name} 已更新;运行 ${name} show 自动重启浮窗。`);
71
+ console.log(`${name} 已更新到 ${latest};运行 ${name} show 自动重启浮窗。`);
45
72
  }