diff --git a/vscode-trace-extension/src/extension.ts b/vscode-trace-extension/src/extension.ts index ec739c8..6b93491 100644 --- a/vscode-trace-extension/src/extension.ts +++ b/vscode-trace-extension/src/extension.ts @@ -80,7 +80,7 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI { await startTraceServerIfAvailable(file.fsPath); if (await isTraceServerUp()) { fileOpenHandler(context, file); - vscode.commands.executeCommand('setContext', 'trace-explorer.noExperiments', false); + vscode.commands.executeCommand('trace-explorer.refreshContext'); } }) ); @@ -181,6 +181,7 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI { await startTraceServerIfAvailable(traceUri.fsPath); if (await isTraceServerUp()) { fileOpenHandler(context, traceUri); + serverStatusService.updateServerStatus(true); vscode.commands.executeCommand('setContext', 'trace-explorer.noExperiments', false); } }) @@ -193,24 +194,28 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI { ); context.subscriptions.push( - vscode.commands.registerCommand('serverStatus.started', () => { - serverStatusService.checkAndUpdateServerStatus(); + vscode.commands.registerCommand('serverStatus.started', async () => { + await serverStatusService.updateServerStatus(true); if (tracesProvider) { + // Trigger webview refresh tracesProvider.postMessagetoWebview(VSCODE_MESSAGES.TRACE_SERVER_STARTED, undefined); } + // Refresh so that either trace explorer or welcome page is rendered + updateNoExperimentsContext(); }) ); context.subscriptions.push( - vscode.commands.registerCommand('serverStatus.stopped', () => { - serverStatusService.checkAndUpdateServerStatus(); + vscode.commands.registerCommand('serverStatus.stopped', async () => { + await serverStatusService.updateServerStatus(false); }) ); context.subscriptions.push( vscode.commands.registerCommand('trace-explorer.refreshContext', async () => { + // Refresh so that either trace explorer or welcome page is rendered const isUp = await isTraceServerUp(); - vscode.commands.executeCommand('setContext', 'traceViewer.serverUp', isUp); + await serverStatusService.updateServerStatus(isUp); if (isUp) { await updateNoExperimentsContext(); } @@ -219,9 +224,13 @@ export function activate(context: vscode.ExtensionContext): ExternalAPI { vscode.commands.executeCommand('setContext', 'traceViewer.markerSetsPresent', false); vscode.commands.executeCommand('setContext', 'traceViewer.markerCategoriesPresent', false); - vscode.commands.executeCommand('setContext', 'trace-explorer.noExperiments', true); + + // Initialize noExperiments/serverUp in a way so that trace explorer webviews are initialized + vscode.commands.executeCommand('setContext', 'trace-explorer.noExperiments', false); + vscode.commands.executeCommand('setContext', 'traceViewer.serverUp', true); + + // Refresh to trigger rendering trace explorer or welcome page vscode.commands.executeCommand('trace-explorer.refreshContext'); - serverStatusService.checkAndUpdateServerStatus(); return traceExtensionAPI; } diff --git a/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts index e60a6bf..5e283cd 100644 --- a/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/available-views/trace-explorer-available-views-webview-provider.ts @@ -39,7 +39,7 @@ export class TraceExplorerAvailableViewsProvider extends AbstractTraceExplorerPr const data: any = message.data; switch (command) { case VSCODE_MESSAGES.CONNECTION_STATUS: - if (data && data.status) { + if (data?.status) { const status: boolean = JSON.parse(message.data.status); this._statusService.updateServerStatus(status); } diff --git a/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts b/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts index b9e72b3..69c795f 100644 --- a/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts +++ b/vscode-trace-extension/src/trace-explorer/opened-traces/trace-explorer-opened-traces-webview-provider.ts @@ -65,7 +65,7 @@ export class TraceExplorerOpenedTracesViewProvider extends AbstractTraceExplorer const data: any = message.data; switch (command) { case VSCODE_MESSAGES.CONNECTION_STATUS: - if (data && data.status) { + if (data?.status) { const status: boolean = JSON.parse(message.data.status); this._statusService.updateServerStatus(status); } diff --git a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts index 7a4c298..cc835db 100644 --- a/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts +++ b/vscode-trace-extension/src/trace-viewer-panel/trace-viewer-webview-panel.ts @@ -255,7 +255,8 @@ export class TraceViewerPanel { return; case VSCODE_MESSAGES.CONNECTION_STATUS: if (message.data?.status && this._statusService) { - this._statusService.checkAndUpdateServerStatus(); + const status: boolean = JSON.parse(message.data.status); + this._statusService.updateServerStatus(status); } return; case VSCODE_MESSAGES.SHOW_MARKER_CATEGORIES: diff --git a/vscode-trace-extension/src/utils/trace-server-status.ts b/vscode-trace-extension/src/utils/trace-server-status.ts index 9f1dfc2..8c3e53f 100644 --- a/vscode-trace-extension/src/utils/trace-server-status.ts +++ b/vscode-trace-extension/src/utils/trace-server-status.ts @@ -1,5 +1,6 @@ import { ThemeColor, StatusBarItem } from 'vscode'; import { isTraceServerUp } from './backend-tsp-client-provider'; +import * as vscode from 'vscode'; export class TraceServerConnectionStatusService { private statusBarItem: StatusBarItem; @@ -11,9 +12,14 @@ export class TraceServerConnectionStatusService { public checkAndUpdateServerStatus = async (): Promise => { const isUp = await isTraceServerUp(); - this.render(isUp); + await this.updateServerStatus(isUp); }; + public async updateServerStatus(status: boolean): Promise { + await vscode.commands.executeCommand('setContext', 'traceViewer.serverUp', status); + this.render(status); + } + private render = (status: boolean): void => { if (status) { this.statusBarItem.backgroundColor = new ThemeColor('statusBarItem.warningBackground');