From 389ca91b5ed3adb54a8e5ddb2464f52049260589 Mon Sep 17 00:00:00 2001 From: Rob Bos Date: Sun, 28 Sep 2025 10:51:53 +0200 Subject: [PATCH] button to refresh the data on demand --- src/extension.ts | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 7183ef0..61cb9fa 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -424,7 +424,7 @@ class CopilotTokenTracker { preserveFocus: true }, { - enableScripts: false, + enableScripts: true, retainContextWhenHidden: false } ); @@ -432,12 +432,32 @@ class CopilotTokenTracker { // Set the HTML content this.detailsPanel.webview.html = this.getDetailsHtml(stats); + // Handle messages from the webview + this.detailsPanel.webview.onDidReceiveMessage(async (message) => { + switch (message.command) { + case 'refresh': + await this.refreshDetailsPanel(); + break; + } + }); + // Handle panel disposal this.detailsPanel.onDidDispose(() => { this.detailsPanel = undefined; }); } + private async refreshDetailsPanel(): Promise { + if (!this.detailsPanel) { + return; + } + + // Update token stats and refresh the webview content + await this.updateTokenStats(); + const stats = await this.calculateDetailedStats(); + this.detailsPanel.webview.html = this.getDetailsHtml(stats); + } + private getDetailsHtml(stats: DetailedStats): string { const usedModels = new Set([ ...Object.keys(stats.today.modelUsage), @@ -572,6 +592,27 @@ class CopilotTokenTracker { color: #999999; font-style: italic; } + .refresh-button { + background: #0e639c; + border: 1px solid #1177bb; + color: #ffffff; + padding: 8px 16px; + border-radius: 4px; + cursor: pointer; + font-size: 12px; + font-weight: 500; + margin-top: 12px; + transition: background-color 0.2s; + display: inline-flex; + align-items: center; + gap: 6px; + } + .refresh-button:hover { + background: #1177bb; + } + .refresh-button:active { + background: #0a5a8a; + } @@ -670,8 +711,22 @@ class CopilotTokenTracker { + + `; }