easy-claude 0.2.7 → 0.2.11
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 +15 -5
- package/native/Overlay.swift +184 -8
- package/native/build/EasyClaudeOverlay.app/Contents/Info.plist +1 -1
- package/native/build/EasyClaudeOverlay.app/Contents/MacOS/EasyClaudeOverlay +0 -0
- package/package.json +4 -2
- package/src/overlay-update.js +9 -5
- package/src/update-lock.js +26 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.2.11(2026-10-21)
|
|
4
|
+
|
|
5
|
+
- 新增一次性“额度可用提醒”:同时受5小时和周额度限制时,等待较晚的恢复时间,在线确认全部可用后发送系统通知和提示音,随后自动关闭。
|
|
6
|
+
- 提醒状态跨重启保存;关闭即取消,断网或查询失败继续等待,目标窗口缺失或额度未知时不误报。
|
|
7
|
+
- 更新锁改为系统内核锁,异常强退后自动释放;安装仍在运行时保持排他,旧锁目录无需手动清理。
|
|
8
|
+
|
|
9
|
+
## v0.2.8(2026-10-21)
|
|
10
|
+
|
|
11
|
+
- 当前时间浮窗和城市菜单跟随系统12/24小时制及地区格式,保留所选城市时区;字体自动适应宽度,避免上午/下午标记截断。
|
|
12
|
+
|
|
3
13
|
## v0.2.7(2026-10-21)
|
|
4
14
|
|
|
5
15
|
- 修复旧浮窗退出后日志清理失效;检查失败保留上次成功的新版提示并显示检查失败状态。
|
package/README.md
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.2.
|
|
7
|
+
## v0.2.11 更新说明
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- 修复更新重开后临时日志残留;检查失败保留已知新版绿点并显示失败提示。
|
|
9
|
+
- 新增一次性“额度可用提醒”:同时受5小时和周额度限制时,等待较晚的恢复时间,在线确认全部可用后发送系统通知和提示音,随后自动关闭。
|
|
10
|
+
- 提醒状态跨重启保存;关闭即取消,断网或查询失败继续等待,目标窗口缺失或额度未知时不误报。
|
|
11
|
+
- 更新锁改为系统内核锁,异常强退后自动释放;安装仍在运行时保持排他,旧锁目录无需手动清理。
|
|
13
12
|
|
|
14
13
|
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
15
14
|
|
|
@@ -73,6 +72,7 @@ npm run build:overlay
|
|
|
73
72
|
|
|
74
73
|
命令更新:`easy-claude update`,成功后会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
|
|
75
74
|
|
|
75
|
+
|
|
76
76
|
菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
|
|
77
77
|
|
|
78
78
|
更新前会在线核对版本;已经是最新版本时只提示,不重复安装或重开浮窗。有更高正式版本并安装成功后,才自动重开。
|
|
@@ -80,3 +80,13 @@ npm run build:overlay
|
|
|
80
80
|
额度菜单的重置时刻跟随系统的12/24小时制和AM/PM格式,时区仍使用电脑系统时区。
|
|
81
81
|
|
|
82
82
|
菜单“自动更新”默认关闭,开启后在浮窗运行期间每天检查一次,有新正式版本时自动安装并重开,保留设置;关闭后仍每天检查并显示新版提示,但不自动安装。开启时如已发现新版,会立即更新。自动更新失败仅在菜单提示,可点击“更新版本”查看原因或重试。
|
|
83
|
+
|
|
84
|
+
更新锁恢复:异常强退后自动释放;安装仍在运行时继续阻止并发更新,安装结束即可重试,无需手动清理旧锁。
|
|
85
|
+
|
|
86
|
+
## 额度可用提醒
|
|
87
|
+
|
|
88
|
+
在菜单栏 EA 或浮窗右键菜单开启“额度可用提醒”。首次开启需允许系统通知。仅在额度耗尽且重置时间有效时启用;当前已可用或数据未知时提示刷新后重试。
|
|
89
|
+
|
|
90
|
+
只有5小时或只有周额度时等待对应恢复;两项都耗尽时等待较晚时间,仍有剩余的窗口不参与等待。到点后约每分钟查询,确认所有已知窗口均有剩余,才发送一次系统通知和提示音,然后自动关闭开关。若等待期间再次耗尽,会继续等到有效恢复。
|
|
91
|
+
|
|
92
|
+
开启状态跨更新/重启保存;关闭可取消。浮窗运行时即使目标应用不在前台也能检查,断网则保留提醒并重试。休眠会延后至唤醒,工具完全退出期间不能提醒,重新启动后补查;系统通知权限、专注模式和声音设置可能影响通知展示或声音。不调用模型、不消耗对话额度。
|
package/native/Overlay.swift
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import AppKit
|
|
2
2
|
import CoreGraphics
|
|
3
|
+
import Darwin
|
|
4
|
+
import UserNotifications
|
|
3
5
|
|
|
4
6
|
struct UsageWindow: Decodable {
|
|
5
7
|
let id: String
|
|
@@ -185,14 +187,23 @@ func resetDescription(_ resetsAt: Double?, weekly: Bool, now: Date = Date(), zon
|
|
|
185
187
|
return "\(duration)后 \(time) 重置"
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
func clockText(at date: Date, zone: TimeZone) -> String {
|
|
190
|
+
func clockText(at date: Date, zone: TimeZone, locale: Locale = .autoupdatingCurrent) -> String {
|
|
189
191
|
let formatter = DateFormatter()
|
|
190
|
-
formatter.locale =
|
|
192
|
+
formatter.locale = locale
|
|
191
193
|
formatter.timeZone = zone
|
|
192
|
-
formatter.
|
|
194
|
+
formatter.setLocalizedDateFormatFromTemplate("jm")
|
|
193
195
|
return formatter.string(from: date)
|
|
194
196
|
}
|
|
195
197
|
|
|
198
|
+
|
|
199
|
+
@MainActor
|
|
200
|
+
func fittedClockFont(for text: String, width: CGFloat, baseSize: CGFloat) -> NSFont {
|
|
201
|
+
let base = NSFont.monospacedDigitSystemFont(ofSize: baseSize, weight: .medium)
|
|
202
|
+
let measured = max(1, (text as NSString).size(withAttributes: [.font: base]).width)
|
|
203
|
+
let size = min(baseSize, baseSize * max(1, width - 2) / measured)
|
|
204
|
+
return NSFont.monospacedDigitSystemFont(ofSize: size, weight: .medium)
|
|
205
|
+
}
|
|
206
|
+
|
|
196
207
|
func clockState(at date: Date, zone: TimeZone) -> RingState {
|
|
197
208
|
var calendar = Calendar(identifier: .gregorian)
|
|
198
209
|
calendar.timeZone = zone
|
|
@@ -212,7 +223,7 @@ final class ClockView: RingView {
|
|
|
212
223
|
let now = Date()
|
|
213
224
|
let time = clockText(at: now, zone: zone)
|
|
214
225
|
(time as NSString).draw(in: CGRect(x: 0, y: 17, width: bounds.width, height: 25),
|
|
215
|
-
withAttributes: [.font:
|
|
226
|
+
withAttributes: [.font: fittedClockFont(for: time, width: bounds.width, baseSize: 20),
|
|
216
227
|
.foregroundColor: clockState(at: now, zone: zone).color, .paragraphStyle: style])
|
|
217
228
|
let city = cityName
|
|
218
229
|
(city as NSString).draw(in: CGRect(x: 0, y: 1, width: bounds.width, height: 15),
|
|
@@ -221,8 +232,36 @@ final class ClockView: RingView {
|
|
|
221
232
|
}
|
|
222
233
|
}
|
|
223
234
|
|
|
235
|
+
// 只等待耗尽窗口,但确认恢复时必须同时检查所有已知窗口,缺失或未知不能报可用。
|
|
236
|
+
struct AvailabilityReminder: Codable {
|
|
237
|
+
var ids: [String]
|
|
238
|
+
var due: Double
|
|
239
|
+
static func arm(_ windows: [UsageWindow], now: Double) -> Self? {
|
|
240
|
+
guard !windows.isEmpty, windows.allSatisfy({ window in
|
|
241
|
+
guard let remaining = window.remaining, remaining.isFinite, remaining >= 0,
|
|
242
|
+
let reset = window.resetsAt, reset.isFinite, reset > now else { return false }
|
|
243
|
+
return true
|
|
244
|
+
}) else { return nil }
|
|
245
|
+
let blocked = windows.filter { $0.remaining == 0 }
|
|
246
|
+
guard let due = blocked.compactMap(\.resetsAt).max() else { return nil }
|
|
247
|
+
return Self(ids: windows.map(\.id), due: due)
|
|
248
|
+
}
|
|
249
|
+
mutating func recovered(_ windows: [UsageWindow], fetchedAt: Double, restricted: Bool, now: Double) -> Bool {
|
|
250
|
+
guard now >= due, fetchedAt >= due, now - fetchedAt <= 120, !restricted,
|
|
251
|
+
ids.allSatisfy({ id in windows.contains { $0.id == id } }), !windows.isEmpty else { return false }
|
|
252
|
+
let blocked = windows.filter { $0.remaining == 0 }
|
|
253
|
+
if let later = blocked.compactMap(\.resetsAt).filter({ $0.isFinite && $0 > now }).max() { due = later }
|
|
254
|
+
return windows.allSatisfy {
|
|
255
|
+
guard let remaining = $0.remaining, remaining.isFinite, remaining > 0,
|
|
256
|
+
let reset = $0.resetsAt, reset.isFinite, reset > now else { return false }
|
|
257
|
+
return true
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
func reminderWindows(_ windows: [UsageWindow]) -> [UsageWindow] { windows.filter { ["five_hour:primary", "seven_day:primary"].contains($0.id) } }
|
|
262
|
+
|
|
224
263
|
@MainActor
|
|
225
|
-
final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
264
|
+
final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNotificationCenterDelegate {
|
|
226
265
|
let panel = NSPanel(contentRect: CGRect(x: 0, y: 0, width: 32, height: 32),
|
|
227
266
|
styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
|
|
228
267
|
let ring = RingView(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
|
|
@@ -240,6 +279,11 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
240
279
|
var automaticUpdateError: String?
|
|
241
280
|
var versionCheckError: String?
|
|
242
281
|
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "未知"
|
|
282
|
+
var reminder = UserDefaults.standard.data(forKey: "availabilityReminder").flatMap { try? JSONDecoder().decode(AvailabilityReminder.self, from: $0) }
|
|
283
|
+
var reminderSending = false
|
|
284
|
+
var reminderAuthorizing = false
|
|
285
|
+
var reminderGeneration = 0
|
|
286
|
+
var reminderError: String?
|
|
243
287
|
var snapshot: Snapshot?
|
|
244
288
|
var error: String?
|
|
245
289
|
var lastAttempt = Date.distantPast
|
|
@@ -251,6 +295,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
251
295
|
var claudeHome = ""
|
|
252
296
|
|
|
253
297
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
298
|
+
UNUserNotificationCenter.current().delegate = self
|
|
254
299
|
let args = CommandLine.arguments
|
|
255
300
|
guard args.count >= 4 else { NSApp.terminate(nil); return }
|
|
256
301
|
node = args[1]; script = args[2]; searchPath = args[3]
|
|
@@ -313,6 +358,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
313
358
|
@objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
|
|
314
359
|
@objc func tick() {
|
|
315
360
|
checkVersionIfNeeded()
|
|
361
|
+
if let reminder, Date().timeIntervalSince(lastAttempt) >= (Date().timeIntervalSince1970 >= reminder.due ? 60 : 300) { refresh() }
|
|
316
362
|
guard let rect = targetWindow() else { hide(); lastRect = nil; return }
|
|
317
363
|
lastRect = rect
|
|
318
364
|
if clockEnabled {
|
|
@@ -380,6 +426,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
380
426
|
self.snapshot = value; self.error = nil
|
|
381
427
|
} else { self.error = "额度查询失败" }
|
|
382
428
|
} catch { self.error = "无法读取额度响应,请检查 CLI 和网络" }
|
|
429
|
+
self.checkReminder()
|
|
383
430
|
self.updateRing()
|
|
384
431
|
}
|
|
385
432
|
}
|
|
@@ -387,6 +434,77 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
387
434
|
do { try process.run() }
|
|
388
435
|
catch { query = nil; self.error = "无法启动额度查询,请重新运行 easy-claude show"; updateRing() }
|
|
389
436
|
}
|
|
437
|
+
func saveReminder() {
|
|
438
|
+
if let reminder, let data = try? JSONEncoder().encode(reminder) {
|
|
439
|
+
UserDefaults.standard.set(data, forKey: "availabilityReminder")
|
|
440
|
+
} else { UserDefaults.standard.removeObject(forKey: "availabilityReminder") }
|
|
441
|
+
}
|
|
442
|
+
@objc func toggleReminder() {
|
|
443
|
+
guard !reminderAuthorizing else { return }
|
|
444
|
+
reminderGeneration += 1
|
|
445
|
+
reminderError = nil
|
|
446
|
+
if reminder != nil {
|
|
447
|
+
reminder = nil; saveReminder()
|
|
448
|
+
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["quota-available"])
|
|
449
|
+
return
|
|
450
|
+
}
|
|
451
|
+
let now = Date().timeIntervalSince1970
|
|
452
|
+
guard error == nil, let snapshot, now - snapshot.fetchedAt <= 600,
|
|
453
|
+
let candidate = AvailabilityReminder.arm(reminderWindows(snapshot.windows), now: now) else {
|
|
454
|
+
reminderError = "当前额度可用,或缺少有效额度/重置时间;请刷新后重试"
|
|
455
|
+
refresh(); return
|
|
456
|
+
}
|
|
457
|
+
reminderAuthorizing = true
|
|
458
|
+
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { @Sendable [weak self] allowed, _ in
|
|
459
|
+
Task { @MainActor in
|
|
460
|
+
guard let self else { return }
|
|
461
|
+
self.reminderAuthorizing = false
|
|
462
|
+
if allowed { self.reminder = candidate; self.saveReminder() }
|
|
463
|
+
else { self.reminderError = "请在系统设置中允许本工具发送通知,再开启提醒" }
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
func checkReminder() {
|
|
468
|
+
guard !reminderSending, error == nil, let snapshot, var pending = reminder else { return }
|
|
469
|
+
let ready = pending.recovered(reminderWindows(snapshot.windows), fetchedAt: snapshot.fetchedAt,
|
|
470
|
+
restricted: snapshot.restricted, now: Date().timeIntervalSince1970)
|
|
471
|
+
reminder = pending; saveReminder()
|
|
472
|
+
guard ready else { return }
|
|
473
|
+
reminderSending = true
|
|
474
|
+
let generation = reminderGeneration
|
|
475
|
+
UNUserNotificationCenter.current().getNotificationSettings { @Sendable [weak self] settings in
|
|
476
|
+
// 旧SDK的设置对象不是Sendable,只把判断结果送回主线程。
|
|
477
|
+
let allowed = settings.authorizationStatus == .authorized || settings.authorizationStatus == .provisional
|
|
478
|
+
Task { @MainActor in
|
|
479
|
+
guard let self else { return }
|
|
480
|
+
guard generation == self.reminderGeneration, self.reminder != nil else { self.reminderSending = false; return }
|
|
481
|
+
guard allowed else {
|
|
482
|
+
self.reminderSending = false
|
|
483
|
+
self.reminderError = "通知未获允许,提醒已保留;请在系统设置允许通知"
|
|
484
|
+
return
|
|
485
|
+
}
|
|
486
|
+
let content = UNMutableNotificationContent()
|
|
487
|
+
content.title = "Claude 额度已恢复"
|
|
488
|
+
content.body = "已确认当前额度可用,可以继续使用了。"
|
|
489
|
+
content.sound = .default
|
|
490
|
+
UNUserNotificationCenter.current().add(UNNotificationRequest(identifier: "quota-available", content: content, trigger: nil)) { @Sendable [weak self] error in
|
|
491
|
+
let failed = error != nil
|
|
492
|
+
Task { @MainActor in
|
|
493
|
+
guard let self else { return }
|
|
494
|
+
if generation == self.reminderGeneration {
|
|
495
|
+
if !failed { self.reminder = nil; self.reminderError = nil; self.saveReminder() }
|
|
496
|
+
else { self.reminderError = "通知发送失败,提醒已保留,将稍后重试" }
|
|
497
|
+
}
|
|
498
|
+
self.reminderSending = false
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter,
|
|
505
|
+
willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
506
|
+
completionHandler([.banner, .sound, .list])
|
|
507
|
+
}
|
|
390
508
|
func item(_ title: String, _ action: Selector?) -> NSMenuItem {
|
|
391
509
|
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
|
392
510
|
item.target = self
|
|
@@ -409,6 +527,13 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
409
527
|
menu.addItem(option)
|
|
410
528
|
}
|
|
411
529
|
menu.addItem(item(query == nil ? "立即刷新" : "正在刷新…", query == nil ? #selector(refresh) : nil))
|
|
530
|
+
let alarm = item("额度可用提醒", reminderAuthorizing ? nil : #selector(toggleReminder))
|
|
531
|
+
alarm.state = reminder == nil ? .off : .on
|
|
532
|
+
menu.addItem(alarm)
|
|
533
|
+
if let reminder {
|
|
534
|
+
menu.addItem(item("等待额度恢复 · " + resetDescription(reminder.due, weekly: true), nil))
|
|
535
|
+
}
|
|
536
|
+
if let reminderError { menu.addItem(item(reminderError, nil)) }
|
|
412
537
|
menu.addItem(item("恢复默认位置", #selector(resetPosition)))
|
|
413
538
|
menu.addItem(.separator())
|
|
414
539
|
let toggle = item("显示时间", #selector(toggleClock))
|
|
@@ -630,7 +755,48 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
630
755
|
@main
|
|
631
756
|
struct Main {
|
|
632
757
|
@MainActor static func main() {
|
|
758
|
+
if CommandLine.arguments.count >= 2 && CommandLine.arguments[1] == "--with-update-lock" {
|
|
759
|
+
let args = CommandLine.arguments
|
|
760
|
+
guard args.count >= 5 else { exit(72) }
|
|
761
|
+
let fd = Darwin.open(args[2], O_RDWR | O_CREAT | O_NOFOLLOW | O_EXLOCK | O_NONBLOCK, mode_t(0o600))
|
|
762
|
+
guard fd >= 0 else { exit(errno == EWOULDBLOCK || errno == EAGAIN ? 75 : 73) }
|
|
763
|
+
// 更新不读取交互输入;通过stdin把同一个内核锁传给Node和npm子进程。
|
|
764
|
+
guard dup2(fd, STDIN_FILENO) >= 0 else { Darwin.close(fd); exit(73) }
|
|
765
|
+
if fd != STDIN_FILENO { Darwin.close(fd) }
|
|
766
|
+
var argv = Array(args.dropFirst(3)).map { strdup($0) } + [nil]
|
|
767
|
+
argv.withUnsafeMutableBufferPointer { buffer in
|
|
768
|
+
_ = execv(args[3], buffer.baseAddress!)
|
|
769
|
+
}
|
|
770
|
+
for value in argv { free(value) }
|
|
771
|
+
exit(74)
|
|
772
|
+
}
|
|
773
|
+
|
|
633
774
|
if CommandLine.arguments.contains("--self-test") {
|
|
775
|
+
func quota(_ id: String, _ remaining: Double?, _ reset: Double?) -> UsageWindow {
|
|
776
|
+
UsageWindow(id: id, label: id, name: id, remaining: remaining, resetsAt: reset)
|
|
777
|
+
}
|
|
778
|
+
let a = quota("five", 0, 3700), b = quota("week", 0, 7300)
|
|
779
|
+
precondition(AvailabilityReminder.arm([a, b], now: 100)?.due == 7300)
|
|
780
|
+
precondition(AvailabilityReminder.arm([quota("five", 0, 10900), b], now: 100)?.due == 10900)
|
|
781
|
+
precondition(AvailabilityReminder.arm([a, quota("week", 30, 7300)], now: 100)?.due == 3700)
|
|
782
|
+
precondition(AvailabilityReminder.arm([b], now: 100)?.due == 7300)
|
|
783
|
+
precondition(AvailabilityReminder.arm([quota("five", 10, 3700)], now: 100) == nil)
|
|
784
|
+
precondition(AvailabilityReminder.arm([quota("five", nil, 3700)], now: 100) == nil)
|
|
785
|
+
precondition(AvailabilityReminder.arm([quota("five", 0, nil)], now: 100) == nil)
|
|
786
|
+
var alarm = AvailabilityReminder.arm([a, b], now: 100)!
|
|
787
|
+
let restored = try! JSONDecoder().decode(AvailabilityReminder.self, from: JSONEncoder().encode(alarm))
|
|
788
|
+
precondition(restored.ids == alarm.ids && restored.due == 7300)
|
|
789
|
+
let usable = [quota("five", 100, 18000), quota("week", 100, 600000)]
|
|
790
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7300, restricted: false, now: 7299))
|
|
791
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7200, restricted: false, now: 7400))
|
|
792
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7300, restricted: false, now: 7500))
|
|
793
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7400, restricted: true, now: 7400))
|
|
794
|
+
precondition(!alarm.recovered([usable[0]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
795
|
+
precondition(!alarm.recovered([quota("five", nil, 18000), usable[1]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
796
|
+
precondition(alarm.recovered(usable, fetchedAt: 7400, restricted: false, now: 7400))
|
|
797
|
+
precondition(!alarm.recovered([quota("five", 0, 18000), usable[1]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
798
|
+
precondition(alarm.due == 18000)
|
|
799
|
+
print("额度提醒:较晚恢复、单窗口、未知/过期/受限、重启保存及再次耗尽检查通过")
|
|
634
800
|
let preferenceSuite = "easy-auto-update-self-test-" + UUID().uuidString
|
|
635
801
|
let preferences = UserDefaults(suiteName: preferenceSuite)!
|
|
636
802
|
precondition(!preferences.bool(forKey: "automaticUpdatesEnabled"))
|
|
@@ -648,6 +814,16 @@ struct Main {
|
|
|
648
814
|
let countdownStart = ISO8601DateFormatter().date(from: "2026-10-15T04:57:00Z")!
|
|
649
815
|
let countdownUTC = TimeZone(secondsFromGMT: 0)!
|
|
650
816
|
let afternoon = ISO8601DateFormatter().date(from: "2026-10-21T14:30:00Z")!
|
|
817
|
+
for identifier in ["en_US", "en_GB", "zh_CN"] {
|
|
818
|
+
let text = clockText(at: afternoon, zone: countdownUTC, locale: Locale(identifier: identifier))
|
|
819
|
+
if identifier == "en_US" { precondition(text.contains("PM") && !text.contains("14:30")) }
|
|
820
|
+
else { precondition(text == "14:30") }
|
|
821
|
+
let font = fittedClockFont(for: text, width: 96, baseSize: 20)
|
|
822
|
+
precondition((text as NSString).size(withAttributes: [.font: font]).width <= 96 - 1)
|
|
823
|
+
}
|
|
824
|
+
let laClock = clockText(at: afternoon, zone: TimeZone(identifier: "America/Los_Angeles")!, locale: Locale(identifier: "en_US"))
|
|
825
|
+
precondition(laClock.contains("7:30") && laClock.contains("AM"))
|
|
826
|
+
|
|
651
827
|
let morning = ISO8601DateFormatter().date(from: "2026-10-21T02:30:00Z")!
|
|
652
828
|
for weekly in [false, true] {
|
|
653
829
|
let us = resetDescription(afternoon.timeIntervalSince1970, weekly: weekly,
|
|
@@ -683,9 +859,9 @@ struct Main {
|
|
|
683
859
|
let singapore = TimeZone(identifier: "Asia/Singapore")!
|
|
684
860
|
let winter = ISO8601DateFormatter().date(from: "2026-01-15T12:00:00Z")!
|
|
685
861
|
let summer = ISO8601DateFormatter().date(from: "2026-07-15T12:00:00Z")!
|
|
686
|
-
precondition(clockText(at: winter, zone: la) == "04:00")
|
|
687
|
-
precondition(clockText(at: summer, zone: la) == "05:00")
|
|
688
|
-
precondition(clockText(at: winter, zone: singapore) == "20:00")
|
|
862
|
+
precondition(clockText(at: winter, zone: la, locale: Locale(identifier: "en_GB")) == "04:00")
|
|
863
|
+
precondition(clockText(at: summer, zone: la, locale: Locale(identifier: "en_GB")) == "05:00")
|
|
864
|
+
precondition(clockText(at: winter, zone: singapore, locale: Locale(identifier: "en_GB")) == "20:00")
|
|
689
865
|
precondition(TimeZone(identifier: "Invalid/Zone") == nil)
|
|
690
866
|
let utc = TimeZone(secondsFromGMT: 0)!
|
|
691
867
|
for (hour, state) in [(0, RingState.red), (6, .red), (8, .red), (9, .green), (14, .green), (15, .green), (17, .green), (18, .orange), (23, .orange)] {
|
|
@@ -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.11</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.11",
|
|
4
4
|
"description": "Claude Code quota rings and transparent world clock for Claude desktop",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"test": "node --test",
|
|
23
23
|
"start": "node bin/easy-claude.js",
|
|
24
24
|
"build:overlay": "node scripts/build-overlay.mjs",
|
|
25
|
-
"test:native": "python3 scripts/test-native-update.py"
|
|
25
|
+
"test:native": "python3 scripts/test-native-update.py",
|
|
26
|
+
"test:lock": "python3 scripts/test-native-lock.py",
|
|
27
|
+
"test:reminder": "python3 scripts/test-native-reminder.py"
|
|
26
28
|
},
|
|
27
29
|
"license": "MIT",
|
|
28
30
|
"author": "UnionSchool",
|
package/src/overlay-update.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { pathToFileURL } from 'node:url';
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
2
|
import { updatePackage } from './update.js';
|
|
3
|
-
import {
|
|
3
|
+
import { runWithUpdateLock } from './update-lock.js';
|
|
4
4
|
|
|
5
|
-
export async function
|
|
6
|
-
show = async () => (await import('./overlay.js')).launchOverlay(), lock =
|
|
5
|
+
export async function performUpdateAndShow({ update = updatePackage,
|
|
6
|
+
show = async () => (await import('./overlay.js')).launchOverlay(), lock = action => action() } = {}) {
|
|
7
7
|
await lock(async () => {
|
|
8
8
|
if (await update('easy-claude')) await show();
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export async function updateAndShow() {
|
|
13
|
+
await runWithUpdateLock(process.execPath, [fileURLToPath(import.meta.url), '--locked']);
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
13
|
-
updateAndShow().catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
17
|
+
(process.argv[2] === '--locked' ? performUpdateAndShow() : updateAndShow()).catch(error => { console.error(error.message); process.exitCode = 1; });
|
|
14
18
|
}
|
package/src/update-lock.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
@@ -6,17 +6,30 @@ import { fileURLToPath } from 'node:url';
|
|
|
6
6
|
import { installedPrefix } from './update.js';
|
|
7
7
|
|
|
8
8
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
9
|
+
const key = createHash('sha256').update(installedPrefix(root) ?? root).digest('hex').slice(0, 24);
|
|
10
|
+
// 使用新文件名,旧版无持有者信息的目录不再阻挡更新,也不冒险删除它。
|
|
11
|
+
const lockFile = join(tmpdir(), `easy-tools-update-${key}.flock`);
|
|
12
|
+
const helper = fileURLToPath(new URL('../native/build/EasyClaudeOverlay.app/Contents/MacOS/EasyClaudeOverlay', import.meta.url));
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
function runHelper(command, args) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const child = spawn(command, args, { stdio: 'inherit', shell: false });
|
|
17
|
+
child.once('error', () => reject(new Error('无法启动系统更新锁组件,请重新安装此工具。')));
|
|
18
|
+
child.once('exit', (code, signal) => {
|
|
19
|
+
if (signal) reject(new Error('更新进程已中断;系统会在安装进程退出后自动释放锁。'));
|
|
20
|
+
else resolve(code);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function runWithUpdateLock(command, args, {
|
|
26
|
+
lock = lockFile, binary = helper, run = runHelper, platform = process.platform
|
|
27
|
+
} = {}) {
|
|
28
|
+
if (platform !== 'darwin') throw new Error('浮窗更新仅支持 macOS。');
|
|
29
|
+
const code = await run(binary, ['--with-update-lock', lock, command, ...args]);
|
|
30
|
+
if (code === 0) return;
|
|
31
|
+
if (code === 75) throw new Error('另一个 Easy 工具正在更新,请稍后重试;无需清理更新锁。');
|
|
32
|
+
if (code === 73) throw new Error('无法建立系统更新锁,请检查临时目录权限。');
|
|
33
|
+
if (code === 74) throw new Error('无法启动更新程序,请检查 Node.js 安装。');
|
|
34
|
+
throw new Error('更新未完成,请查看上方提示后重试。');
|
|
22
35
|
}
|