easy-claude 0.3.3 → 0.3.4

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,12 @@
1
1
  # 更新记录
2
2
 
3
+ ## v0.3.4(2026-10-22,America/Los_Angeles)
4
+
5
+ - 12小时制按所选时区显示五个时段:00:00–06:00 凌晨、06:00–12:00 上午、12:00–18:00 下午、18:00–21:00 晚上、21:00–24:00 深夜。
6
+ - 零点显示 `00:12`,不再显示 `12:12`;正午仍显示 `12:12`。24小时制及额度重置时间的系统格式保持不变。
7
+ - 菜单新增“开机启动”,默认关闭;手动开启后,登录当前macOS用户会自动打开浮窗。关闭取消后续登录启动,不结束当前浮窗。
8
+ - 使用独立的用户级LaunchAgent,无需管理员权限,不修改官方应用。原时区、位置、提醒及更新设置继续保留。
9
+
3
10
  ## v0.3.3(2026-10-20,America/Los_Angeles)
4
11
 
5
12
  - 改为只请求一次 `https://ipinfo.io/json`,同时获取当前网络出口的公网IP、城市和时区;继续支持环境及系统HTTPS代理。
package/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
 
5
5
  需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
6
6
 
7
- ## v0.3.3 更新说明
7
+ ## v0.3.4 更新说明
8
8
 
9
- - 改为只请求一次 `https://ipinfo.io/json`,同时获取当前网络出口的公网IP、城市和时区;继续支持环境及系统HTTPS代理。
10
- - 跟随IP时区时,浮窗时间下方显示接口返回的城市名称,例如 `Los Angeles`,不再显示“IP时区”;时间仍按接口返回的时区计算。
11
- - 城市名称居中,最大宽度不超过时间文字的实际宽度,过长自动缩小字号。
12
- - 获取不到IP或有效时区时继续显示自定义时区时间;城市缺失显示“城市未知”。不改变已保存的时区、位置和开关。
9
+ - 12小时制按所选时区显示五个时段:00:00–06:00 凌晨、06:00–12:00 上午、12:00–18:00 下午、18:00–21:00 晚上、21:00–24:00 深夜。
10
+ - 零点显示 `00:12`,不再显示 `12:12`;正午仍显示 `12:12`。24小时制及额度重置时间的系统格式保持不变。
11
+ - 菜单新增“开机启动”,默认关闭;手动开启后,登录当前macOS用户会自动打开浮窗。关闭取消后续登录启动,不结束当前浮窗。
12
+ - 使用独立的用户级LaunchAgent,无需管理员权限,不修改官方应用。原时区、位置、提醒及更新设置继续保留。
13
13
 
14
14
  历史版本更新记录见 [CHANGELOG](CHANGELOG.md)。
15
15
 
@@ -105,3 +105,11 @@ IP地理库的城市与时区可能存在偏差或互相不一致;显示接口
105
105
  菜单开启“跟随IP时区”后,时钟按地理接口返回的IANA时区显示当地时间,自动处理夏令时,继续跟随系统12/24小时制;时钟下方显示IP返回的城市名称,宽度不超过时间文字,手动时区选择隐藏。IP每5分钟刷新或点击IP菜单刷新,时区同步更新。
106
106
 
107
107
  关闭后恢复之前手动选择的城市和时区,并重新显示选择菜单。取不到IP或有效时区时,时钟回退到手动设置的时区,菜单提示“IP时区不可用,显示自定义时间”;开关仍开启,获取成功后继续跟随。开关和手动设置跨重启/更新保存,不保存IP历史。IP地理数据可能不准确,跟随的是出口时区,不修改电脑系统时区。
108
+
109
+ ## 开机启动与12小时时段
110
+
111
+ 从菜单勾选“开机启动”后,在登录当前macOS用户时自动运行本工具的 `show`,默认关闭,不会自动登录系统或打开官方Codex/Claude应用。关闭仅取消下次登录启动,当前浮窗继续运行。系统若禁止此后台项目,则需在系统设置中允许。
112
+
113
+ 登录配置保存当前Node/npm安装路径,常规原前缀npm更新可继续使用;删除或迁移Node/npm目录后,从新安装打开浮窗并关闭再开启此选项以更新路径。
114
+
115
+ 12小时制时段按时钟所选时区计算;跟随IP时使用有效IP时区,获取失败沿用自定义时间。浮窗、城市菜单和辅助文本使用相同五时段,Codex上方小字独立显示时段,Claude沿用单行时间。零点如“凌晨 00:12”、正午如“下午 12:12”;24小时制不增加时段文字,额度重置时刻继续使用系统格式。
@@ -187,11 +187,30 @@ func resetDescription(_ resetsAt: Double?, weekly: Bool, now: Date = Date(), zon
187
187
  return "\(duration)后 \(time) 重置"
188
188
  }
189
189
 
