easy-claude 0.2.8 → 0.2.12
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 +11 -0
- package/README.md +20 -3
- package/native/Overlay.swift +202 -1
- 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-ip.js +3 -0
- package/src/overlay-update.js +9 -5
- package/src/public-ip.js +31 -0
- package/src/update-lock.js +26 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.2.12(2026-10-21)
|
|
4
|
+
|
|
5
|
+
- 菜单新增公网IP和城市,固定从ip.sb获取IP,再查询该IP的出口城市;启动及每5分钟刷新,点击地址可立即刷新。
|
|
6
|
+
- 获取不到IP时显示“IP异常”;仅城市查询失败时保留IP并显示“城市未知”。支持IPv4/IPv6和现有环境/系统HTTPS代理,不保存IP历史。
|
|
7
|
+
|
|
8
|
+
## v0.2.11(2026-10-21)
|
|
9
|
+
|
|
10
|
+
- 新增一次性“额度可用提醒”:同时受5小时和周额度限制时,等待较晚的恢复时间,在线确认全部可用后发送系统通知和提示音,随后自动关闭。
|
|
11
|
+
- 提醒状态跨重启保存;关闭即取消,断网或查询失败继续等待,目标窗口缺失或额度未知时不误报。
|
|
12
|
+
- 更新锁改为系统内核锁,异常强退后自动释放;安装仍在运行时保持排他,旧锁目录无需手动清理。
|
|
13
|
+
|
|
3
14
|
## v0.2.8(2026-10-21)
|
|
4
15
|
|
|
5
16
|
- 当前时间浮窗和城市菜单跟随系统12/24小时制及地区格式,保留所选城市时区;字体自动适应宽度,避免上午/下午标记截断。
|
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.2.
|
|
7
|
+
## v0.2.12 更新说明
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
9
|
+
- 菜单新增公网IP和城市,固定从ip.sb获取IP,再查询该IP的出口城市;启动及每5分钟刷新,点击地址可立即刷新。
|
|
10
|
+
- 获取不到IP时显示“IP异常”;仅城市查询失败时保留IP并显示“城市未知”。支持IPv4/IPv6和现有环境/系统HTTPS代理,不保存IP历史。
|
|
11
11
|
|
|
12
12
|
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
13
13
|
|
|
@@ -71,6 +71,7 @@ npm run build:overlay
|
|
|
71
71
|
|
|
72
72
|
命令更新:`easy-claude update`,成功后会自动退出旧浮窗并打开新版。旧版本尚未提供 update 时,可先执行 `npm i -g easy-claude@latest`。更新过程中需要正常网络及原安装目录写入权限,不会自动使用 sudo。
|
|
73
73
|
|
|
74
|
+
|
|
74
75
|
菜单中的“更新版本”会后台检查并更新,成功后自动重开浮窗;失败时保留当前浮窗并提示原因。更新期间不能重复点击,已保存设置保持不变。
|
|
75
76
|
|
|
76
77
|
更新前会在线核对版本;已经是最新版本时只提示,不重复安装或重开浮窗。有更高正式版本并安装成功后,才自动重开。
|
|
@@ -78,3 +79,19 @@ npm run build:overlay
|
|
|
78
79
|
额度菜单的重置时刻跟随系统的12/24小时制和AM/PM格式,时区仍使用电脑系统时区。
|
|
79
80
|
|
|
80
81
|
菜单“自动更新”默认关闭,开启后在浮窗运行期间每天检查一次,有新正式版本时自动安装并重开,保留设置;关闭后仍每天检查并显示新版提示,但不自动安装。开启时如已发现新版,会立即更新。自动更新失败仅在菜单提示,可点击“更新版本”查看原因或重试。
|
|
82
|
+
|
|
83
|
+
更新锁恢复:异常强退后自动释放;安装仍在运行时继续阻止并发更新,安装结束即可重试,无需手动清理旧锁。
|
|
84
|
+
|
|
85
|
+
## 额度可用提醒
|
|
86
|
+
|
|
87
|
+
在菜单栏 EA 或浮窗右键菜单开启“额度可用提醒”。首次开启需允许系统通知。仅在额度耗尽且重置时间有效时启用;当前已可用或数据未知时提示刷新后重试。
|
|
88
|
+
|
|
89
|
+
只有5小时或只有周额度时等待对应恢复;两项都耗尽时等待较晚时间,仍有剩余的窗口不参与等待。到点后约每分钟查询,确认所有已知窗口均有剩余,才发送一次系统通知和提示音,然后自动关闭开关。若等待期间再次耗尽,会继续等到有效恢复。
|
|
90
|
+
|
|
91
|
+
开启状态跨更新/重启保存;关闭可取消。浮窗运行时即使目标应用不在前台也能检查,断网则保留提醒并重试。休眠会延后至唤醒,工具完全退出期间不能提醒,重新启动后补查;系统通知权限、专注模式和声音设置可能影响通知展示或声音。不调用模型、不消耗对话额度。
|
|
92
|
+
|
|
93
|
+
## 公网IP与城市
|
|
94
|
+
|
|
95
|
+
菜单显示“公网IP·地址·城市”,由 `https://ip.sb/ip` 获取IP,再通过 `https://api.ip.sb/geoip/<IP>` 获取对应城市;城市名称按接口返回显示。启动和每5分钟刷新,点击该菜单项可立即重查。IP取不到显示“IP异常”;城市取不到显示“城市未知”。
|
|
96
|
+
|
|
97
|
+
查询遵循已有HTTPS/ALL代理环境或macOS系统HTTPS代理。这里显示查询服务看到的网络出口;Clash分流时可能与AI请求不同,城市不代表电脑所在地,也不改变时钟时区。不主动保存IP历史,不发送账号凭据。
|
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
|
|
@@ -230,8 +232,45 @@ final class ClockView: RingView {
|
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
|
|
235
|
+
struct PublicIP: Decodable {
|
|
236
|
+
let ip: String?
|
|
237
|
+
let city: String?
|
|
238
|
+
}
|
|
239
|
+
func publicIPText(ip: String?, city: String?) -> String {
|
|
240
|
+
guard let ip, !ip.isEmpty else { return "IP异常" }
|
|
241
|
+
return "公网IP·\(ip)·\(city ?? "城市未知")"
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 只等待耗尽窗口,但确认恢复时必须同时检查所有已知窗口,缺失或未知不能报可用。
|
|
245
|
+
struct AvailabilityReminder: Codable {
|
|
246
|
+
var ids: [String]
|
|
247
|
+
var due: Double
|
|
248
|
+
static func arm(_ windows: [UsageWindow], now: Double) -> Self? {
|
|
249
|
+
guard !windows.isEmpty, windows.allSatisfy({ window in
|
|
250
|
+
guard let remaining = window.remaining, remaining.isFinite, remaining >= 0,
|
|
251
|
+
let reset = window.resetsAt, reset.isFinite, reset > now else { return false }
|
|
252
|
+
return true
|
|
253
|
+
}) else { return nil }
|
|
254
|
+
let blocked = windows.filter { $0.remaining == 0 }
|
|
255
|
+
guard let due = blocked.compactMap(\.resetsAt).max() else { return nil }
|
|
256
|
+
return Self(ids: windows.map(\.id), due: due)
|
|
257
|
+
}
|
|
258
|
+
mutating func recovered(_ windows: [UsageWindow], fetchedAt: Double, restricted: Bool, now: Double) -> Bool {
|
|
259
|
+
guard now >= due, fetchedAt >= due, now - fetchedAt <= 120, !restricted,
|
|
260
|
+
ids.allSatisfy({ id in windows.contains { $0.id == id } }), !windows.isEmpty else { return false }
|
|
261
|
+
let blocked = windows.filter { $0.remaining == 0 }
|
|
262
|
+
if let later = blocked.compactMap(\.resetsAt).filter({ $0.isFinite && $0 > now }).max() { due = later }
|
|
263
|
+
return windows.allSatisfy {
|
|
264
|
+
guard let remaining = $0.remaining, remaining.isFinite, remaining > 0,
|
|
265
|
+
let reset = $0.resetsAt, reset.isFinite, reset > now else { return false }
|
|
266
|
+
return true
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
func reminderWindows(_ windows: [UsageWindow]) -> [UsageWindow] { windows.filter { ["five_hour:primary", "seven_day:primary"].contains($0.id) } }
|
|
271
|
+
|
|
233
272
|
@MainActor
|
|
234
|
-
final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
273
|
+
final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNotificationCenterDelegate {
|
|
235
274
|
let panel = NSPanel(contentRect: CGRect(x: 0, y: 0, width: 32, height: 32),
|
|
236
275
|
styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
|
|
237
276
|
let ring = RingView(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
|
|
@@ -242,6 +281,9 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
242
281
|
var clockEnabled = true
|
|
243
282
|
var status: NSStatusItem?
|
|
244
283
|
var timer: Timer?
|
|
284
|
+
var ipQuery: Process?
|
|
285
|
+
var ipLastAttempt = Date.distantPast
|
|
286
|
+
var ipText = "正在获取IP…"
|
|
245
287
|
var query: Process?
|
|
246
288
|
var updater: Process?
|
|
247
289
|
var versionCheck: Process?
|
|
@@ -249,6 +291,11 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
249
291
|
var automaticUpdateError: String?
|
|
250
292
|
var versionCheckError: String?
|
|
251
293
|
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "未知"
|
|
294
|
+
var reminder = UserDefaults.standard.data(forKey: "availabilityReminder").flatMap { try? JSONDecoder().decode(AvailabilityReminder.self, from: $0) }
|
|
295
|
+
var reminderSending = false
|
|
296
|
+
var reminderAuthorizing = false
|
|
297
|
+
var reminderGeneration = 0
|
|
298
|
+
var reminderError: String?
|
|
252
299
|
var snapshot: Snapshot?
|
|
253
300
|
var error: String?
|
|
254
301
|
var lastAttempt = Date.distantPast
|
|
@@ -260,6 +307,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
260
307
|
var claudeHome = ""
|
|
261
308
|
|
|
262
309
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
310
|
+
UNUserNotificationCenter.current().delegate = self
|
|
263
311
|
let args = CommandLine.arguments
|
|
264
312
|
guard args.count >= 4 else { NSApp.terminate(nil); return }
|
|
265
313
|
node = args[1]; script = args[2]; searchPath = args[3]
|
|
@@ -322,6 +370,8 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
322
370
|
@objc func hide() { panel.orderOut(nil); clockPanel.orderOut(nil) }
|
|
323
371
|
@objc func tick() {
|
|
324
372
|
checkVersionIfNeeded()
|
|
373
|
+
if Date().timeIntervalSince(ipLastAttempt) >= 300 { refreshIP() }
|
|
374
|
+
if let reminder, Date().timeIntervalSince(lastAttempt) >= (Date().timeIntervalSince1970 >= reminder.due ? 60 : 300) { refresh() }
|
|
325
375
|
guard let rect = targetWindow() else { hide(); lastRect = nil; return }
|
|
326
376
|
lastRect = rect
|
|
327
377
|
if clockEnabled {
|
|
@@ -389,6 +439,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
389
439
|
self.snapshot = value; self.error = nil
|
|
390
440
|
} else { self.error = "额度查询失败" }
|
|
391
441
|
} catch { self.error = "无法读取额度响应,请检查 CLI 和网络" }
|
|
442
|
+
self.checkReminder()
|
|
392
443
|
self.updateRing()
|
|
393
444
|
}
|
|
394
445
|
}
|
|
@@ -396,6 +447,101 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
396
447
|
do { try process.run() }
|
|
397
448
|
catch { query = nil; self.error = "无法启动额度查询,请重新运行 easy-claude show"; updateRing() }
|
|
398
449
|
}
|
|
450
|
+
@objc func refreshIP() {
|
|
451
|
+
guard ipQuery == nil else { return }
|
|
452
|
+
ipLastAttempt = Date()
|
|
453
|
+
let process = Process(), pipe = Pipe()
|
|
454
|
+
process.executableURL = URL(fileURLWithPath: node)
|
|
455
|
+
process.arguments = [URL(fileURLWithPath: script).deletingLastPathComponent().appendingPathComponent("overlay-ip.js").path]
|
|
456
|
+
var env = ProcessInfo.processInfo.environment
|
|
457
|
+
env["PATH"] = searchPath
|
|
458
|
+
process.environment = env
|
|
459
|
+
process.standardOutput = pipe
|
|
460
|
+
process.standardError = FileHandle.nullDevice
|
|
461
|
+
process.terminationHandler = { [weak self] process in
|
|
462
|
+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
463
|
+
let value = try? JSONDecoder().decode(PublicIP.self, from: data)
|
|
464
|
+
let text = publicIPText(ip: process.terminationStatus == 0 ? value?.ip : nil, city: value?.city)
|
|
465
|
+
Task { @MainActor in
|
|
466
|
+
guard let self else { return }
|
|
467
|
+
self.ipQuery = nil; self.ipText = text
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
ipQuery = process
|
|
471
|
+
do { try process.run() }
|
|
472
|
+
catch { ipQuery = nil; ipText = "IP异常" }
|
|
473
|
+
}
|
|
474
|
+
func saveReminder() {
|
|
475
|
+
if let reminder, let data = try? JSONEncoder().encode(reminder) {
|
|
476
|
+
UserDefaults.standard.set(data, forKey: "availabilityReminder")
|
|
477
|
+
} else { UserDefaults.standard.removeObject(forKey: "availabilityReminder") }
|
|
478
|
+
}
|
|
479
|
+
@objc func toggleReminder() {
|
|
480
|
+
guard !reminderAuthorizing else { return }
|
|
481
|
+
reminderGeneration += 1
|
|
482
|
+
reminderError = nil
|
|
483
|
+
if reminder != nil {
|
|
484
|
+
reminder = nil; saveReminder()
|
|
485
|
+
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ["quota-available"])
|
|
486
|
+
return
|
|
487
|
+
}
|
|
488
|
+
let now = Date().timeIntervalSince1970
|
|
489
|
+
guard error == nil, let snapshot, now - snapshot.fetchedAt <= 600,
|
|
490
|
+
let candidate = AvailabilityReminder.arm(reminderWindows(snapshot.windows), now: now) else {
|
|
491
|
+
reminderError = "当前额度可用,或缺少有效额度/重置时间;请刷新后重试"
|
|
492
|
+
refresh(); return
|
|
493
|
+
}
|
|
494
|
+
reminderAuthorizing = true
|
|
495
|
+
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { @Sendable [weak self] allowed, _ in
|
|
496
|
+
Task { @MainActor in
|
|
497
|
+
guard let self else { return }
|
|
498
|
+
self.reminderAuthorizing = false
|
|
499
|
+
if allowed { self.reminder = candidate; self.saveReminder() }
|
|
500
|
+
else { self.reminderError = "请在系统设置中允许本工具发送通知,再开启提醒" }
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
func checkReminder() {
|
|
505
|
+
guard !reminderSending, error == nil, let snapshot, var pending = reminder else { return }
|
|
506
|
+
let ready = pending.recovered(reminderWindows(snapshot.windows), fetchedAt: snapshot.fetchedAt,
|
|
507
|
+
restricted: snapshot.restricted, now: Date().timeIntervalSince1970)
|
|
508
|
+
reminder = pending; saveReminder()
|
|
509
|
+
guard ready else { return }
|
|
510
|
+
reminderSending = true
|
|
511
|
+
let generation = reminderGeneration
|
|
512
|
+
UNUserNotificationCenter.current().getNotificationSettings { @Sendable [weak self] settings in
|
|
513
|
+
// 旧SDK的设置对象不是Sendable,只把判断结果送回主线程。
|
|
514
|
+
let allowed = settings.authorizationStatus == .authorized || settings.authorizationStatus == .provisional
|
|
515
|
+
Task { @MainActor in
|
|
516
|
+
guard let self else { return }
|
|
517
|
+
guard generation == self.reminderGeneration, self.reminder != nil else { self.reminderSending = false; return }
|
|
518
|
+
guard allowed else {
|
|
519
|
+
self.reminderSending = false
|
|
520
|
+
self.reminderError = "通知未获允许,提醒已保留;请在系统设置允许通知"
|
|
521
|
+
return
|
|
522
|
+
}
|
|
523
|
+
let content = UNMutableNotificationContent()
|
|
524
|
+
content.title = "Claude 额度已恢复"
|
|
525
|
+
content.body = "已确认当前额度可用,可以继续使用了。"
|
|
526
|
+
content.sound = .default
|
|
527
|
+
UNUserNotificationCenter.current().add(UNNotificationRequest(identifier: "quota-available", content: content, trigger: nil)) { @Sendable [weak self] error in
|
|
528
|
+
let failed = error != nil
|
|
529
|
+
Task { @MainActor in
|
|
530
|
+
guard let self else { return }
|
|
531
|
+
if generation == self.reminderGeneration {
|
|
532
|
+
if !failed { self.reminder = nil; self.reminderError = nil; self.saveReminder() }
|
|
533
|
+
else { self.reminderError = "通知发送失败,提醒已保留,将稍后重试" }
|
|
534
|
+
}
|
|
535
|
+
self.reminderSending = false
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter,
|
|
542
|
+
willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
543
|
+
completionHandler([.banner, .sound, .list])
|
|
544
|
+
}
|
|
399
545
|
func item(_ title: String, _ action: Selector?) -> NSMenuItem {
|
|
400
546
|
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
|
401
547
|
item.target = self
|
|
@@ -407,6 +553,9 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
407
553
|
menu.addItem(item(lastRect == nil ? "等待 Claude 前台窗口" : "拖动圆环可调整位置", nil))
|
|
408
554
|
if let error { menu.addItem(item(error, nil)) }
|
|
409
555
|
if snapshot?.restricted == true { menu.addItem(item("服务端提示:当前使用受限", nil)) }
|
|
556
|
+
let address = item(ipText, ipQuery == nil ? #selector(refreshIP) : nil)
|
|
557
|
+
address.toolTip = "点击刷新公网IP;城市为网络出口位置"
|
|
558
|
+
menu.addItem(address)
|
|
410
559
|
menu.addItem(.separator())
|
|
411
560
|
for (id, label) in [("five_hour:primary", "5小时"), ("seven_day:primary", "周")] {
|
|
412
561
|
guard let window = snapshot?.windows.first(where: { $0.id == id }) else { continue }
|
|
@@ -418,6 +567,13 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
418
567
|
menu.addItem(option)
|
|
419
568
|
}
|
|
420
569
|
menu.addItem(item(query == nil ? "立即刷新" : "正在刷新…", query == nil ? #selector(refresh) : nil))
|
|
570
|
+
let alarm = item("额度可用提醒", reminderAuthorizing ? nil : #selector(toggleReminder))
|
|
571
|
+
alarm.state = reminder == nil ? .off : .on
|
|
572
|
+
menu.addItem(alarm)
|
|
573
|
+
if let reminder {
|
|
574
|
+
menu.addItem(item("等待额度恢复 · " + resetDescription(reminder.due, weekly: true), nil))
|
|
575
|
+
}
|
|
576
|
+
if let reminderError { menu.addItem(item(reminderError, nil)) }
|
|
421
577
|
menu.addItem(item("恢复默认位置", #selector(resetPosition)))
|
|
422
578
|
menu.addItem(.separator())
|
|
423
579
|
let toggle = item("显示时间", #selector(toggleClock))
|
|
@@ -629,6 +785,7 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
629
785
|
}
|
|
630
786
|
@objc func quit() { NSApp.terminate(nil) }
|
|
631
787
|
func applicationWillTerminate(_ notification: Notification) {
|
|
788
|
+
ipQuery?.terminate()
|
|
632
789
|
timer?.invalidate()
|
|
633
790
|
query?.terminate()
|
|
634
791
|
versionCheck?.terminate()
|
|
@@ -639,7 +796,51 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
639
796
|
@main
|
|
640
797
|
struct Main {
|
|
641
798
|
@MainActor static func main() {
|
|
799
|
+
if CommandLine.arguments.count >= 2 && CommandLine.arguments[1] == "--with-update-lock" {
|
|
800
|
+
let args = CommandLine.arguments
|
|
801
|
+
guard args.count >= 5 else { exit(72) }
|
|
802
|
+
let fd = Darwin.open(args[2], O_RDWR | O_CREAT | O_NOFOLLOW | O_EXLOCK | O_NONBLOCK, mode_t(0o600))
|
|
803
|
+
guard fd >= 0 else { exit(errno == EWOULDBLOCK || errno == EAGAIN ? 75 : 73) }
|
|
804
|
+
// 更新不读取交互输入;通过stdin把同一个内核锁传给Node和npm子进程。
|
|
805
|
+
guard dup2(fd, STDIN_FILENO) >= 0 else { Darwin.close(fd); exit(73) }
|
|
806
|
+
if fd != STDIN_FILENO { Darwin.close(fd) }
|
|
807
|
+
var argv = Array(args.dropFirst(3)).map { strdup($0) } + [nil]
|
|
808
|
+
argv.withUnsafeMutableBufferPointer { buffer in
|
|
809
|
+
_ = execv(args[3], buffer.baseAddress!)
|
|
810
|
+
}
|
|
811
|
+
for value in argv { free(value) }
|
|
812
|
+
exit(74)
|
|
813
|
+
}
|
|
814
|
+
|
|
642
815
|
if CommandLine.arguments.contains("--self-test") {
|
|
816
|
+
precondition(publicIPText(ip: nil, city: "City") == "IP异常")
|
|
817
|
+
precondition(publicIPText(ip: "203.0.113.1", city: nil) == "公网IP·203.0.113.1·城市未知")
|
|
818
|
+
precondition(publicIPText(ip: "203.0.113.1", city: "City") == "公网IP·203.0.113.1·City")
|
|
819
|
+
func quota(_ id: String, _ remaining: Double?, _ reset: Double?) -> UsageWindow {
|
|
820
|
+
UsageWindow(id: id, label: id, name: id, remaining: remaining, resetsAt: reset)
|
|
821
|
+
}
|
|
822
|
+
let a = quota("five", 0, 3700), b = quota("week", 0, 7300)
|
|
823
|
+
precondition(AvailabilityReminder.arm([a, b], now: 100)?.due == 7300)
|
|
824
|
+
precondition(AvailabilityReminder.arm([quota("five", 0, 10900), b], now: 100)?.due == 10900)
|
|
825
|
+
precondition(AvailabilityReminder.arm([a, quota("week", 30, 7300)], now: 100)?.due == 3700)
|
|
826
|
+
precondition(AvailabilityReminder.arm([b], now: 100)?.due == 7300)
|
|
827
|
+
precondition(AvailabilityReminder.arm([quota("five", 10, 3700)], now: 100) == nil)
|
|
828
|
+
precondition(AvailabilityReminder.arm([quota("five", nil, 3700)], now: 100) == nil)
|
|
829
|
+
precondition(AvailabilityReminder.arm([quota("five", 0, nil)], now: 100) == nil)
|
|
830
|
+
var alarm = AvailabilityReminder.arm([a, b], now: 100)!
|
|
831
|
+
let restored = try! JSONDecoder().decode(AvailabilityReminder.self, from: JSONEncoder().encode(alarm))
|
|
832
|
+
precondition(restored.ids == alarm.ids && restored.due == 7300)
|
|
833
|
+
let usable = [quota("five", 100, 18000), quota("week", 100, 600000)]
|
|
834
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7300, restricted: false, now: 7299))
|
|
835
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7200, restricted: false, now: 7400))
|
|
836
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7300, restricted: false, now: 7500))
|
|
837
|
+
precondition(!alarm.recovered(usable, fetchedAt: 7400, restricted: true, now: 7400))
|
|
838
|
+
precondition(!alarm.recovered([usable[0]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
839
|
+
precondition(!alarm.recovered([quota("five", nil, 18000), usable[1]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
840
|
+
precondition(alarm.recovered(usable, fetchedAt: 7400, restricted: false, now: 7400))
|
|
841
|
+
precondition(!alarm.recovered([quota("five", 0, 18000), usable[1]], fetchedAt: 7400, restricted: false, now: 7400))
|
|
842
|
+
precondition(alarm.due == 18000)
|
|
843
|
+
print("额度提醒:较晚恢复、单窗口、未知/过期/受限、重启保存及再次耗尽检查通过")
|
|
643
844
|
let preferenceSuite = "easy-auto-update-self-test-" + UUID().uuidString
|
|
644
845
|
let preferences = UserDefaults(suiteName: preferenceSuite)!
|
|
645
846
|
precondition(!preferences.bool(forKey: "automaticUpdatesEnabled"))
|
|
@@ -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.12</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.12",
|
|
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/public-ip.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { isIP } from 'node:net';
|
|
4
|
+
import { systemProxy } from './transport.js';
|
|
5
|
+
|
|
6
|
+
export async function readPublicIP({ run = promisify(execFile), env = process.env, platform = process.platform } = {}) {
|
|
7
|
+
let proxy = env.https_proxy || env.HTTPS_PROXY || env.all_proxy || env.ALL_PROXY;
|
|
8
|
+
if (!proxy && platform === 'darwin') {
|
|
9
|
+
const { stdout } = await run('/usr/sbin/scutil', ['--proxy'], { timeout: 2000, maxBuffer: 65536 });
|
|
10
|
+
proxy = systemProxy(stdout);
|
|
11
|
+
}
|
|
12
|
+
const request = async url => {
|
|
13
|
+
const { stdout } = await run('/usr/bin/curl', ['-q', '--silent', '--show-error', '--fail', '--proto', '=https',
|
|
14
|
+
'--connect-timeout', '5', '--max-time', '12', '--max-redirs', '0', url], {
|
|
15
|
+
timeout: 15000, maxBuffer: 8192, env: proxy ? { ...env, https_proxy: proxy } : env
|
|
16
|
+
});
|
|
17
|
+
return stdout;
|
|
18
|
+
};
|
|
19
|
+
let ip;
|
|
20
|
+
try { ip = (await request('https://ip.sb/ip')).trim(); }
|
|
21
|
+
catch { throw new Error('IP异常'); }
|
|
22
|
+
if (!isIP(ip)) throw new Error('IP异常');
|
|
23
|
+
let city = null;
|
|
24
|
+
try {
|
|
25
|
+
const data = JSON.parse(await request('https://api.ip.sb/geoip/' + ip));
|
|
26
|
+
if (data.ip === ip && typeof data.city === 'string') {
|
|
27
|
+
city = data.city.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').trim().slice(0, 60) || null;
|
|
28
|
+
}
|
|
29
|
+
} catch { /* 城市查询失败仍保留已确认的IP。 */ }
|
|
30
|
+
return { ip, city };
|
|
31
|
+
}
|
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
|
}
|