diff --git a/README.md b/README.md index faffc9d..29c6b94 100644 --- a/README.md +++ b/README.md @@ -44,27 +44,33 @@ Antigravity 实时测速与官方额度监控侧边栏插件(UI Extension Side git clone https://github.com/yuhuan2498281558/antigravity-usage-monitor.git ~/.gemini/config/plugins/usage-monitor ``` -### 方式三:手动下载 ZIP 解压 +### 方式三:直接下载 Release 安装包 (`usage-monitor.zip`) -1. 点击本仓库右上角的 **Code** -> **Download ZIP**。 -2. 解压到全局插件目录,确保目录结构如下: - - **Windows**: `C:\Users\<你的用户名>\.gemini\config\plugins\usage-monitor\` - - **macOS / Linux**: `~/.gemini/config/plugins/usage-monitor/` - ```text - usage-monitor/ - ├── plugin.json - ├── README.md - ├── assets/ - │ └── logo.svg - └── sidecars/ - └── panel/ - ├── sidecar.json - ├── package.json - ├── main.mjs - ├── index.html - ├── app.js - └── styles.css - ``` +1. 直接点击下载打包好的安装包:**[📦 下载 usage-monitor.zip (Latest Release)](https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip)**(也可在仓库右侧 **[Releases](https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases)** 页面下载)。 +2. 将压缩包解压到全局插件目录 `~/.gemini/config/plugins/` 下(压缩包内已自带 `usage-monitor/` 顶层文件夹): + - **Windows PowerShell 一键下载并解压**: + ```powershell + $pluginsDir = "$env:USERPROFILE\.gemini\config\plugins" + New-Item -ItemType Directory -Path $pluginsDir -Force | Out-Null + Invoke-WebRequest -Uri "https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip" -OutFile "$env:TEMP\usage-monitor.zip" + Expand-Archive -Path "$env:TEMP\usage-monitor.zip" -DestinationPath $pluginsDir -Force + ``` + - 解压后的目录结构如下: + ```text + ~/.gemini/config/plugins/usage-monitor/ + ├── plugin.json + ├── README.md + ├── assets/ + │ └── logo.svg + └── sidecars/ + └── panel/ + ├── sidecar.json + ├── package.json + ├── main.mjs + ├── index.html + ├── app.js + └── styles.css + ``` --- diff --git a/sidecars/panel/app.js b/sidecars/panel/app.js index db8204d..c201643 100644 --- a/sidecars/panel/app.js +++ b/sidecars/panel/app.js @@ -177,14 +177,19 @@ function applyTelemetryToDom(data) { const livePill = $('live-status-pill'); const speedDot = $('speed-dot'); if (active.isRunning) { - livePill.textContent = '生成中…'; - livePill.classList.add('running'); speedDot.classList.add('pulsing'); } else { - livePill.textContent = '实时 2s'; - livePill.classList.remove('running'); speedDot.classList.remove('pulsing'); } + if (!manualRefreshFeedbackTimer) { + if (active.isRunning) { + livePill.textContent = '生成中…'; + livePill.classList.add('running'); + } else { + livePill.textContent = '实时 2s'; + livePill.classList.remove('running'); + } + } // 2. Status strip metrics $('tok-per-sec').textContent = `${Number(active.latestTokPerSec || 0).toFixed(1)} tok/s`; @@ -267,17 +272,64 @@ function applyTelemetryToDom(data) { renderTables(active, data.modelBreakdown); } +let manualRefreshFeedbackTimer = null; + async function refreshTelemetry(force = false) { + const btn = $('refresh-btn'); + const livePill = $('live-status-pill'); + const startMs = Date.now(); + + if (force && btn) { + btn.classList.add('refreshing'); + if (livePill) { + livePill.textContent = '同步中…'; + livePill.classList.remove('running'); + livePill.classList.add('synced'); + } + } + try { const params = new URLSearchParams(); if (selectedConversationId) params.set('conversationId', selectedConversationId); if (force === true) params.set('force', '1'); const qs = params.toString(); const data = await callApi(`/api/telemetry${qs ? `?${qs}` : ''}`); + + if (force) { + const elapsed = Date.now() - startMs; + if (elapsed < 320) { + await new Promise((r) => setTimeout(r, 320 - elapsed)); + } + } + applyTelemetryToDom(data); + + if (force && livePill) { + if (manualRefreshFeedbackTimer) clearTimeout(manualRefreshFeedbackTimer); + livePill.textContent = '✓ 已刷新'; + livePill.classList.remove('running'); + livePill.classList.add('synced'); + manualRefreshFeedbackTimer = setTimeout(() => { + manualRefreshFeedbackTimer = null; + livePill.classList.remove('synced'); + if (latestTelemetry?.activeConversation?.isRunning) { + livePill.textContent = '生成中…'; + livePill.classList.add('running'); + } else { + livePill.textContent = '实时 2s'; + } + }, 1200); + } } catch (err) { console.error('Telemetry refresh failed:', err); - $('live-status-pill').textContent = '连接重试中'; + if (livePill) { + livePill.classList.remove('synced'); + livePill.textContent = '连接重试中'; + } + } finally { + if (force && btn) { + btn.classList.remove('refreshing'); + } } } diff --git a/sidecars/panel/index.html b/sidecars/panel/index.html index ca431bb..5dcad35 100644 --- a/sidecars/panel/index.html +++ b/sidecars/panel/index.html @@ -17,7 +17,9 @@
实时 2s - +
diff --git a/sidecars/panel/styles.css b/sidecars/panel/styles.css index 182b8b1..a9468fc 100644 --- a/sidecars/panel/styles.css +++ b/sidecars/panel/styles.css @@ -108,20 +108,54 @@ body { color: var(--speed-accent); } +.live-pill.synced { + background: color-mix(in srgb, #2563eb 16%, transparent); + color: var(--model-blue); +} + .icon-btn { - padding: 2px 7px; + display: inline-flex; + align-items: center; + justify-content: center; + width: 24px; + height: 22px; + padding: 0; font-size: 13px; - line-height: 1.2; + line-height: 1; color: var(--muted-foreground, #5f6368); background: transparent; border: 1px solid var(--border, #d8dee4); border-radius: 5px; cursor: pointer; + user-select: none; + transition: transform 0.12s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease; } .icon-btn:hover { background: var(--secondary, #eef1f4); color: var(--foreground, #1f2328); + border-color: var(--muted-foreground, #8c959f); +} + +.icon-btn:active { + transform: scale(0.88); +} + +.icon-btn.refreshing { + color: var(--model-blue); + border-color: var(--model-blue); + background: color-mix(in srgb, var(--model-blue) 10%, transparent); + pointer-events: none; +} + +.icon-btn.refreshing .refresh-glyph { + display: inline-block; + animation: spin-refresh 0.55s linear infinite; +} + +@keyframes spin-refresh { + from { transform: rotate(0deg); } + to { transform: rotate(360deg); } } /* 2. Compact Status Strip Card (Left status bar in screenshot) ------------ */