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 @@