Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a manual refresh button to the GitHub Copilot Token Tracker extension's details panel, allowing users to update the token statistics on demand instead of waiting for the automatic 5-minute update cycle.
Key changes:
- Enables JavaScript execution in the webview to support interactive functionality
- Adds message handling between the webview and extension for refresh commands
- Implements a styled refresh button with click handler in the details panel
| await this.updateTokenStats(); | ||
| const stats = await this.calculateDetailedStats(); |
There was a problem hiding this comment.
The refreshDetailsPanel method calls both updateTokenStats() and calculateDetailedStats() sequentially. Since updateTokenStats() already calls calculateDetailedStats() internally, this results in redundant computation. Remove the separate calculateDetailedStats() call and use the stats from updateTokenStats().
| await this.updateTokenStats(); | |
| const stats = await this.calculateDetailedStats(); | |
| const stats = await this.updateTokenStats(); | |
| <script> | ||
| const vscode = acquireVsCodeApi(); | ||
|
|
||
| function refreshData() { | ||
| // Send message to extension to refresh data | ||
| vscode.postMessage({ command: 'refresh' }); | ||
| } | ||
| </script> |
There was a problem hiding this comment.
The inline script lacks Content Security Policy considerations. Consider moving the script to a separate function or implementing proper CSP headers to prevent potential XSS vulnerabilities in the webview context.
This pull request enhances the Copilot token usage details panel by allowing users to manually refresh the displayed statistics. It introduces a new "Refresh Now" button in the panel UI, updates the webview to support script execution, and handles communication between the webview and the extension for real-time updates.
User interface improvements:
.refresh-buttonclass). [1] [2]Webview and extension integration:
refreshDetailsPanelmethod to update token stats and refresh the webview content when requested.