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
28 changes: 22 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class CopilotTokenTracker implements vscode.Disposable {
private lastDetailedStats: DetailedStats | undefined;
private lastDailyStats: DailyTokenStats[] | undefined;
private lastUsageAnalysisStats: UsageAnalysisStats | undefined;
private lastDashboardData: any | undefined;
private tokenEstimators: { [key: string]: number } = tokenEstimatorsData.estimators;
private co2Per1kTokens = 0.2; // gCO2e per 1000 tokens, a rough estimate
private co2AbsorptionPerTreePerYear = 21000; // grams of CO2 per tree per year
Expand Down Expand Up @@ -357,6 +358,7 @@ class CopilotTokenTracker implements vscode.Disposable {
this.lastDetailedStats = undefined;
this.lastDailyStats = undefined;
this.lastUsageAnalysisStats = undefined;
this.lastDashboardData = undefined;

this.log(`Cache cleared successfully. Removed ${cacheSize} entries.`);
vscode.window.showInformationMessage('Cache cleared successfully. Reloading statistics...');
Expand Down Expand Up @@ -4828,20 +4830,33 @@ ${hashtag}`;
this.dashboardPanel = undefined;
});

// Load data asynchronously and send to webview
// If we have cached data, show it immediately so the panel renders fast
if (this.lastDashboardData) {
this.log("📊 Sending cached dashboard data immediately");
this.dashboardPanel.webview.postMessage({
command: "dashboardData",
data: this.lastDashboardData,
});
}

// Load (or refresh) data asynchronously and send to webview
try {
const dashboardData = await this.getDashboardData();
this.lastDashboardData = dashboardData;
this.dashboardPanel?.webview.postMessage({
command: "dashboardData",
data: dashboardData,
});
} catch (error) {
this.error("Failed to load dashboard data:", error);
this.dashboardPanel?.webview.postMessage({
command: "dashboardError",
message:
"Failed to load dashboard data. Please check backend configuration and try again.",
});
// Only show error state when there's no cached data to fall back on
if (!this.lastDashboardData) {
this.dashboardPanel?.webview.postMessage({
command: "dashboardError",
message:
"Failed to load dashboard data. Please check backend configuration and try again.",
});
}
}
}

Expand All @@ -4854,6 +4869,7 @@ ${hashtag}`;
this.dashboardPanel.webview.postMessage({ command: "dashboardLoading" });
try {
const dashboardData = await this.getDashboardData();
this.lastDashboardData = dashboardData;
this.dashboardPanel?.webview.postMessage({
command: "dashboardData",
data: dashboardData,
Expand Down
Loading