From 5d9171ac5c5f616245debe66f781ba703ba5b236 Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Fri, 24 Nov 2023 12:41:09 +0530 Subject: [PATCH] fixed the issue of second time opening the webview Signed-off-by: msivasubramaniaan --- src/webview/helm-chart/app/index.html | 1 - src/webview/helm-chart/helmChartLoader.ts | 43 +++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/webview/helm-chart/app/index.html b/src/webview/helm-chart/app/index.html index 62aa505e8..148902abd 100644 --- a/src/webview/helm-chart/app/index.html +++ b/src/webview/helm-chart/app/index.html @@ -47,6 +47,5 @@
- diff --git a/src/webview/helm-chart/helmChartLoader.ts b/src/webview/helm-chart/helmChartLoader.ts index 0770d7e5b..f4aa2f173 100644 --- a/src/webview/helm-chart/helmChartLoader.ts +++ b/src/webview/helm-chart/helmChartLoader.ts @@ -134,13 +134,12 @@ function helmChartMessageListener(event: any): void { } export default class HelmChartLoader { - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + static get extensionPath() { return vscode.extensions.getExtension(ExtensionID).extensionPath } - // eslint-disable-next-line @typescript-eslint/require-await - static async loadView(title: string, url?: string): Promise { + static async loadView(title: string): Promise { const localResourceRoot = vscode.Uri.file(path.join(HelmChartLoader.extensionPath, 'out', 'helmChartViewer')); if (panel) { // If we already have a panel, show it in the target column @@ -154,10 +153,11 @@ export default class HelmChartLoader { }); panel.iconPath = vscode.Uri.file(path.join(HelmChartLoader.extensionPath, 'images/helm/helm.svg')); panel.webview.html = await loadWebviewHtml('helmChartViewer', panel); + const messageDisposable = panel.webview.onDidReceiveMessage(helmChartMessageListener); panel.onDidDispose(() => { + messageDisposable.dispose(); panel = undefined; }); - panel.webview.onDidReceiveMessage(helmChartMessageListener); } await getHelmCharts(); return panel; @@ -170,25 +170,24 @@ export default class HelmChartLoader { } async function getHelmCharts(): Promise { - if (helmCharts.length === 0) { - const cliData = await Helm.getHelmRepos(); - if (!cliData.error && !cliData.stderr) { - const helmRepos = JSON.parse(cliData.stdout) as HelmRepo[]; - void panel?.webview.postMessage( - { - action: 'getHelmRepos', - data: { - helmRepos - } + helmCharts.length = 0; + const cliData = await Helm.getHelmRepos(); + if (!cliData.error && !cliData.stderr) { + const helmRepos = JSON.parse(cliData.stdout) as HelmRepo[]; + void panel?.webview.postMessage( + { + action: 'getHelmRepos', + data: { + helmRepos } - ); - helmRepos.forEach((helmRepo: HelmRepo) => { - let url = helmRepo.url; - url = url.endsWith('/') ? url : url.concat('/'); - url = url.concat('index.yaml'); - void fetchURL(helmRepo, url); - }); - } + } + ); + helmRepos.forEach((helmRepo: HelmRepo) => { + let url = helmRepo.url; + url = url.endsWith('/') ? url : url.concat('/'); + url = url.concat('index.yaml'); + void fetchURL(helmRepo, url); + }); } }