From b0b697d31a6ee3fa242c8d80a2c918c9f35708c6 Mon Sep 17 00:00:00 2001 From: zhangyi <1401457589@qq.com> Date: Thu, 27 Apr 2023 14:08:45 +0800 Subject: [PATCH] fix: plugin doesn't show welcome view (#12458) The commit check view data provider after start plugin to show plugin welcom view. Signed-off-by: zhangyi <1401457589@qq.com> --- .../src/hosted/browser/hosted-plugin.ts | 3 ++ .../main/browser/view/plugin-view-registry.ts | 39 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index 836ec55af78cc..ff818ed28da52 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -303,6 +303,9 @@ export class HostedPluginSupport { } await this.startPlugins(contributionsByHost, toDisconnect); + // check data provider after start plugin to show welcom view + this.viewRegistry.checkViewDataProvider(); + this.deferredDidStart.resolve(); this.restoreWebviews(); diff --git a/packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts b/packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts index 16283f6f0cf6a..500d690838a96 100644 --- a/packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts +++ b/packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts @@ -780,19 +780,48 @@ export class PluginViewRegistry implements FrontendApplicationContribution { return toDispose; } + checkViewDataProvider(): void { + for (const viewId of this.views.keys()) { + if (!this.viewDataProviders.has(viewId)) { + this.getView(viewId).then(async view => { + if (view) { + if (view.isVisible) { + await this.prepareView(view); + } else { + const toDisposeOnDidExpandView = new DisposableCollection(this.onDidExpandView(async id => { + if (id === viewId) { + unsubscribe(); + await this.prepareView(view); + } + })); + const unsubscribe = () => toDisposeOnDidExpandView.dispose(); + view.disposed.connect(unsubscribe); + toDisposeOnDidExpandView.push(Disposable.create(() => view.disposed.disconnect(unsubscribe))); + } + } + }); + } + } + } + protected async createViewDataWidget(viewId: string, webviewId?: string): Promise { const view = this.views.get(viewId); if (view?.[1]?.type === PluginViewType.Webview) { const webviewWidget = this.widgetManager.getWidget(WebviewWidget.FACTORY_ID, { id: webviewId }); return webviewWidget; } - const provider = this.viewDataProviders.get(viewId); - if (!view || !provider) { + if (!view) { return undefined; } - const [, viewInfo] = view; - const state = this.viewDataState.get(viewId); - const widget = await provider({ state, viewInfo }); + let widget; + const provider = this.viewDataProviders.get(viewId); + if (!provider) { + widget = await this.widgetManager.getOrCreateWidget(PLUGIN_VIEW_DATA_FACTORY_ID, { id: viewId }); + } else { + const [, viewInfo] = view; + const state = this.viewDataState.get(viewId); + widget = await provider({ state, viewInfo }); + } widget.handleViewWelcomeContentChange(this.getViewWelcomes(viewId)); if (StatefulWidget.is(widget)) { this.storeViewDataStateOnDispose(viewId, widget);