Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,40 @@ class CopilotTokenTracker {
preserveFocus: true
},
{
enableScripts: false,
enableScripts: true,
retainContextWhenHidden: false
}
);

// 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<void> {
if (!this.detailsPanel) {
return;
}

// Update token stats and refresh the webview content
await this.updateTokenStats();
const stats = await this.calculateDetailedStats();
Comment on lines +456 to +457
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.
this.detailsPanel.webview.html = this.getDetailsHtml(stats);
}

private getDetailsHtml(stats: DetailedStats): string {
const usedModels = new Set([
...Object.keys(stats.today.modelUsage),
Expand Down Expand Up @@ -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;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -670,8 +711,22 @@ class CopilotTokenTracker {
<div class="footer">
Last updated: ${stats.lastUpdated.toLocaleString()}<br>
Updates automatically every 5 minutes
<br>
<button class="refresh-button" onclick="refreshData()">
<span>🔄</span>
<span>Refresh Now</span>
</button>
</div>
</div>

<script>
const vscode = acquireVsCodeApi();

function refreshData() {
// Send message to extension to refresh data
vscode.postMessage({ command: 'refresh' });
}
</script>
Comment on lines +722 to +729
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.
</body>
</html>`;
}
Expand Down
Loading