easy-claude 0.2.5 → 0.2.6

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,11 @@
1
1
  # 更新记录
2
2
 
3
+ ## v0.2.6(2026-10-19)
4
+
5
+ - 菜单显示“更新版本·当前版本号”,每天检查一次官方 npm,有新版时右侧显示绿色圆点;检查记录跨重启保存,只提示、不自动安装。
6
+ - 命令行 update 成功后自动重开浮窗,与菜单更新一致。
7
+ - 新增大写 -V 显示版本号,保留 -v 与 --version。
8
+
3
9
  ## v0.2.5(2026-10-19)
4
10
 
5
11
  - 菜单新增“更新版本”:后台复用 update,防重复点击;成功后自动重开浮窗,失败保留当前浮窗并提示,设置保持不变。
package/README.md CHANGED
@@ -4,10 +4,11 @@
4
4
 
5
5
  需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
6
6
 
7
- ## v0.2.5 更新说明
7
+ ## v0.2.6 更新说明
8
8
 
9
- - 菜单新增“更新版本”,后台检查并安装最新正式版,更新期间防止重复点击。
10
- - 更新成功后自动重开新版浮窗,保留时区、城市、位置和显示选择;失败时保留当前浮窗并提示原因。
9
+ - 菜单显示“更新版本·0.2.6”,每24小时检查一次官方 npm,有新版本时右侧显示绿色圆点;重启后保留检查记录,只提示、不自动安装。
10
+ - 命令行 `easy-claude update` 成功后自动重开浮窗,与菜单更新一致,保留已有时区、城市、位置和显示设置。
11
+ - 新增 `easy-claude -V` 显示版本号,兼容 `-v`、`--version`。
11
12
 
12
13
  历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
13
14
 
@@ -69,6 +70,6 @@ npm run build:overlay
69
70
  周倒计时只显示最大单位,例如“6天后 25日 06:17 重置”,不足一天按小时、不足一小时按分钟。5小时窗口保留时分组合,例如“3小时2分后 07:59 重置”,没有小时则“22分后 07:59 重置”,省略为零的单位。绝对重置时刻使用电脑本地时区;周含日,5小时不含日期。
70
71
 
71
72
 
72
- 命令更新:`easy-claude update`,更新完成后运行 `easy-claude show`,会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
73
+ 命令更新:`easy-claude update`,成功后会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
73
74
 
74
75
  菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
@@ -6,13 +6,13 @@ import { readUsage, formatUsage } from '../src/usage.js';
6
6
  const args = process.argv.slice(2);
7
7
  if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
8
8
  console.log('用法:easy-claude [usage|show|overlay|update]\n显示已登录 Claude 账号的剩余百分比和重置时间。需要 Claude Code 订阅登录。');
9
- } else if (args.length === 1 && ['--version', '-v'].includes(args[0])) {
9
+ } else if (args.length === 1 && ['--version', '-v', '-V'].includes(args[0])) {
10
10
  console.log(version);
11
11
  } else if (args.length === 1 && ['show', 'overlay'].includes(args[0])) {
12
12
  try { const { launchOverlay } = await import('../src/overlay.js'); await launchOverlay(); }
13
13
  catch (error) { console.error(`easy-claude: ${error.message}`); process.exitCode = 1; }
14
14
  } else if (args.length === 1 && args[0] === 'update') {
15
- try { const { updatePackage } = await import('../src/update.js'); await updatePackage('easy-claude'); }
15
+ try { const { updateAndShow } = await import('../src/overlay-update.js'); await updateAndShow(); }
16
16
  catch (error) { console.error(`easy-claude: ${error.message}`); process.exitCode = 1; }
17
17
  } else if (args.length === 0 || (args.length === 1 && args[0] === 'usage')) {
18
18
  try { console.log(formatUsage(await readUsage())); }
@@ -153,6 +153,11 @@ struct ClockCity {
153
153
  ]
154
154
  }
155
155
 
