easy-claude 0.2.4 → 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 +10 -0
- package/README.md +8 -14
- package/bin/easy-claude.js +2 -2
- package/native/Overlay.swift +112 -0
- package/native/build/EasyClaudeOverlay.app/Contents/Info.plist +1 -1
- package/native/build/EasyClaudeOverlay.app/Contents/MacOS/EasyClaudeOverlay +0 -0
- package/package.json +1 -1
- package/src/check-update.js +3 -0
- package/src/overlay-update.js +12 -0
- package/src/update.js +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.2.6(2026-10-19)
|
|
4
|
+
|
|
5
|
+
- 菜单显示“更新版本·当前版本号”,每天检查一次官方 npm,有新版时右侧显示绿色圆点;检查记录跨重启保存,只提示、不自动安装。
|
|
6
|
+
- 命令行 update 成功后自动重开浮窗,与菜单更新一致。
|
|
7
|
+
- 新增大写 -V 显示版本号,保留 -v 与 --version。
|
|
8
|
+
|
|
9
|
+
## v0.2.5(2026-10-19)
|
|
10
|
+
|
|
11
|
+
- 菜单新增“更新版本”:后台复用 update,防重复点击;成功后自动重开浮窗,失败保留当前浮窗并提示,设置保持不变。
|
|
12
|
+
|
|
3
13
|
## 0.2.4 — 2026-10-19
|
|
4
14
|
|
|
5
15
|
### 修复
|
package/README.md
CHANGED
|
@@ -4,21 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.2.
|
|
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
|
-
|
|
14
|
-
- **命令更新**:新增 `easy-claude update`,从官方 npm 更新当前全局安装。
|
|
15
|
-
- **自动重开**:`easy-claude show` 会先退出自身旧浮窗,再打开新版;设置保持不变。
|
|
16
|
-
|
|
17
|
-
- 统一时间颜色:所选城市当地时间 **00:00–09:00 红色、09:00–18:00 绿色、18:00–24:00 橙色**,绿色时段延长到18:00。
|
|
18
|
-
- 09:00转绿、18:00转橙、午夜转红,自动适应目标时区夏令时。
|
|
19
|
-
- 保留已有时区、城市、位置和显示选择;额度圆环颜色阈值保持原有规则。
|
|
20
|
-
|
|
21
|
-
完整版本说明见 [CHANGELOG](CHANGELOG.md)。
|
|
13
|
+
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
22
14
|
|
|
23
15
|
## 安装与使用
|
|
24
16
|
|
|
@@ -78,4 +70,6 @@ npm run build:overlay
|
|
|
78
70
|
周倒计时只显示最大单位,例如“6天后 25日 06:17 重置”,不足一天按小时、不足一小时按分钟。5小时窗口保留时分组合,例如“3小时2分后 07:59 重置”,没有小时则“22分后 07:59 重置”,省略为零的单位。绝对重置时刻使用电脑本地时区;周含日,5小时不含日期。
|
|
79
71
|
|
|
80
72
|
|
|
81
|
-
命令更新:`easy-claude update
|
|
73
|
+
命令更新:`easy-claude update`,成功后会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
|
|
74
|
+
|
|
75
|
+
菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
|
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,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
|
|
@@ -225,6 +230,10 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
225
230
|
var status: NSStatusItem?
|
|
226
231
|
var timer: Timer?
|
|
227
232
|
var query: Process?
|
|
233
|
+
var updater: Process?
|
|
234
|
+
var versionCheck: Process?
|
|
235
|
+
var updateAvailable = false
|
|
236
|
+
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "未知"
|
|
228
237
|
var snapshot: Snapshot?
|
|
229
238
|
var error: String?
|
|
230
239
|
var lastAttempt = Date.distantPast
|
|
@@ -297,6 +306,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
297
306
|
}
|
|
298
307
|
@objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
|
|
299
308
|
@objc func tick() {
|
|
309
|
+
checkVersionIfNeeded()
|
|
300
310
|
guard let rect = targetWindow() else { hide(); lastRect = nil; return }
|
|
301
311
|
lastRect = rect
|
|
302
312
|
if clockEnabled {
|
|
@@ -410,6 +420,19 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
410
420
|
zoneItem.submenu = zones
|
|
411
421
|
menu.addItem(zoneItem)
|
|
412
422
|
menu.addItem(.separator())
|
|
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)
|
|
413
436
|
menu.addItem(item("退出浮窗", #selector(quit)))
|
|
414
437
|
return menu
|
|
415
438
|
}
|
|
@@ -468,10 +491,95 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
468
491
|
UserDefaults.standard.removeObject(forKey: "bottomInset")
|
|
469
492
|
tick()
|
|
470
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
|
+
}
|
|
530
|
+
@objc func updateVersion() {
|
|
531
|
+
guard updater == nil else { return }
|
|
532
|
+
let cli = URL(fileURLWithPath: script).deletingLastPathComponent()
|
|
533
|
+
.appendingPathComponent("overlay-update.js")
|
|
534
|
+
let process = Process()
|
|
535
|
+
process.executableURL = URL(fileURLWithPath: node)
|
|
536
|
+
process.arguments = [cli.path]
|
|
537
|
+
var env = ProcessInfo.processInfo.environment
|
|
538
|
+
env["PATH"] = searchPath
|
|
539
|
+
process.environment = env
|
|
540
|
+
// npm 输出可能超过管道容量,写临时文件以免等待退出时死锁。
|
|
541
|
+
let output = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
|
542
|
+
guard FileManager.default.createFile(atPath: output.path, contents: nil,
|
|
543
|
+
attributes: [.posixPermissions: 0o600]), let handle = try? FileHandle(forWritingTo: output) else {
|
|
544
|
+
showUpdateResult("无法创建更新日志,请检查临时目录权限。")
|
|
545
|
+
return
|
|
546
|
+
}
|
|
547
|
+
process.standardOutput = handle
|
|
548
|
+
process.standardError = handle
|
|
549
|
+
process.terminationHandler = { [weak self] process in
|
|
550
|
+
try? handle.close()
|
|
551
|
+
let data = (try? Data(contentsOf: output)) ?? Data()
|
|
552
|
+
try? FileManager.default.removeItem(at: output)
|
|
553
|
+
let message = String(decoding: data.suffix(4096), as: UTF8.self)
|
|
554
|
+
Task { @MainActor in
|
|
555
|
+
guard let self else { return }
|
|
556
|
+
self.updater = nil
|
|
557
|
+
self.showUpdateResult(process.terminationStatus == 0
|
|
558
|
+
? message : "更新失败,请检查网络或安装目录权限。\n" + message)
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
updater = process
|
|
562
|
+
do { try process.run() }
|
|
563
|
+
catch {
|
|
564
|
+
updater = nil
|
|
565
|
+
try? handle.close()
|
|
566
|
+
try? FileManager.default.removeItem(at: output)
|
|
567
|
+
showUpdateResult("无法启动更新,请重新运行 easy-claude show。")
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
func showUpdateResult(_ message: String) {
|
|
571
|
+
let alert = NSAlert()
|
|
572
|
+
alert.messageText = "更新版本"
|
|
573
|
+
alert.informativeText = message
|
|
574
|
+
alert.addButton(withTitle: "好")
|
|
575
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
576
|
+
alert.runModal()
|
|
577
|
+
}
|
|
471
578
|
@objc func quit() { NSApp.terminate(nil) }
|
|
472
579
|
func applicationWillTerminate(_ notification: Notification) {
|
|
473
580
|
timer?.invalidate()
|
|
474
581
|
query?.terminate()
|
|
582
|
+
versionCheck?.terminate()
|
|
475
583
|
NSWorkspace.shared.notificationCenter.removeObserver(self)
|
|
476
584
|
}
|
|
477
585
|
}
|
|
@@ -480,6 +588,10 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
480
588
|
struct Main {
|
|
481
589
|
@MainActor static func main() {
|
|
482
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))
|
|
483
595
|
precondition(ClockCity.presets.map(\.name) == ["硅谷", "洛杉矶", "西雅图", "华盛顿", "哥伦布", "新加坡", "上海"])
|
|
484
596
|
precondition(ClockCity.presets.allSatisfy { TimeZone(identifier: $0.identifier) != nil })
|
|
485
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.
|
|
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/>
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -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
|
@@ -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}
|
|
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
|
}
|