Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for WebviewPanelSerializer not working in Theia #12854

Merged
merged 4 commits into from
Aug 24, 2023
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
23 changes: 9 additions & 14 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ export class HostedPluginSupport {
await this.startPlugins(contributionsByHost, toDisconnect);

this.deferredDidStart.resolve();

this.restoreWebviews();
}

/**
Expand Down Expand Up @@ -757,14 +755,18 @@ export class HostedPluginSupport {
return `${plugins} plugin${plugins === 1 ? '' : 's'}`;
}

protected readonly webviewsToRestore = new Set<WebviewWidget>();
protected readonly webviewsToRestore = new Map<string, WebviewWidget>();
protected readonly webviewRevivers = new Map<string, (webview: WebviewWidget) => Promise<void>>();

registerWebviewReviver(viewType: string, reviver: (webview: WebviewWidget) => Promise<void>): void {
if (this.webviewRevivers.has(viewType)) {
throw new Error(`Reviver for ${viewType} already registered`);
}
this.webviewRevivers.set(viewType, reviver);

if (this.webviewsToRestore.has(viewType)) {
this.restoreWebview(this.webviewsToRestore.get(viewType) as WebviewWidget);
}
}

unregisterWebviewReviver(viewType: string): void {
Expand All @@ -785,21 +787,14 @@ export class HostedPluginSupport {
}

protected preserveWebview(webview: WebviewWidget): void {
if (!this.webviewsToRestore.has(webview)) {
this.webviewsToRestore.add(webview);
webview.disposed.connect(() => this.webviewsToRestore.delete(webview));
}
}

protected restoreWebviews(): void {
for (const webview of this.webviewsToRestore) {
this.restoreWebview(webview);
if (!this.webviewsToRestore.has(webview.viewType)) {
this.activateByEvent(`onWebviewPanel:${webview.viewType}`);
this.webviewsToRestore.set(webview.viewType, webview);
webview.disposed.connect(() => this.webviewsToRestore.delete(webview.viewType));
}
this.webviewsToRestore.clear();
}

protected async restoreWebview(webview: WebviewWidget): Promise<void> {
await this.activateByEvent(`onWebviewPanel:${webview.viewType}`);
const restore = this.webviewRevivers.get(webview.viewType);
if (restore) {
try {
Expand Down