156
+ func versionCheckDue(lastAttempt: Double, checkedVersion: String?, currentVersion: String,
157
+ now: Double = Date().timeIntervalSince1970) -> Bool {
158
+ checkedVersion != currentVersion || now - lastAttempt >= 86400
159
+ }
160
+
156
161
  func resetDescription(_ resetsAt: Double?, weekly: Bool, now: Date = Date(), zone: TimeZone = .current) -> String {
157
162
  guard let resetsAt, resetsAt.isFinite, abs(resetsAt) < 8.64e12 else { return "重置时间未知" }
158
163
  let remaining = resetsAt - now.timeIntervalSince1970
@@ -226,6 +231,9 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
226
231
  var timer: Timer?
227
232
  var query: Process?
228
233
  var updater: Process?
234
+ var versionCheck: Process?
235
+ var updateAvailable = false
236
+ let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "未知"
229
237
  var snapshot: Snapshot?
230
238
  var error: String?
231
239
  var lastAttempt = Date.distantPast
@@ -298,6 +306,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
298
306
  }
299
307
  @objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
300
308
  @objc func tick() {
309
+ checkVersionIfNeeded()
301
310
  guard let rect = targetWindow() else { hide(); lastRect = nil; return }
302
311
  lastRect = rect
303
312
  if clockEnabled {
@@ -411,7 +420,19 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
411
420
  zoneItem.submenu = zones
412
421
  menu.addItem(zoneItem)
413
422
  menu.addItem(.separator())
414
- menu.addItem(item(updater == nil ? "更新版本" : "正在更新…", updater == nil ? #selector(updateVersion) : nil))
423
+ let updateItem = item(updater == nil ? "更新版本·\(appVersion)" : "正在更新…·\(appVersion)",
424
+ updater == nil ? #selector(updateVersion) : nil)
425
+ if updateAvailable {
426
+ let title = NSMutableAttributedString(string: updateItem.title + "\t●")
427
+ let style = NSMutableParagraphStyle()
428
+ style.tabStops = [NSTextTab(textAlignment: .right, location: 230)]
429
+ title.addAttribute(.paragraphStyle, value: style, range: NSRange(location: 0, length: title.length))
430
+ title.addAttribute(.foregroundColor, value: NSColor.systemGreen,
431
+ range: NSRange(location: title.length - 1, length: 1))
432
+ updateItem.attributedTitle = title
433
+ updateItem.setAccessibilityHelp("有新版本可更新")
434
+ }
435
+ menu.addItem(updateItem)
415
436
  menu.addItem(item("退出浮窗", #selector(quit)))
416
437
  return menu
417
438
  }
@@ -470,6 +491,42 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
470
491
  UserDefaults.standard.removeObject(forKey: "bottomInset")
471
492
  tick()
472
493
  }
494
+ func checkVersionIfNeeded() {
495
+ let prefs = UserDefaults.standard
496
+ updateAvailable = prefs.string(forKey: "updateCheckedVersion") == appVersion
497
+ && prefs.bool(forKey: "updateAvailable")
498
+ let last = prefs.double(forKey: "updateLastAttempt")
499
+ guard versionCheck == nil, !script.isEmpty,
500
+ versionCheckDue(lastAttempt: last, checkedVersion: prefs.string(forKey: "updateCheckedVersion"),
501
+ currentVersion: appVersion) else { return }
502
+ prefs.set(appVersion, forKey: "updateCheckedVersion")
503
+ prefs.set(Date().timeIntervalSince1970, forKey: "updateLastAttempt")
504
+ prefs.set(false, forKey: "updateAvailable")
505
+ updateAvailable = false
506
+ let process = Process(), pipe = Pipe()
507
+ process.executableURL = URL(fileURLWithPath: node)
508
+ process.arguments = [URL(fileURLWithPath: script).deletingLastPathComponent()
509
+ .appendingPathComponent("check-update.js").path]
510
+ var env = ProcessInfo.processInfo.environment
511
+ env["PATH"] = searchPath
512
+ process.environment = env
513
+ process.standardOutput = pipe
514
+ process.standardError = FileHandle.nullDevice
515
+ process.terminationHandler = { [weak self] process in
516
+ let data = pipe.fileHandleForReading.readDataToEndOfFile()
517
+ let value = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
518
+ let available = process.terminationStatus == 0 && value?["available"] as? Bool == true
519
+ Task { @MainActor in
520
+ guard let self else { return }
521
+ self.versionCheck = nil
522
+ self.updateAvailable = available
523
+ UserDefaults.standard.set(available, forKey: "updateAvailable")
524
+ }
525
+ }
526
+ versionCheck = process
527
+ do { try process.run() }
528
+ catch { versionCheck = nil }
529
+ }
473
530
  @objc func updateVersion() {
474
531
  guard updater == nil else { return }
475
532
  let cli = URL(fileURLWithPath: script).deletingLastPathComponent()
@@ -522,6 +579,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
522
579
  func applicationWillTerminate(_ notification: Notification) {
523
580
  timer?.invalidate()
524
581
  query?.terminate()
582
+ versionCheck?.terminate()
525
583
  NSWorkspace.shared.notificationCenter.removeObserver(self)
526
584
  }
527
585
  }
@@ -530,6 +588,10 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
530
588
  struct Main {
531
589
  @MainActor static func main() {
532
590
  if CommandLine.arguments.contains("--self-test") {
591
+ precondition(!versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.0", now: 86499))
592
+ precondition(versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.0", now: 86500))
593
+ precondition(versionCheckDue(lastAttempt: 100, checkedVersion: nil, currentVersion: "1.0.0", now: 100))
594
+ precondition(versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.1", now: 100))
533
595
  precondition(ClockCity.presets.map(\.name) == ["硅谷", "洛杉矶", "西雅图", "华盛顿", "哥伦布", "新加坡", "上海"])
534
596
  precondition(ClockCity.presets.allSatisfy { TimeZone(identifier: $0.identifier) != nil })
535
597
  let countdownStart = ISO8601DateFormatter().date(from: "2026-10-15T04:57:00Z")!
@@ -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.5</string>
8
+ <key>CFBundleShortVersionString</key><string>0.2.6</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.5",
3
+ "version": "0.2.6",
4
4
  "description": "Claude Code quota rings and transparent world clock for Claude desktop",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,3 @@
1
+ import { checkUpdate } from './update.js';
2
+ try { console.log(JSON.stringify(await checkUpdate('easy-claude'))); }
3
+ catch { process.exitCode = 1; }
package/src/update.js CHANGED
@@ -34,7 +34,7 @@ async function findNpmCli() {
34
34
  throw new Error('未找到 npm,请先安装 Node.js/npm,再使用 npm i -g 更新。');
35
35
  }
36
36
 
37
- async function readLatest(npmCli, name) {
37
+ export async function readLatest(npmCli, name) {
38
38
  try {
39
39
  const { stdout } = await promisify(execFile)(process.execPath, [npmCli, 'view', name, 'dist-tags.latest',
40
40
  '--json', '--prefer-online', '--registry=https://registry.npmjs.org'], { timeout: 30000, maxBuffer: 4096 });
@@ -68,5 +68,12 @@ export async function updatePackage(name, { root = fileURLToPath(new URL('../',
68
68
  const args = [npmCli, 'install', '--global', ...(prefix ? ['--prefix', prefix] : []),
69
69
  '--prefer-online', '--registry=https://registry.npmjs.org', `${name}@${latest}`];
70
70
  await run(process.execPath, args);
71
- console.log(`${name} 已更新到 ${latest};运行 ${name} show 自动重启浮窗。`);
71
+ console.log(`${name} 已更新到 ${latest}。`);
72
+ }
73
+
74
+ export async function checkUpdate(name, { getNpmCli = findNpmCli, getLatest = readLatest,
75
+ currentVersion = version } = {}) {
76
+ if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
77
+ const latest = await getLatest(await getNpmCli(), name);
78
+ return { latest, available: isNewer(latest, currentVersion) };
72
79
  }