Skip to content

新增 DeepSeek / GLM 余额显示、菜单栏分段开关与应用内设置窗口 - #2

Open
RichardYi-SYSU wants to merge 6 commits into
wjx8:mainfrom
RichardYi-SYSU:feature/remote-balances-settings
Open

RichardYi-SYSU wants to merge 6 commits into
wjx8:mainfrom
RichardYi-SYSU:feature/remote-balances-settings

Conversation

@RichardYi-SYSU

Copy link
Copy Markdown

概述

在原有 Codex 额度显示的基础上,菜单栏现在可以同时展示 DeepSeek 与智谱 GLM 的账户余额;菜单栏三段内容支持在状态菜单中勾选显隐;新增应用内设置窗口管理 API Key 与刷新间隔。全部配置存于本机 UserDefaults,源码与构建产物不再包含任何密钥(已核查全部历史对象)。

菜单栏三段余额 下拉菜单:分段开关 + 设置入口
菜单栏余额 下拉菜单
设置窗口(Key 脱敏回显 + 刷新间隔) 余额刷新 11 档预设
设置窗口 刷新档位

新增功能

1. 多模型余额显示

  • 菜单栏标题在 Codex 额度(5h / 周限额)右侧追加 DS xx.xx¥GLM xx.xx¥
  • DeepSeek 走官方 GET /user/balance(Bearer 认证),优先显示 CNY 余额
  • 智谱 GLM 走 BigModel 控制台账务接口(www.bigmodel.cn/api/biz/account/query-customer-account-report;旧的 open.bigmodel.cn/api/paas/v4/users/me/balance 已 404 下线)
  • 刷新失败保留上一次成功数值;Key 未配置或尚未成功时显示 DS --¥ / GLM --¥

2. 菜单栏分段开关

  • 状态菜单新增三个勾选项(HIG checkmark 样式):菜单栏显示 Codex 用量 / DS 余额 / GLM 余额
  • 开关状态持久化 UserDefaults(menubar.show*),默认全显,重启保留

3. 应用内设置窗口(设置… ⌘,)

  • API Key 圆点脱敏输入 + 尾号回显(已保存:···a4f5);保存后立即生效,无需重新构建
  • Key 持久化 UserDefaults(本机),不再硬编码进二进制
  • 刷新间隔可配置:额度刷新 30秒 / 1 / 2 / 5 分钟;余额刷新 1 / 2 / 3 / 4 / 5 / 10 / 15 / 20 / 25 / 30 / 60 分钟;保存即时重建定时器并立即刷新
  • 非预设值(如经 defaults write 写入)回显为额外档位,不会被吞掉

4. 菜单栏交互修复

  • 状态菜单与状态项等宽对齐(minimumWidth 跟随状态项宽度),显示分段增减时不再左右偏移
  • 菜单顶边与菜单栏底边齐平;外观跟随系统深浅色模式
  • 修复菜单实例复用导致的滚动残留:再次打开时首项被菜单栏遮住、行位上移一格,容易误点相邻项(曾导致点击「设置…」实际命中「退出」)
  • 设置窗口:长 Key 单行滚动不换行、保存后自动关窗、窗口居中打开

测试

  • 本机 Apple Silicon / macOS 26 构建通过,GUI 全流程验证(开菜单、勾选分段、改档位、保存关窗)
  • 余额接口以真实 Key 实测:DeepSeek 200 OK(CNY 余额正确);GLM 200 OK(availableBalance 正确)
  • 解析器离线用例:DeepSeek CNY / 仅 USD / 错误响应;GLM 新旧两种响应形状 / 错误响应
  • Key 安全:git grep 全历史对象检索确认无密钥残留

注意事项

  • Key 以明文存储在本机 UserDefaults(个人工具可接受;未进 git)
  • GLM 余额接口为控制台域名的非公开文档接口,智谱改版可能失效(届时显示保留旧值)
  • 涉及私有 Touch Bar API 的部分不在本分支改动范围内(上游原有代码)

- RemoteBalanceStore polls DeepSeek /user/balance and the BigModel CN
  account report endpoint; API keys live in UserDefaults (set via the
  in-app settings window), never in source or build products.
- Menu bar title adapts to content width and renders Codex quota, DS and
  GLM balance segments; checkmark menu toggles show/hide each segment.
- Settings window (设置…, ⌘,) edits keys with masked echo and saves them
  with instant effect.
- Status item now pops its menu manually so the menu's horizontal center
  tracks the item center regardless of which balance segments are shown.
- Secure key fields set cell wraps=false + scrollable so long keys scroll
  on one line instead of wrapping dots to a second line.
- 保存 now closes the settings window after persisting; the window also
  opens centered instead of cascading to the bottom-left.
- popUp(in:) made the menu inherit the status bar button's dark-tinted
  appearance, rendering dark menus in light mode; pin the menu to
  NSApp.effectiveAppearance so light/dark system modes both render with
  the standard menu material (HIG: menus follow the system appearance).
- Drop the 3pt vertical offset so the menu's top edge sits flush with
  the bottom of the menu bar.
The manual popUp presentation rendered with the wrong (dark) appearance,
sat 9pt inside the menu bar, and could reopen pre-scrolled with the first
item hidden under the bar. Go back to the system-anchored presentation,
which guarantees correct light/dark materials and flush placement, and
achieve stable centering by pinning menu.minimumWidth to the status item
width in menuNeedsUpdate (equal width + left anchor = visually centered).

Settings window: secure fields scroll long keys on one line instead of
wrapping dots; 保存 closes the window; the window opens centered.
- New AppSettings: refresh intervals persist in UserDefaults
  (interval.quotaSeconds / interval.balanceSeconds) with lower-bound
  clamping; the old hardcoded 60s/600s values remain as fallback defaults.
- Settings window gains 额度刷新 / 余额刷新 pop-up buttons: quota presets
  30s/1/2/5min, balance presets 1/2/3/4/5/10/15/20/25/30/60min per
  request; non-preset values (e.g. written via defaults) are echoed back
  as an extra row instead of being swallowed.
- Both stores rebuild their timer on save (applySettings) and refresh
  immediately, so new intervals take effect without restarting the app.
- defaults write com.wangjiaxuan666.CodexBar interval.* also works
  (picked up on next launch or settings save).
- Settings rows renamed: 额度刷新 → Codex额度刷新间隔, 余额刷新 →
  DS/GLM余额刷新间隔; label column and window widened to fit.
- menuNeedsUpdate now rebuilds the menu items in place: reusing one
  NSMenu instance preserved the previous scroll offset, so reopening
  shifted every row up by one (first item hidden under the menu bar) and
  clicks meant for 设置… could land on 退出.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant