diff --git a/src/commands/refreshAll/registerRefreshAllCommand.ts b/src/commands/refreshAll/registerRefreshAllCommand.ts index 5427f778..0b7478e9 100644 --- a/src/commands/refreshAll/registerRefreshAllCommand.ts +++ b/src/commands/refreshAll/registerRefreshAllCommand.ts @@ -4,10 +4,11 @@ import { StateManager } from '../../StateManager' import { UsagesTreeProvider } from '../../views/usages' import { EnvironmentsTreeProvider } from '../../views/environments' import { InspectorViewProvider } from '../../views/inspector' +import { HomeViewProvider } from '../../views/home' export async function registerRefreshAllCommand( context: vscode.ExtensionContext, - providers: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider)[] + providers: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider | HomeViewProvider)[] ) { context.subscriptions.push( vscode.commands.registerCommand( diff --git a/src/extension.ts b/src/extension.ts index c4663f6e..c0c6d5e3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode' import * as path from 'path' import { KEYS, StateManager } from './StateManager' -import { AuthCLIController, BaseCLIController, getOrganizationId } from './cli' +import { BaseCLIController, getOrganizationId } from './cli' import { getHoverString } from './components/hoverCard' import { trackRudderstackEvent } from './RudderStackService' import { registerStartupViewProvider } from './views/startup' @@ -10,9 +10,8 @@ import { registerLoginViewProvider } from './views/login' import { UsagesTreeProvider, registerUsagesViewProvider } from './views/usages' import { EnvironmentsTreeProvider, registerEnvironmentsViewProvider } from './views/environments' import { registerResourcesViewProvider } from './views/resources' -import { registerHomeViewProvider } from './views/home' +import { HomeViewProvider, registerHomeViewProvider } from './views/home' import { - executeRefreshAllCommand, registerRefreshAllCommand, registerInitCommand, registerUsagesNodeClickedCommand, @@ -72,14 +71,15 @@ export const activate = async (context: vscode.ExtensionContext) => { const { usagesDataProvider, usagesTreeView } = await registerUsagesViewProvider(context) const environmentsDataProvider = await registerEnvironmentsViewProvider(context) const inspectorViewProvider = await registerInspectorViewProvider(context) - const refreshProviders: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider)[] = [ - usagesDataProvider, + const homeViewProvider = await registerHomeViewProvider(context) + const refreshProviders: (UsagesTreeProvider | EnvironmentsTreeProvider | InspectorViewProvider | HomeViewProvider)[] = [ + usagesDataProvider, environmentsDataProvider, - inspectorViewProvider + inspectorViewProvider, + homeViewProvider ] await registerResourcesViewProvider(context) - await registerHomeViewProvider(context) await registerOpenInspectorViewCommand(context, inspectorViewProvider) await registerUsagesNodeClickedCommand(context) await registerInitCommand(context) diff --git a/src/views/home/HomeViewProvider.ts b/src/views/home/HomeViewProvider.ts index 2bab1467..13c5a7b4 100644 --- a/src/views/home/HomeViewProvider.ts +++ b/src/views/home/HomeViewProvider.ts @@ -17,11 +17,18 @@ type HomeViewMessage = export class HomeViewProvider implements vscode.WebviewViewProvider { _view?: vscode.WebviewView _doc?: vscode.TextDocument + isRefreshing: boolean = false + webviewIsDisposed: boolean = false + constructor(private readonly _extensionUri: vscode.Uri) {} public async resolveWebviewView(webviewView: vscode.WebviewView) { this._view = webviewView + webviewView.onDidDispose(() => { + this.webviewIsDisposed = true + }) + webviewView.webview.options = { enableScripts: true, @@ -55,7 +62,6 @@ export class HomeViewProvider implements vscode.WebviewViewProvider { const organizationsController = new OrganizationsCLIController(folder) await organizationsController.selectOrganization(data.value, false) await executeRefreshAllCommand() - webviewView.webview.html = await this._getHtmlForWebview(webviewView.webview) }) } else if (data.type === 'project') { const projectsController = new ProjectsCLIController(folder) @@ -77,12 +83,39 @@ export class HomeViewProvider implements vscode.WebviewViewProvider { } } }) + + this.webviewIsDisposed = false } public revive(panel: vscode.WebviewView) { this._view = panel } + public async refreshAll() { + if (this.isRefreshing) { + return + } + + this.isRefreshing = true + + await vscode.window.withProgress( + { + location: { viewId: 'devcycle-home' }, + }, + async () => { + if (!this._view || this.webviewIsDisposed) { + return + } + this._view.webview.html = await this._getHtmlForWebview(this._view.webview) + } + ) + this.isRefreshing = false + } + + public async refresh() { + await this.refreshAll() + } + private async getBodyHtml(folder: vscode.WorkspaceFolder, showHeader?: boolean): Promise { const organizationsController = new OrganizationsCLIController(folder) const projectsController = new ProjectsCLIController(folder)