Skip to content

button to refresh the data on demand#16

Merged
rajbos merged 1 commit intomainfrom
refresh-btn
Sep 28, 2025
Merged

button to refresh the data on demand#16
rajbos merged 1 commit intomainfrom
refresh-btn

Conversation

@rajbos
Copy link
Owner

@rajbos rajbos commented Sep 28, 2025

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:

  • Added a "Refresh Now" button to the details panel, including new CSS styles for the button and hover/active states (.refresh-button class). [1] [2]

Webview and extension integration:

  • Enabled scripts in the webview to allow interactive features such as the refresh button.
  • Implemented a message handler in the extension to listen for refresh requests from the webview and trigger a data update.
  • Added a refreshDetailsPanel method to update token stats and refresh the webview content when requested.
  • Injected a script into the webview HTML to post a refresh command to the extension when the button is clicked.

@rajbos rajbos requested a review from Copilot September 28, 2025 08:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +456 to +457
await this.updateTokenStats();
const stats = await this.calculateDetailedStats();
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Suggested change
await this.updateTokenStats();
const stats = await this.calculateDetailedStats();
const stats = await this.updateTokenStats();

Copilot uses AI. Check for mistakes.
Comment on lines +722 to +729
<script>
const vscode = acquireVsCodeApi();

function refreshData() {
// Send message to extension to refresh data
vscode.postMessage({ command: 'refresh' });
}
</script>
Copy link

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@rajbos rajbos merged commit b51b260 into main Sep 28, 2025
9 checks passed
@rajbos rajbos deleted the refresh-btn branch September 28, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments