Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(tray): show GitHub Copilot quota for cards without a usage config

Jason5bef86acc49e
diff --git a/src-tauri/src/commands/provider.rs b/src-tauri/src/commands/provider.rs
index 1efadf661..5a5c4bfc2 100644
--- a/src-tauri/src/commands/provider.rs
+++ b/src-tauri/src/commands/provider.rs
@@ -689,7 +689,10 @@ async fn query_provider_usage_inner(
.unwrap_or("");
// ── GitHub Copilot 专用路径 ──
- if template_type == TEMPLATE_TYPE_GITHUB_COPILOT {
+ // 新建的 Copilot 反代卡不存用量配置(入口已隐藏),按卡认;托盘按同一规则查它(#10106)。
+ let copilot_proxy =
+ app_type != AppType::Copilot && provider.is_some_and(|p| p.is_github_copilot());
+ if template_type == TEMPLATE_TYPE_GITHUB_COPILOT || copilot_proxy {
let copilot_account_id = provider
.and_then(|p| p.meta.as_ref())
.and_then(|m| m.managed_account_id_for(TEMPLATE_TYPE_GITHUB_COPILOT));
diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs
index 9c1369155..87323d54e 100644
--- a/src-tauri/src/tray.rs
+++ b/src-tauri/src/tray.rs
@@ -1172,6 +1172,11 @@ fn tray_usage_source(app_type: &AppType, provider: &Provider) -> Option<TrayUsag
.then_some(TrayUsageSource::AgyAccount(account_id));
}
}
+ // Copilot 反代卡(任意应用下,含聚合成员):卡片底部恒显示 Copilot 额度,这类卡的
+ // 「配置用量查询」入口也已隐藏、存不下开关(#10106),托盘同口径按 Copilot 路径查。
+ if is_copilot_proxy(app_type, provider) {
+ return Some(TrayUsageSource::Script);
+ }
// 绑了托管账号的卡(Codex、Claude 官方、Grok 官方、xAI OAuth)按账号取额度
let bound = match app_type {
// xAI OAuth 卡在哪个应用下都按 xAI 账号取(同卡片),聚合成员也一样(#9899)
@@ -3824,6 +3829,8 @@ const AGY_TRAY_QUOTA_REUSE: std::time::Duration = std::time::Duration::from_secs
/// SuperGrok 账号额度)也是,其余脚本是第三方余额 / 套餐查询。
fn queries_official_account(source: &TrayUsageSource, provider: &Provider) -> bool {
match source {
+ // 没存用量配置的 Copilot 反代卡也查 Copilot 账号(tray_usage_source 只按卡认)
+ TrayUsageSource::Script if provider.is_github_copilot() => true,
TrayUsageSource::Script => provider
.meta
.as_ref()
@@ -3847,6 +3854,9 @@ fn auto_refresh_allowed(
!official_manual_only || !queries_official_account(source, provider)
}
+/// 没存用量配置的 Copilot 反代卡,面板替它补查的间隔(同卡片 `useCopilotQuota` 的轮询间隔)。
+const COPILOT_PANEL_QUERY_MINUTES: u64 = 5;
+
/// 托盘面板发起过的脚本额度查询:(应用, 供应商 id) → 上次查询时间。
static PANEL_SCRIPT_QUERIES: LazyLock<Mutex<HashMap<(AppType, String), std::time::Instant>>> =
LazyLock::new(|| Mutex::new(HashMap::new()));
@@ -3886,6 +3896,10 @@ pub(crate) async fn refresh_panel_provider_usage(app: &tauri::AppHandle) {
.as_ref()
.and_then(|meta| meta.usage_script.as_ref())
.and_then(|script| script.auto_query_interval)
+ // Copilot 反代卡没有用量查询配置(入口已隐藏):照卡片额度的 5 分钟间隔补查
+ .or_else(|| {
+ is_copilot_proxy(app_type, provider).then_some(COPILOT_PANEL_QUERY_MINUTES)
+ })
.unwrap_or(0);
if interval_minutes == 0 {
continue;
diff --git a/src-tauri/src/tray/tests.rs b/src-tauri/src/tray/tests.rs
index c4b5130d6..7158c1721 100644
--- a/src-tauri/src/tray/tests.rs
+++ b/src-tauri/src/tray/tests.rs
@@ -372,6 +372,57 @@ fn script_provider(template_type: &str, provider_type: Option<&str>) -> Provider
.unwrap()
}
+/// #10106:预设新建的 Copilot 反代卡不存用量配置(入口已隐藏),卡片照样显示额度;
+/// 托盘(含聚合成员)也要按 Copilot 路径取,并受「自动查询额度」开关约束。
+#[test]
+fn copilot_proxy_without_usage_config_still_shows_quota_in_tray() {
+ let copilot: Provider = serde_json::from_value(serde_json::json!({
+ "id": "copilot",
+ "name": "GitHub Copilot",
+ "settingsConfig": {},
+ "meta": { "providerType": "github_copilot" }
+ }))
+ .unwrap();
+ for app in [AppType::Codex, AppType::Claude, AppType::GrokBuild] {
+ assert_eq!(
+ tray_usage_source(&app, &copilot),
+ Some(TrayUsageSource::Script)
+ );
+ }
+ assert!(auto_refresh_allowed(
+ &TrayUsageSource::Script,
+ &copilot,
+ false
+ ));
+ assert!(!auto_refresh_allowed(
+ &TrayUsageSource::Script,
+ &copilot,
+ true
+ ));
+
+ // 缓存里有 Copilot 结果时面板行 / 在用行都能读到
+ let cache = UsageCache::new();
+ cache.put_script(
+ AppType::Codex,
+ "copilot".to_string(),
+ UsageResult {
+ success: true,
+ data: Some(vec![UsageData {
+ plan_name: Some("copilot_pro".to_string()),
+ remaining: Some(180.0),
+ total: Some(300.0),
+ used: Some(120.0),
+ unit: Some(COPILOT_UNIT_PREMIUM.to_string()),
+ is_valid: Some(true),
+ invalid_message: None,
+ extra: None,
+ }]),
+ error: None,
+ },
+ );
+ assert!(usage_view(&cache, &zh(), &AppType::Codex, &copilot, "copilot").is_some());
+}
+
#[test]
fn manual_only_quota_skips_official_accounts_but_not_third_party_scripts() {
let any_provider = script_provider("balance", None);