190
+ func clockPeriod(at date: Date, zone: TimeZone) -> String {
191
+ var calendar = Calendar(identifier: .gregorian)
192
+ calendar.timeZone = zone
193
+ switch calendar.component(.hour, from: date) {
194
+ case 0..<6: return "凌晨"
195
+ case 6..<12: return "上午"
196
+ case 12..<18: return "下午"
197
+ case 18..<21: return "晚上"
198
+ default: return "深夜"
199
+ }
200
+ }
201
+
190
202
  func clockText(at date: Date, zone: TimeZone, locale: Locale = .autoupdatingCurrent) -> String {
191
203
  let formatter = DateFormatter()
192
204
  formatter.locale = locale
193
205
  formatter.timeZone = zone
194
206
  formatter.setLocalizedDateFormatFromTemplate("jm")
207
+ if locale.hourCycle == .oneToTwelve || locale.hourCycle == .zeroToEleven {
208
+ var calendar = Calendar(identifier: .gregorian)
209
+ calendar.timeZone = zone
210
+ formatter.locale = Locale(identifier: "en_US_POSIX")
211
+ formatter.dateFormat = calendar.component(.hour, from: date) == 0 ? "HH:mm" : "h:mm"
212
+ return "\(clockPeriod(at: date, zone: zone)) \(formatter.string(from: date))"
213
+ }
195
214
  return formatter.string(from: date)
196
215
  }
197
216
 
@@ -290,6 +309,29 @@ struct AvailabilityReminder: Codable {
290
309
  }
291
310
  func reminderWindows(_ windows: [UsageWindow]) -> [UsageWindow] { windows.filter { ["five_hour:primary", "seven_day:primary"].contains($0.id) } }
292
311
 
312
+ enum LoginStartup {
313
+ static let label = "com.unionschool.easy-claude.login"
314
+ static var file: URL {
315
+ FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/LaunchAgents/" + label + ".plist")
316
+ }
317
+ static func enabled(at file: URL = file) -> Bool { FileManager.default.fileExists(atPath: file.path) }
318
+ static func setEnabled(_ enabled: Bool, node: String, cli: String, environment: [String: String], at file: URL = file) throws {
319
+ if !enabled {
320
+ if self.enabled(at: file) { try FileManager.default.removeItem(at: file) }
321
+ return
322
+ }
323
+ guard node.hasPrefix("/"), cli.hasPrefix("/"),
324
+ FileManager.default.isExecutableFile(atPath: node), FileManager.default.fileExists(atPath: cli) else {
325
+ throw NSError(domain: label, code: 1, userInfo: [NSLocalizedDescriptionKey: "启动路径无效,请从正式安装的命令重新打开浮窗"])
326
+ }
327
+ let config: [String: Any] = ["Label": label, "ProgramArguments": [node, cli, "show"],
328
+ "RunAtLoad": true, "EnvironmentVariables": environment]
329
+ let data = try PropertyListSerialization.data(fromPropertyList: config, format: .xml, options: 0)
330
+ try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)
331
+ try data.write(to: file, options: .atomic)
332
+ }
333
+ }
334
+
293
335
  @MainActor
