easy-claude 0.2.5 → 0.2.7
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 +16 -0
- package/README.md +12 -4
- package/bin/easy-claude.js +2 -2
- package/native/Overlay.swift +149 -22
- package/native/build/EasyClaudeOverlay.app/Contents/Info.plist +1 -1
- package/native/build/EasyClaudeOverlay.app/Contents/MacOS/EasyClaudeOverlay +0 -0
- package/package.json +3 -2
- package/src/check-update.js +3 -0
- package/src/overlay-update.js +5 -3
- package/src/update-lock.js +22 -0
- package/src/update.js +16 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.2.7(2026-10-21)
|
|
4
|
+
|
|
5
|
+
- 修复旧浮窗退出后日志清理失效;检查失败保留上次成功的新版提示并显示检查失败状态。
|
|
6
|
+
|
|
7
|
+
- 新增菜单“自动更新”开关,默认关闭并保存选择;开启后每日检查到新版自动安装并重开,失败只在菜单提示。更新锁防止同一安装前缀的多个Easy更新进程并发安装。
|
|
8
|
+
|
|
9
|
+
- 额度菜单重置时间跟随系统12/24小时制及AM/PM显示,保持原时区、日期和倒计时规则。
|
|
10
|
+
|
|
11
|
+
- 更新前在线判断版本,已最新时提示“已经是最新版本”,不安装也不重开;有新版并安装成功才自动重开。
|
|
12
|
+
|
|
13
|
+
## v0.2.6(2026-10-19)
|
|
14
|
+
|
|
15
|
+
- 菜单显示“更新版本·当前版本号”,每天检查一次官方 npm,有新版时右侧显示绿色圆点;检查记录跨重启保存,只提示、不自动安装。
|
|
16
|
+
- 命令行 update 成功后自动重开浮窗,与菜单更新一致。
|
|
17
|
+
- 新增大写 -V 显示版本号,保留 -v 与 --version。
|
|
18
|
+
|
|
3
19
|
## v0.2.5(2026-10-19)
|
|
4
20
|
|
|
5
21
|
- 菜单新增“更新版本”:后台复用 update,防重复点击;成功后自动重开浮窗,失败保留当前浮窗并提示,设置保持不变。
|
package/README.md
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.2.
|
|
7
|
+
## v0.2.7 更新说明
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
9
|
+
- 新增“自动更新”开关,默认关闭;开启后每天检查,有新版才安装并自动重开,保留设置。
|
|
10
|
+
- 已是最新版本时仅提示,不重复安装或重开;同一安装目录的更新互斥执行。
|
|
11
|
+
- 额度菜单重置时间跟随系统12/24小时制及AM/PM。
|
|
12
|
+
- 修复更新重开后临时日志残留;检查失败保留已知新版绿点并显示失败提示。
|
|
11
13
|
|
|
12
14
|
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
13
15
|
|
|
@@ -69,6 +71,12 @@ npm run build:overlay
|
|
|
69
71
|
周倒计时只显示最大单位,例如“6天后 25日 06:17 重置”,不足一天按小时、不足一小时按分钟。5小时窗口保留时分组合,例如“3小时2分后 07:59 重置”,没有小时则“22分后 07:59 重置”,省略为零的单位。绝对重置时刻使用电脑本地时区;周含日,5小时不含日期。
|
|
70
72
|
|
|
71
73
|
|
|
72
|
-
命令更新:`easy-claude update
|
|
74
|
+
命令更新:`easy-claude update`,成功后会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
|
|
73
75
|
|
|
74
76
|
菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
|
|
77
|
+
|
|
78
|
+
更新前会在线核对版本;已经是最新版本时只提示,不重复安装或重开浮窗。有更高正式版本并安装成功后,才自动重开。
|
|
79
|
+
|
|
80
|
+
额度菜单的重置时刻跟随系统的12/24小时制和AM/PM格式,时区仍使用电脑系统时区。
|
|
81
|
+
|
|
82
|
+
菜单“自动更新”默认关闭,开启后在浮窗运行期间每天检查一次,有新正式版本时自动安装并重开,保留设置;关闭后仍每天检查并显示新版提示,但不自动安装。开启时如已发现新版,会立即更新。自动更新失败仅在菜单提示,可点击“更新版本”查看原因或重试。
|
package/bin/easy-claude.js
CHANGED
|
@@ -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 {
|
|
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())); }
|
package/native/Overlay.swift
CHANGED
|
@@ -153,15 +153,24 @@ struct ClockCity {
|
|
|
153
153
|
]
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
func
|
|
156
|
+
func versionCheckDue(lastAttempt: Double, checkedVersion: String?, currentVersion: String,
|
|
157
|
+
now: Double = Date().timeIntervalSince1970) -> Bool {
|
|
158
|
+
checkedVersion != currentVersion || now - lastAttempt >= 86400
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func resetDescription(_ resetsAt: Double?, weekly: Bool, now: Date = Date(), zone: TimeZone = .current,
|
|
162
|
+
locale: Locale = .autoupdatingCurrent) -> String {
|
|
157
163
|
guard let resetsAt, resetsAt.isFinite, abs(resetsAt) < 8.64e12 else { return "重置时间未知" }
|
|
158
164
|
let remaining = resetsAt - now.timeIntervalSince1970
|
|
159
165
|
guard remaining > 0 else { return "已到重置时间,等待更新" }
|
|
160
166
|
let formatter = DateFormatter()
|
|
161
|
-
formatter.locale =
|
|
167
|
+
formatter.locale = locale
|
|
162
168
|
formatter.timeZone = zone
|
|
163
|
-
formatter.
|
|
164
|
-
let
|
|
169
|
+
formatter.setLocalizedDateFormatFromTemplate("jm")
|
|
170
|
+
let date = Date(timeIntervalSince1970: resetsAt)
|
|
171
|
+
let clock = formatter.string(from: date)
|
|
172
|
+
formatter.dateFormat = "d'日'"
|
|
173
|
+
let time = weekly ? "\(formatter.string(from: date)) \(clock)" : clock
|
|
165
174
|
let duration: String
|
|
166
175
|
if weekly {
|
|
167
176
|
if remaining >= 86400 { duration = "\(Int(remaining / 86400))天" }
|
|
@@ -226,6 +235,11 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
226
235
|
var timer: Timer?
|
|
227
236
|
var query: Process?
|
|
228
237
|
var updater: Process?
|
|
238
|
+
var versionCheck: Process?
|
|
239
|
+
var updateAvailable = false
|
|
240
|
+
var automaticUpdateError: String?
|
|
241
|
+
var versionCheckError: String?
|
|
242
|
+
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "未知"
|
|
229
243
|
var snapshot: Snapshot?
|
|
230
244
|
var error: String?
|
|
231
245
|
var lastAttempt = Date.distantPast
|
|
@@ -298,6 +312,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
298
312
|
}
|
|
299
313
|
@objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
|
|
300
314
|
@objc func tick() {
|
|
315
|
+
checkVersionIfNeeded()
|
|
301
316
|
guard let rect = targetWindow() else { hide(); lastRect = nil; return }
|
|
302
317
|
lastRect = rect
|
|
303
318
|
if clockEnabled {
|
|
@@ -411,7 +426,24 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
411
426
|
zoneItem.submenu = zones
|
|
412
427
|
menu.addItem(zoneItem)
|
|
413
428
|
menu.addItem(.separator())
|
|
414
|
-
|
|
429
|
+
let updateItem = item(updater == nil ? "更新版本·\(appVersion)" : "正在更新…·\(appVersion)",
|
|
430
|
+
updater == nil ? #selector(updateVersion) : nil)
|
|
431
|
+
if updateAvailable {
|
|
432
|
+
let title = NSMutableAttributedString(string: updateItem.title + "\t●")
|
|
433
|
+
let style = NSMutableParagraphStyle()
|
|
434
|
+
style.tabStops = [NSTextTab(textAlignment: .right, location: 230)]
|
|
435
|
+
title.addAttribute(.paragraphStyle, value: style, range: NSRange(location: 0, length: title.length))
|
|
436
|
+
title.addAttribute(.foregroundColor, value: NSColor.systemGreen,
|
|
437
|
+
range: NSRange(location: title.length - 1, length: 1))
|
|
438
|
+
updateItem.attributedTitle = title
|
|
439
|
+
updateItem.setAccessibilityHelp("有新版本可更新")
|
|
440
|
+
}
|
|
441
|
+
menu.addItem(updateItem)
|
|
442
|
+
let automatic = item("自动更新", #selector(toggleAutomaticUpdates))
|
|
443
|
+
automatic.state = UserDefaults.standard.bool(forKey: "automaticUpdatesEnabled") ? .on : .off
|
|
444
|
+
menu.addItem(automatic)
|
|
445
|
+
if let automaticUpdateError { menu.addItem(item(automaticUpdateError, nil)) }
|
|
446
|
+
if let versionCheckError { menu.addItem(item(versionCheckError, nil)) }
|
|
415
447
|
menu.addItem(item("退出浮窗", #selector(quit)))
|
|
416
448
|
return menu
|
|
417
449
|
}
|
|
@@ -470,8 +502,63 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
470
502
|
UserDefaults.standard.removeObject(forKey: "bottomInset")
|
|
471
503
|
tick()
|
|
472
504
|
}
|
|
473
|
-
|
|
505
|
+
func checkVersionIfNeeded() {
|
|
506
|
+
let prefs = UserDefaults.standard
|
|
507
|
+
updateAvailable = prefs.string(forKey: "updateCheckedVersion") == appVersion
|
|
508
|
+
&& prefs.bool(forKey: "updateAvailable")
|
|
509
|
+
let last = prefs.double(forKey: "updateLastAttempt")
|
|
510
|
+
guard versionCheck == nil, !script.isEmpty,
|
|
511
|
+
versionCheckDue(lastAttempt: last, checkedVersion: prefs.string(forKey: "updateCheckedVersion"),
|
|
512
|
+
currentVersion: appVersion) else { return }
|
|
513
|
+
if prefs.string(forKey: "updateCheckedVersion") != appVersion {
|
|
514
|
+
prefs.set(false, forKey: "updateAvailable")
|
|
515
|
+
updateAvailable = false
|
|
516
|
+
}
|
|
517
|
+
prefs.set(appVersion, forKey: "updateCheckedVersion")
|
|
518
|
+
prefs.set(Date().timeIntervalSince1970, forKey: "updateLastAttempt")
|
|
519
|
+
versionCheckError = nil
|
|
520
|
+
let process = Process(), pipe = Pipe()
|
|
521
|
+
process.executableURL = URL(fileURLWithPath: node)
|
|
522
|
+
process.arguments = [URL(fileURLWithPath: script).deletingLastPathComponent()
|
|
523
|
+
.appendingPathComponent("check-update.js").path]
|
|
524
|
+
var env = ProcessInfo.processInfo.environment
|
|
525
|
+
env["PATH"] = searchPath
|
|
526
|
+
process.environment = env
|
|
527
|
+
process.standardOutput = pipe
|
|
528
|
+
process.standardError = FileHandle.nullDevice
|
|
529
|
+
process.terminationHandler = { [weak self] process in
|
|
530
|
+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
531
|
+
let value = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
|
|
532
|
+
let available = process.terminationStatus == 0 ? value?["available"] as? Bool : nil
|
|
533
|
+
Task { @MainActor in
|
|
534
|
+
guard let self else { return }
|
|
535
|
+
self.versionCheck = nil
|
|
536
|
+
guard let available else {
|
|
537
|
+
self.versionCheckError = "版本检查失败,保留上次结果"
|
|
538
|
+
return
|
|
539
|
+
}
|
|
540
|
+
self.versionCheckError = nil
|
|
541
|
+
self.updateAvailable = available
|
|
542
|
+
UserDefaults.standard.set(available, forKey: "updateAvailable")
|
|
543
|
+
if available && UserDefaults.standard.bool(forKey: "automaticUpdatesEnabled") {
|
|
544
|
+
self.startUpdate(automatic: true)
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
versionCheck = process
|
|
549
|
+
do { try process.run() }
|
|
550
|
+
catch { versionCheck = nil; versionCheckError = "版本检查失败,保留上次结果" }
|
|
551
|
+
}
|
|
552
|
+
@objc func toggleAutomaticUpdates() {
|
|
553
|
+
let prefs = UserDefaults.standard
|
|
554
|
+
let enabled = !prefs.bool(forKey: "automaticUpdatesEnabled")
|
|
555
|
+
prefs.set(enabled, forKey: "automaticUpdatesEnabled")
|
|
556
|
+
if enabled && updateAvailable { startUpdate(automatic: true) }
|
|
557
|
+
}
|
|
558
|
+
@objc func updateVersion() { startUpdate(automatic: false) }
|
|
559
|
+
func startUpdate(automatic: Bool) {
|
|
474
560
|
guard updater == nil else { return }
|
|
561
|
+
automaticUpdateError = nil
|
|
475
562
|
let cli = URL(fileURLWithPath: script).deletingLastPathComponent()
|
|
476
563
|
.appendingPathComponent("overlay-update.js")
|
|
477
564
|
let process = Process()
|
|
@@ -483,22 +570,35 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
483
570
|
// npm 输出可能超过管道容量,写临时文件以免等待退出时死锁。
|
|
484
571
|
let output = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
|
485
572
|
guard FileManager.default.createFile(atPath: output.path, contents: nil,
|
|
486
|
-
attributes: [.posixPermissions: 0o600]), let handle = try? FileHandle(
|
|
487
|
-
|
|
573
|
+
attributes: [.posixPermissions: 0o600]), let handle = try? FileHandle(forUpdating: output) else {
|
|
574
|
+
if automatic { automaticUpdateError = "自动更新失败:无法创建更新日志" }
|
|
575
|
+
else { showUpdateResult("无法创建更新日志,请检查临时目录权限。") }
|
|
576
|
+
return
|
|
577
|
+
}
|
|
578
|
+
// 先取消文件名,描述符仍可读写;旧浮窗退出后也不会遗留日志。
|
|
579
|
+
do { try FileManager.default.removeItem(at: output) }
|
|
580
|
+
catch {
|
|
581
|
+
try? handle.close()
|
|
582
|
+
if automatic { automaticUpdateError = "自动更新失败:无法清理临时日志" }
|
|
583
|
+
else { showUpdateResult("无法清理临时更新日志,请检查临时目录权限。") }
|
|
488
584
|
return
|
|
489
585
|
}
|
|
490
586
|
process.standardOutput = handle
|
|
491
587
|
process.standardError = handle
|
|
492
588
|
process.terminationHandler = { [weak self] process in
|
|
589
|
+
try? handle.seek(toOffset: 0)
|
|
590
|
+
let data = (try? handle.readToEnd()) ?? Data()
|
|
493
591
|
try? handle.close()
|
|
494
|
-
let data = (try? Data(contentsOf: output)) ?? Data()
|
|
495
|
-
try? FileManager.default.removeItem(at: output)
|
|
496
592
|
let message = String(decoding: data.suffix(4096), as: UTF8.self)
|
|
497
593
|
Task { @MainActor in
|
|
498
594
|
guard let self else { return }
|
|
499
595
|
self.updater = nil
|
|
500
|
-
|
|
501
|
-
|
|
596
|
+
if automatic {
|
|
597
|
+
if process.terminationStatus != 0 { self.automaticUpdateError = "自动更新失败,请点击更新版本查看原因" }
|
|
598
|
+
} else {
|
|
599
|
+
self.showUpdateResult(process.terminationStatus == 0
|
|
600
|
+
? message : "更新失败,请检查网络或安装目录权限。\n" + message)
|
|
601
|
+
}
|
|
502
602
|
}
|
|
503
603
|
}
|
|
504
604
|
updater = process
|
|
@@ -506,8 +606,8 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
506
606
|
catch {
|
|
507
607
|
updater = nil
|
|
508
608
|
try? handle.close()
|
|
509
|
-
|
|
510
|
-
showUpdateResult("无法启动更新,请重新运行 easy-claude show。")
|
|
609
|
+
if automatic { automaticUpdateError = "自动更新失败:无法启动更新" }
|
|
610
|
+
else { showUpdateResult("无法启动更新,请重新运行 easy-claude show。") }
|
|
511
611
|
}
|
|
512
612
|
}
|
|
513
613
|
func showUpdateResult(_ message: String) {
|
|
@@ -522,6 +622,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
522
622
|
func applicationWillTerminate(_ notification: Notification) {
|
|
523
623
|
timer?.invalidate()
|
|
524
624
|
query?.terminate()
|
|
625
|
+
versionCheck?.terminate()
|
|
525
626
|
NSWorkspace.shared.notificationCenter.removeObserver(self)
|
|
526
627
|
}
|
|
527
628
|
}
|
|
@@ -530,21 +631,47 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
530
631
|
struct Main {
|
|
531
632
|
@MainActor static func main() {
|
|
532
633
|
if CommandLine.arguments.contains("--self-test") {
|
|
634
|
+
let preferenceSuite = "easy-auto-update-self-test-" + UUID().uuidString
|
|
635
|
+
let preferences = UserDefaults(suiteName: preferenceSuite)!
|
|
636
|
+
precondition(!preferences.bool(forKey: "automaticUpdatesEnabled"))
|
|
637
|
+
preferences.set(true, forKey: "automaticUpdatesEnabled")
|
|
638
|
+
precondition(UserDefaults(suiteName: preferenceSuite)!.bool(forKey: "automaticUpdatesEnabled"))
|
|
639
|
+
preferences.set(false, forKey: "automaticUpdatesEnabled")
|
|
640
|
+
precondition(!preferences.bool(forKey: "automaticUpdatesEnabled"))
|
|
641
|
+
preferences.removePersistentDomain(forName: preferenceSuite)
|
|
642
|
+
precondition(!versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.0", now: 86499))
|
|
643
|
+
precondition(versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.0", now: 86500))
|
|
644
|
+
precondition(versionCheckDue(lastAttempt: 100, checkedVersion: nil, currentVersion: "1.0.0", now: 100))
|
|
645
|
+
precondition(versionCheckDue(lastAttempt: 100, checkedVersion: "1.0.0", currentVersion: "1.0.1", now: 100))
|
|
533
646
|
precondition(ClockCity.presets.map(\.name) == ["硅谷", "洛杉矶", "西雅图", "华盛顿", "哥伦布", "新加坡", "上海"])
|
|
534
647
|
precondition(ClockCity.presets.allSatisfy { TimeZone(identifier: $0.identifier) != nil })
|
|
535
648
|
let countdownStart = ISO8601DateFormatter().date(from: "2026-10-15T04:57:00Z")!
|
|
536
649
|
let countdownUTC = TimeZone(secondsFromGMT: 0)!
|
|
537
|
-
|
|
650
|
+
let afternoon = ISO8601DateFormatter().date(from: "2026-10-21T14:30:00Z")!
|
|
651
|
+
let morning = ISO8601DateFormatter().date(from: "2026-10-21T02:30:00Z")!
|
|
652
|
+
for weekly in [false, true] {
|
|
653
|
+
let us = resetDescription(afternoon.timeIntervalSince1970, weekly: weekly,
|
|
654
|
+
now: morning, zone: countdownUTC, locale: Locale(identifier: "en_US"))
|
|
655
|
+
precondition(us.contains("2:30") && us.contains("PM") && !us.contains("14:30"))
|
|
656
|
+
precondition(!weekly || us.contains("21日"))
|
|
657
|
+
let gb = resetDescription(afternoon.timeIntervalSince1970, weekly: weekly,
|
|
658
|
+
now: morning, zone: countdownUTC, locale: Locale(identifier: "en_GB"))
|
|
659
|
+
precondition(gb.contains("14:30") && !gb.contains("PM"))
|
|
660
|
+
let am = resetDescription(morning.timeIntervalSince1970, weekly: weekly,
|
|
661
|
+
now: morning.addingTimeInterval(-60), zone: countdownUTC, locale: Locale(identifier: "en_US"))
|
|
662
|
+
precondition(am.contains("2:30") && am.contains("AM"))
|
|
663
|
+
}
|
|
664
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 10920, weekly: false, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "3小时2分后 07:59 重置")
|
|
538
665
|
let weekStart = ISO8601DateFormatter().date(from: "2026-10-14T08:03:00Z")!
|
|
539
|
-
precondition(resetDescription(weekStart.timeIntervalSince1970 + 345360, weekly: true, now: weekStart, zone: countdownUTC) == "3天后 18日 07:59 重置")
|
|
666
|
+
precondition(resetDescription(weekStart.timeIntervalSince1970 + 345360, weekly: true, now: weekStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "3天后 18日 07:59 重置")
|
|
540
667
|
precondition(resetDescription(nil, weekly: true) == "重置时间未知")
|
|
541
668
|
precondition(resetDescription(countdownStart.timeIntervalSince1970, weekly: false, now: countdownStart) == "已到重置时间,等待更新")
|
|
542
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 1, weekly: false, now: countdownStart, zone: countdownUTC) == "1分后 04:57 重置")
|
|
543
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86160, weekly: true, now: countdownStart, zone: countdownUTC) == "23小时后 16日 04:53 重置")
|
|
544
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 120, weekly: true, now: countdownStart, zone: countdownUTC) == "2分钟后 15日 04:59 重置")
|
|
545
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86400, weekly: true, now: countdownStart, zone: countdownUTC) == "1天后 16日 04:57 重置")
|
|
546
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86399, weekly: true, now: countdownStart, zone: countdownUTC) == "23小时后 16日 04:56 重置")
|
|
547
|
-
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 3599, weekly: false, now: countdownStart, zone: countdownUTC) == "1小时后 05:56 重置")
|
|
669
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 1, weekly: false, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "1分后 04:57 重置")
|
|
670
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86160, weekly: true, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "23小时后 16日 04:53 重置")
|
|
671
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 120, weekly: true, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "2分钟后 15日 04:59 重置")
|
|
672
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86400, weekly: true, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "1天后 16日 04:57 重置")
|
|
673
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 86399, weekly: true, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "23小时后 16日 04:56 重置")
|
|
674
|
+
precondition(resetDescription(countdownStart.timeIntervalSince1970 + 3599, weekly: false, now: countdownStart, zone: countdownUTC, locale: Locale(identifier: "en_GB")) == "1小时后 05:56 重置")
|
|
548
675
|
let testRing = RingView()
|
|
549
676
|
testRing.showFiveHourRing = false
|
|
550
677
|
precondition(testRing.displaysWeeklyPercentage)
|
|
@@ -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.
|
|
8
|
+
<key>CFBundleShortVersionString</key><string>0.2.7</string>
|
|
9
9
|
<key>LSMinimumSystemVersion</key><string>14.0</string>
|
|
10
10
|
<key>LSUIElement</key><true/>
|
|
11
11
|
<key>NSHighResolutionCapable</key><true/>
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-claude",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Claude Code quota rings and transparent world clock for Claude desktop",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "node --test",
|
|
23
23
|
"start": "node bin/easy-claude.js",
|
|
24
|
-
"build:overlay": "node scripts/build-overlay.mjs"
|
|
24
|
+
"build:overlay": "node scripts/build-overlay.mjs",
|
|
25
|
+
"test:native": "python3 scripts/test-native-update.py"
|
|
25
26
|
},
|
|
26
27
|
"license": "MIT",
|
|
27
28
|
"author": "UnionSchool",
|
package/src/overlay-update.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import { updatePackage } from './update.js';
|
|
3
|
+
import { withUpdateLock } from './update-lock.js';
|
|
3
4
|
|
|
4
5
|
export async function updateAndShow({ update = updatePackage,
|
|
5
|
-
show = async () => (await import('./overlay.js')).launchOverlay() } = {}) {
|
|
6
|
-
await
|
|
7
|
-
|
|
6
|
+
show = async () => (await import('./overlay.js')).launchOverlay(), lock = withUpdateLock } = {}) {
|
|
7
|
+
await lock(async () => {
|
|
8
|
+
if (await update('easy-claude')) await show();
|
|
9
|
+
});
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mkdir, rmdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { installedPrefix } from './update.js';
|
|
7
|
+
|
|
8
|
+
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
9
|
+
const prefix = installedPrefix(root) ?? root;
|
|
10
|
+
const key = createHash('sha256').update(prefix).digest('hex').slice(0, 24);
|
|
11
|
+
const defaultLock = join(tmpdir(), `easy-tools-update-${key}.lock`);
|
|
12
|
+
|
|
13
|
+
export async function withUpdateLock(action, { lock = defaultLock } = {}) {
|
|
14
|
+
try { await mkdir(lock, { mode: 0o700 }); }
|
|
15
|
+
catch (error) {
|
|
16
|
+
// shortcut: 异常强退可能留下锁;为避免误删在用锁,不自动按时间清除。
|
|
17
|
+
if (error.code === 'EEXIST') throw new Error(`另一个 Easy 工具正在更新。若确认无更新进程,可删除遗留锁目录后重试:${lock}`);
|
|
18
|
+
throw new Error('无法建立更新锁,请检查临时目录权限。');
|
|
19
|
+
}
|
|
20
|
+
try { return await action(); }
|
|
21
|
+
finally { await rmdir(lock); }
|
|
22
|
+
}
|
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 });
|
|
@@ -54,19 +54,30 @@ function runNpm(command, args) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export async function updatePackage(name, { root = fileURLToPath(new URL('../', import.meta.url)),
|
|
57
|
-
getNpmCli = findNpmCli, getLatest = readLatest,
|
|
57
|
+
getNpmCli = findNpmCli, getLatest = readLatest,
|
|
58
|
+
currentVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version,
|
|
58
59
|
run = runNpm, platform = process.platform } = {}) {
|
|
59
60
|
if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
|
|
60
61
|
const npmCli = await getNpmCli();
|
|
61
62
|
const latest = await getLatest(npmCli, name);
|
|
62
63
|
if (!isNewer(latest, currentVersion)) {
|
|
63
|
-
console.log(
|
|
64
|
-
|
|
64
|
+
console.log(currentVersion === latest
|
|
65
|
+
? `${name} 已经是最新版本(${currentVersion})。`
|
|
66
|
+
: `${name} 当前版本 ${currentVersion} 高于 npm 最新版本 ${latest},无需更新。`);
|
|
67
|
+
return false;
|
|
65
68
|
}
|
|
66
69
|
const prefix = installedPrefix(root, platform);
|
|
67
70
|
// 先在线检查再锁定版本,避免安装阶段复用旧 latest 缓存而降级。
|
|
68
71
|
const args = [npmCli, 'install', '--global', ...(prefix ? ['--prefix', prefix] : []),
|
|
69
72
|
'--prefer-online', '--registry=https://registry.npmjs.org', `${name}@${latest}`];
|
|
70
73
|
await run(process.execPath, args);
|
|
71
|
-
console.log(`${name} 已更新到 ${latest}
|
|
74
|
+
console.log(`${name} 已更新到 ${latest}。`);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function checkUpdate(name, { getNpmCli = findNpmCli, getLatest = readLatest,
|
|
79
|
+
currentVersion = version } = {}) {
|
|
80
|
+
if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
|
|
81
|
+
const latest = await getLatest(await getNpmCli(), name);
|
|
82
|
+
return { latest, available: isNewer(latest, currentVersion) };
|
|
72
83
|
}
|