easy-claude 0.2.12 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 更新记录
|
|
2
2
|
|
|
3
|
+
## v0.3.1(2026-10-20,America/Los_Angeles)
|
|
4
|
+
|
|
5
|
+
- 新增“跟随IP时区”开关,默认关闭;开启后自动显示网络出口时区时间并隐藏手动时区选择,关闭恢复原城市和时区。
|
|
6
|
+
- 获取不到IP或有效时区时显示自定义时区的时间;开关保持开启,后续获取成功自动继续跟随。继续支持系统12/24小时制与夏令时。
|
|
7
|
+
- IP菜单改为“城市名称·IP地址”,无空格;IP获取失败仍显示“IP异常”。城市和时区通过已验证IP查询地理信息,不按城市猜测时区。
|
|
8
|
+
|
|
3
9
|
## v0.2.12(2026-10-21)
|
|
4
10
|
|
|
5
11
|
- 菜单新增公网IP和城市,固定从ip.sb获取IP,再查询该IP的出口城市;启动及每5分钟刷新,点击地址可立即刷新。
|
package/README.md
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
|
|
6
6
|
|
|
7
|
-
## v0.
|
|
7
|
+
## v0.3.1 更新说明
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
- 获取不到IP
|
|
9
|
+
- 新增“跟随IP时区”开关,默认关闭;开启后自动显示网络出口时区时间并隐藏手动时区选择,关闭恢复原城市和时区。
|
|
10
|
+
- 获取不到IP或有效时区时显示自定义时区的时间;开关保持开启,后续获取成功自动继续跟随。继续支持系统12/24小时制与夏令时。
|
|
11
|
+
- IP菜单改为“城市名称·IP地址”,无空格;IP获取失败仍显示“IP异常”。城市和时区通过已验证IP查询地理信息,不按城市猜测时区。
|
|
11
12
|
|
|
12
13
|
历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
|
|
13
14
|
|
|
@@ -92,6 +93,15 @@ npm run build:overlay
|
|
|
92
93
|
|
|
93
94
|
## 公网IP与城市
|
|
94
95
|
|
|
95
|
-
|
|
96
|
+
菜单显示“城市名称·IP地址”,由 `https://ip.sb/ip` 获取IP,再通过 `https://api.ip.sb/geoip/<IP>` 获取对应城市;城市名称按接口返回显示。启动和每5分钟刷新,点击该菜单项可立即重查。IP取不到显示“IP异常”;城市取不到显示“城市未知”。
|
|
96
97
|
|
|
97
|
-
查询遵循已有HTTPS/ALL代理环境或macOS系统HTTPS代理。这里显示查询服务看到的网络出口;Clash分流时可能与AI
|
|
98
|
+
查询遵循已有HTTPS/ALL代理环境或macOS系统HTTPS代理。这里显示查询服务看到的网络出口;Clash分流时可能与AI请求不同,城市不代表电脑所在地,关闭“跟随IP时区”时不改变时钟时区。不主动保存IP历史,不发送账号凭据。
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
IP地理库的城市与时区可能存在偏差或互相不一致;显示接口返回值,仅校验时区名称有效性,不根据城市猜测时区。
|
|
102
|
+
|
|
103
|
+
## 跟随IP时区
|
|
104
|
+
|
|
105
|
+
菜单开启“跟随IP时区”后,时钟按地理接口返回的IANA时区显示当地时间,自动处理夏令时,继续跟随系统12/24小时制;时钟下方显示“IP时区”,手动时区选择隐藏。IP每5分钟刷新或点击IP菜单刷新,时区同步更新。
|
|
106
|
+
|
|
107
|
+
关闭后恢复之前手动选择的城市和时区,并重新显示选择菜单。取不到IP或有效时区时,时钟回退到手动设置的时区,菜单提示“IP时区不可用,显示自定义时间”;开关仍开启,获取成功后继续跟随。开关和手动设置跨重启/更新保存,不保存IP历史。IP地理数据可能不准确,跟随的是出口时区,不修改电脑系统时区。
|
package/native/Overlay.swift
CHANGED
|
@@ -232,13 +232,24 @@ final class ClockView: RingView {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
struct IPClockState {
|
|
236
|
+
private(set) var zone: TimeZone?
|
|
237
|
+
mutating func update(_ identifier: String?) -> Bool {
|
|
238
|
+
guard let identifier, let next = TimeZone(identifier: identifier) else { zone = nil; return false }
|
|
239
|
+
zone = next
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
func resolved(manual: TimeZone, following: Bool) -> TimeZone { following ? zone ?? manual : manual }
|
|
243
|
+
}
|
|
244
|
+
|
|
235
245
|
struct PublicIP: Decodable {
|
|
236
246
|
let ip: String?
|
|
237
247
|
let city: String?
|
|
248
|
+
let timezone: String?
|
|
238
249
|
}
|
|
239
250
|
func publicIPText(ip: String?, city: String?) -> String {
|
|
240
251
|
guard let ip, !ip.isEmpty else { return "IP异常" }
|
|
241
|
-
return "
|
|
252
|
+
return "\(city ?? "城市未知")·\(ip)"
|
|
242
253
|
}
|
|
243
254
|
|
|
244
255
|
// 只等待耗尽窗口,但确认恢复时必须同时检查所有已知窗口,缺失或未知不能报可用。
|
|
@@ -279,6 +290,10 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
279
290
|
let clock = ClockView(frame: CGRect(x: 0, y: 0, width: 96, height: 46))
|
|
280
291
|
var clockInset = CGPoint(x: 164, y: 0)
|
|
281
292
|
var clockEnabled = true
|
|
293
|
+
var followIPTimeZone = UserDefaults.standard.bool(forKey: "followIPTimeZone")
|
|
294
|
+
var ipClock = IPClockState()
|
|
295
|
+
var manualClockZone = TimeZone(identifier: "America/Los_Angeles")!
|
|
296
|
+
var manualClockCity = "硅谷"
|
|
282
297
|
var status: NSStatusItem?
|
|
283
298
|
var timer: Timer?
|
|
284
299
|
var ipQuery: Process?
|
|
@@ -323,6 +338,8 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
323
338
|
?? ClockCity.presets.first { $0.identifier == identifier }
|
|
324
339
|
clock.cityName = preset?.name ?? identifier
|
|
325
340
|
}
|
|
341
|
+
manualClockZone = clock.zone; manualClockCity = clock.cityName
|
|
342
|
+
applyClockTimeZone()
|
|
326
343
|
ring.showWeeklyPercentage = prefs.bool(forKey: "showWeeklyPercentage")
|
|
327
344
|
clockEnabled = prefs.object(forKey: "clockEnabled") == nil || prefs.bool(forKey: "clockEnabled")
|
|
328
345
|
if prefs.object(forKey: "clockLeftInset") != nil {
|
|
@@ -447,6 +464,21 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
447
464
|
do { try process.run() }
|
|
448
465
|
catch { query = nil; self.error = "无法启动额度查询,请重新运行 easy-claude show"; updateRing() }
|
|
449
466
|
}
|
|
467
|
+
func applyClockTimeZone() {
|
|
468
|
+
clock.zone = ipClock.resolved(manual: manualClockZone, following: followIPTimeZone)
|
|
469
|
+
clock.cityName = followIPTimeZone && ipClock.zone != nil ? "IP时区" : manualClockCity
|
|
470
|
+
clock.needsDisplay = true
|
|
471
|
+
}
|
|
472
|
+
func receiveIPTimeZone(_ identifier: String?) {
|
|
473
|
+
_ = ipClock.update(identifier)
|
|
474
|
+
applyClockTimeZone()
|
|
475
|
+
}
|
|
476
|
+
@objc func toggleFollowIPTimeZone() {
|
|
477
|
+
followIPTimeZone.toggle()
|
|
478
|
+
UserDefaults.standard.set(followIPTimeZone, forKey: "followIPTimeZone")
|
|
479
|
+
applyClockTimeZone()
|
|
480
|
+
if followIPTimeZone { refreshIP() }
|
|
481
|
+
}
|
|
450
482
|
@objc func refreshIP() {
|
|
451
483
|
guard ipQuery == nil else { return }
|
|
452
484
|
ipLastAttempt = Date()
|
|
@@ -462,14 +494,16 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
462
494
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
|
463
495
|
let value = try? JSONDecoder().decode(PublicIP.self, from: data)
|
|
464
496
|
let text = publicIPText(ip: process.terminationStatus == 0 ? value?.ip : nil, city: value?.city)
|
|
497
|
+
let timezone = process.terminationStatus == 0 ? value?.timezone : nil
|
|
465
498
|
Task { @MainActor in
|
|
466
499
|
guard let self else { return }
|
|
467
500
|
self.ipQuery = nil; self.ipText = text
|
|
501
|
+
self.receiveIPTimeZone(timezone)
|
|
468
502
|
}
|
|
469
503
|
}
|
|
470
504
|
ipQuery = process
|
|
471
505
|
do { try process.run() }
|
|
472
|
-
catch { ipQuery = nil; ipText = "IP异常" }
|
|
506
|
+
catch { ipQuery = nil; ipText = "IP异常"; receiveIPTimeZone(nil) }
|
|
473
507
|
}
|
|
474
508
|
func saveReminder() {
|
|
475
509
|
if let reminder, let data = try? JSONEncoder().encode(reminder) {
|
|
@@ -579,17 +613,25 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
579
613
|
let toggle = item("显示时间", #selector(toggleClock))
|
|
580
614
|
toggle.state = clockEnabled ? .on : .off
|
|
581
615
|
menu.addItem(toggle)
|
|
582
|
-
let
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
616
|
+
let follow = item("跟随IP时区", #selector(toggleFollowIPTimeZone))
|
|
617
|
+
follow.state = followIPTimeZone ? .on : .off
|
|
618
|
+
menu.addItem(follow)
|
|
619
|
+
if followIPTimeZone && ipClock.zone == nil {
|
|
620
|
+
menu.addItem(item("IP时区不可用,显示自定义时间", nil))
|
|
621
|
+
}
|
|
622
|
+
if !followIPTimeZone {
|
|
623
|
+
let zones = NSMenu()
|
|
624
|
+
for city in ClockCity.presets {
|
|
625
|
+
let option = item(city.name, #selector(selectTimeZone(_:)))
|
|
626
|
+
option.representedObject = city.name
|
|
627
|
+
option.state = clock.cityName == city.name && clock.zone.identifier == city.identifier ? .on : .off
|
|
628
|
+
zones.addItem(option)
|
|
629
|
+
}
|
|
630
|
+
zones.addItem(item("自定义时区…", #selector(customTimeZone)))
|
|
631
|
+
let zoneItem = item("\(clock.cityName)·\(clockText(at: Date(), zone: clock.zone))", nil)
|
|
632
|
+
zoneItem.submenu = zones
|
|
633
|
+
menu.addItem(zoneItem)
|
|
634
|
+
}
|
|
593
635
|
menu.addItem(.separator())
|
|
594
636
|
let updateItem = item(updater == nil ? "更新版本·\(appVersion)" : "正在更新…·\(appVersion)",
|
|
595
637
|
updater == nil ? #selector(updateVersion) : nil)
|
|
@@ -630,11 +672,13 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
|
|
|
630
672
|
}
|
|
631
673
|
func setTimeZone(_ identifier: String, cityName: String? = nil) -> Bool {
|
|
632
674
|
guard let zone = TimeZone(identifier: identifier) else { return false }
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
UserDefaults.standard.set(
|
|
675
|
+
manualClockZone = zone
|
|
676
|
+
manualClockCity = cityName ?? ClockCity.presets.first { $0.identifier == zone.identifier }?.name ?? zone.identifier
|
|
677
|
+
UserDefaults.standard.set(manualClockCity, forKey: "clockCity")
|
|
636
678
|
UserDefaults.standard.set(zone.identifier, forKey: "clockTimeZone")
|
|
637
|
-
|
|
679
|
+
followIPTimeZone = false
|
|
680
|
+
UserDefaults.standard.set(false, forKey: "followIPTimeZone")
|
|
681
|
+
applyClockTimeZone()
|
|
638
682
|
return true
|
|
639
683
|
}
|
|
640
684
|
@objc func selectTimeZone(_ sender: NSMenuItem) {
|
|
@@ -813,9 +857,36 @@ struct Main {
|
|
|
813
857
|
}
|
|
814
858
|
|
|
815
859
|
if CommandLine.arguments.contains("--self-test") {
|
|
860
|
+
let manualIPTest = TimeZone(identifier: "Asia/Shanghai")!
|
|
861
|
+
var ipClockTest = IPClockState()
|
|
862
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true) == manualIPTest)
|
|
863
|
+
precondition(ipClockTest.update("America/Los_Angeles"))
|
|
864
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true).identifier == "America/Los_Angeles")
|
|
865
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: false) == manualIPTest)
|
|
866
|
+
precondition(!ipClockTest.update(nil) && !ipClockTest.update("Invalid/Zone"))
|
|
867
|
+
precondition(ipClockTest.zone == nil)
|
|
868
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true) == manualIPTest)
|
|
869
|
+
precondition(ipClockTest.update("Asia/Singapore"))
|
|
870
|
+
precondition(ipClockTest.resolved(manual: manualIPTest, following: true).identifier == "Asia/Singapore")
|
|
871
|
+
_ = NSApplication.shared
|
|
872
|
+
let clockMenuTest = Overlay()
|
|
873
|
+
clockMenuTest.manualClockZone = manualIPTest
|
|
874
|
+
clockMenuTest.manualClockCity = "上海"
|
|
875
|
+
clockMenuTest.followIPTimeZone = true
|
|
876
|
+
_ = clockMenuTest.ipClock.update("America/Los_Angeles")
|
|
877
|
+
clockMenuTest.applyClockTimeZone()
|
|
878
|
+
precondition(clockMenuTest.clock.zone.identifier == "America/Los_Angeles")
|
|
879
|
+
precondition(!clockMenuTest.makeMenu().items.contains { $0.submenu != nil })
|
|
880
|
+
clockMenuTest.receiveIPTimeZone(nil)
|
|
881
|
+
precondition(clockMenuTest.clock.zone == manualIPTest && clockMenuTest.clock.cityName == "上海")
|
|
882
|
+
precondition(clockMenuTest.followIPTimeZone)
|
|
883
|
+
clockMenuTest.followIPTimeZone = false
|
|
884
|
+
clockMenuTest.applyClockTimeZone()
|
|
885
|
+
precondition(clockMenuTest.makeMenu().items.contains { $0.submenu != nil })
|
|
886
|
+
print("跟随IP时区:开关、手动恢复、失败回退及出口变化检查通过")
|
|
816
887
|
precondition(publicIPText(ip: nil, city: "City") == "IP异常")
|
|
817
|
-
precondition(publicIPText(ip: "203.0.113.1", city: nil) == "
|
|
818
|
-
precondition(publicIPText(ip: "203.0.113.1", city: "City") == "
|
|
888
|
+
precondition(publicIPText(ip: "203.0.113.1", city: nil) == "城市未知·203.0.113.1")
|
|
889
|
+
precondition(publicIPText(ip: "203.0.113.1", city: "City") == "City·203.0.113.1")
|
|
819
890
|
func quota(_ id: String, _ remaining: Double?, _ reset: Double?) -> UsageWindow {
|
|
820
891
|
UsageWindow(id: id, label: id, name: id, remaining: remaining, resetsAt: reset)
|
|
821
892
|
}
|
|
@@ -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.
|
|
8
|
+
<key>CFBundleShortVersionString</key><string>0.3.1</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
package/src/public-ip.js
CHANGED
|
@@ -20,12 +20,20 @@ export async function readPublicIP({ run = promisify(execFile), env = process.en
|
|
|
20
20
|
try { ip = (await request('https://ip.sb/ip')).trim(); }
|
|
21
21
|
catch { throw new Error('IP异常'); }
|
|
22
22
|
if (!isIP(ip)) throw new Error('IP异常');
|
|
23
|
-
let city = null;
|
|
23
|
+
let city = null, timezone = null;
|
|
24
24
|
try {
|
|
25
25
|
const data = JSON.parse(await request('https://api.ip.sb/geoip/' + ip));
|
|
26
|
-
if (data.ip === ip
|
|
27
|
-
|
|
26
|
+
if (data.ip === ip) {
|
|
27
|
+
if (typeof data.city === 'string') {
|
|
28
|
+
city = data.city.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ').trim().slice(0, 60) || null;
|
|
29
|
+
}
|
|
30
|
+
if (typeof data.timezone === 'string' && data.timezone.length <= 100) {
|
|
31
|
+
try {
|
|
32
|
+
new Intl.DateTimeFormat('en', { timeZone: data.timezone });
|
|
33
|
+
timezone = data.timezone;
|
|
34
|
+
} catch { /* 无效时区保持未知,不改用电脑时区。 */ }
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
} catch { /* 城市查询失败仍保留已确认的IP。 */ }
|
|
30
|
-
return { ip, city };
|
|
38
|
+
return { ip, city, timezone };
|
|
31
39
|
}
|