294
336
  final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNotificationCenterDelegate {
295
337
  let panel = NSPanel(contentRect: CGRect(x: 0, y: 0, width: 32, height: 32),
@@ -664,9 +706,27 @@ final class Overlay: NSObject, NSApplicationDelegate, NSMenuDelegate, UNUserNoti
664
706
  menu.addItem(automatic)
665
707
  if let automaticUpdateError { menu.addItem(item(automaticUpdateError, nil)) }
666
708
  if let versionCheckError { menu.addItem(item(versionCheckError, nil)) }
709
+ let startup = item("开机启动", #selector(toggleLoginStartup))
710
+ startup.state = LoginStartup.enabled() ? .on : .off
711
+ startup.toolTip = "登录当前macOS用户后自动打开浮窗"
712
+ menu.addItem(startup)
667
713
  menu.addItem(item("退出浮窗", #selector(quit)))
668
714
  return menu
669
715
  }
716
+ @objc func toggleLoginStartup() {
717
+ do {
718
+ let cli = URL(fileURLWithPath: script).deletingLastPathComponent().deletingLastPathComponent()
719
+ .appendingPathComponent("bin/easy-claude.js").path
720
+ let environment = ["PATH": searchPath]
721
+
722
+ try LoginStartup.setEnabled(!LoginStartup.enabled(), node: node, cli: cli, environment: environment)
723
+ } catch {
724
+ let alert = NSAlert()
725
+ alert.messageText = "无法设置开机启动"
726
+ alert.informativeText = error.localizedDescription
727
+ alert.runModal()
728
+ }
729
+ }
670
730
  func menuNeedsUpdate(_ menu: NSMenu) {
671
731
  menu.removeAllItems()
672
732
  let fresh = makeMenu()
@@ -882,6 +942,39 @@ struct Main {
882
942
  precondition(ipClockTest.update("Asia/Singapore"))
883
943
  precondition(ipClockTest.resolved(manual: manualIPTest, following: true).identifier == "Asia/Singapore")
884
944
  _ = NSApplication.shared
945
+ let periodZone = TimeZone(secondsFromGMT: 0)!
946
+ for (minutes, expected) in [(0,"凌晨"),(359,"凌晨"),(360,"上午"),(719,"上午"),(720,"下午"),(1079,"下午"),(1080,"晚上"),(1259,"晚上"),(1260,"深夜"),(1439,"深夜")] {
947
+ let date = Date(timeIntervalSince1970: Double(minutes * 60))
948
+ precondition(clockPeriod(at: date, zone: periodZone) == expected)
949
+ precondition(clockText(at: date, zone: periodZone, locale: Locale(identifier: "en_US")).contains(expected))
950
+ }
951
+ let midnight = Date(timeIntervalSince1970: 12 * 60)
952
+ precondition(clockText(at: midnight, zone: periodZone, locale: Locale(identifier: "en_US")) == "凌晨 00:12")
953
+ precondition(clockText(at: midnight, zone: periodZone, locale: Locale(identifier: "en_GB")) == "00:12")
954
+ precondition(clockText(at: Date(timeIntervalSince1970: 12 * 3600 + 12 * 60), zone: periodZone, locale: Locale(identifier: "en_US")) == "下午 12:12")
955
+ precondition(clockPeriod(at: midnight, zone: TimeZone(identifier: "Asia/Shanghai")!) == "上午")
956
+ let startupTest = FileManager.default.temporaryDirectory.appendingPathComponent("easy-startup-" + UUID().uuidString)
957
+ let startupFile = startupTest.appendingPathComponent("launch.plist")
958
+ do {
959
+ defer { try? FileManager.default.removeItem(at: startupTest) }
960
+ precondition(!LoginStartup.enabled(at: startupFile))
961
+ try FileManager.default.createDirectory(at: startupTest, withIntermediateDirectories: true)
962
+ let cli = startupTest.appendingPathComponent("tool with spaces.js")
963
+ try Data().write(to: cli)
964
+ try LoginStartup.setEnabled(true, node: "/usr/bin/true", cli: cli.path, environment: ["PATH":"/usr/bin"], at: startupFile)
965
+ precondition(LoginStartup.enabled(at: startupFile))
966
+ let config = try PropertyListSerialization.propertyList(from: Data(contentsOf: startupFile), options: [], format: nil) as! [String: Any]
967
+ precondition(config["ProgramArguments"] as? [String] == ["/usr/bin/true", cli.path, "show"])
968
+ precondition(config["RunAtLoad"] as? Bool == true && config["KeepAlive"] == nil)
969
+ try LoginStartup.setEnabled(false, node: "", cli: "", environment: [:], at: startupFile)
970
+ precondition(!LoginStartup.enabled(at: startupFile))
971
+ do {
972
+ try LoginStartup.setEnabled(true, node: "relative", cli: cli.path, environment: [:], at: startupFile)
973
+ preconditionFailure("无效启动路径不得保存")
974
+ } catch { precondition(!LoginStartup.enabled(at: startupFile)) }
975
+ } catch { preconditionFailure("登录启动配置测试失败:\(error)") }
976
+ print("12小时时段边界、零点/正午及登录启动开关自检通过")
977
+
885
978
  for time in ["8:52", "12:59", "上午8:52"] {
886
979
  let font = fittedClockFont(for: time, width: 96, baseSize: 20)
887
980
  let width = (time as NSString).size(withAttributes: [.font: font]).width
@@ -957,13 +1050,13 @@ struct Main {
957
1050
  let afternoon = ISO8601DateFormatter().date(from: "2026-10-21T14:30:00Z")!
958
1051
  for identifier in ["en_US", "en_GB", "zh_CN"] {
959
1052
  let text = clockText(at: afternoon, zone: countdownUTC, locale: Locale(identifier: identifier))
960
- if identifier == "en_US" { precondition(text.contains("PM") && !text.contains("14:30")) }
1053
+ if identifier == "en_US" { precondition(text.contains("下午") && !text.contains("14:30")) }
961
1054
  else { precondition(text == "14:30") }
962
1055
  let font = fittedClockFont(for: text, width: 96, baseSize: 20)
963
1056
  precondition((text as NSString).size(withAttributes: [.font: font]).width <= 96 - 1)
964
1057
  }
965
1058
  let laClock = clockText(at: afternoon, zone: TimeZone(identifier: "America/Los_Angeles")!, locale: Locale(identifier: "en_US"))
966
- precondition(laClock.contains("7:30") && laClock.contains("AM"))
1059
+ precondition(laClock.contains("7:30") && laClock.contains("上午"))
967
1060
 
968
1061
  let morning = ISO8601DateFormatter().date(from: "2026-10-21T02:30:00Z")!
969
1062
  for weekly in [false, true] {
@@ -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.3.3</string>
8
+ <key>CFBundleShortVersionString</key><string>0.3.4</string>
9
9
  <key>LSMinimumSystemVersion</key><string>14.0</string>
10
10
  <key>LSUIElement</key><true/>
11
11
  <key>NSHighResolutionCapable</key><true/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-claude",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Claude Code quota rings and transparent world clock for Claude desktop",
5
5
  "type": "module",
6
6
  "bin": {