diff options
Diffstat (limited to 'src/vs/workbench/contrib/webview/browser/overlayWebview.ts')
-rw-r--r-- | src/vs/workbench/contrib/webview/browser/overlayWebview.ts | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/vs/workbench/contrib/webview/browser/overlayWebview.ts b/src/vs/workbench/contrib/webview/browser/overlayWebview.ts index bb25dfdc171..112efec0ac3 100644 --- a/src/vs/workbench/contrib/webview/browser/overlayWebview.ts +++ b/src/vs/workbench/contrib/webview/browser/overlayWebview.ts @@ -21,7 +21,8 @@ export class OverlayWebview extends Disposable implements IOverlayWebview { private readonly _onDidWheel = this._register(new Emitter<IMouseWheelEvent>()); public readonly onDidWheel = this._onDidWheel.event; - private readonly _pendingMessages = new Set<{ readonly message: any; readonly transfer?: readonly ArrayBuffer[] }>(); + private _isFirstLoad = true; + private readonly _firstLoadPendingMessages = new Set<{ readonly message: any; readonly transfer?: readonly ArrayBuffer[]; readonly resolve: (value: boolean) => void }>(); private readonly _webview = this._register(new MutableDisposable<IWebviewElement>()); private readonly _webviewEvents = this._register(new DisposableStore()); @@ -70,6 +71,11 @@ export class OverlayWebview extends Disposable implements IOverlayWebview { this._container?.remove(); this._container = undefined; + for (const msg of this._firstLoadPendingMessages) { + msg.resolve(false); + } + this._firstLoadPendingMessages.clear(); + this._onDidDispose.fire(); super.dispose(); @@ -200,8 +206,13 @@ export class OverlayWebview extends Disposable implements IOverlayWebview { this._onDidUpdateState.fire(state); })); - this._pendingMessages.forEach(msg => webview.postMessage(msg.message, msg.transfer)); - this._pendingMessages.clear(); + if (this._isFirstLoad) { + this._firstLoadPendingMessages.forEach(async msg => { + msg.resolve(await webview.postMessage(msg.message, msg.transfer)); + }); + } + this._isFirstLoad = false; + this._firstLoadPendingMessages.clear(); } this.container.style.visibility = 'visible'; @@ -268,12 +279,19 @@ export class OverlayWebview extends Disposable implements IOverlayWebview { private readonly _onMissingCsp = this._register(new Emitter<ExtensionIdentifier>()); public readonly onMissingCsp: Event<any> = this._onMissingCsp.event; - public postMessage(message: any, transfer?: readonly ArrayBuffer[]): void { + public async postMessage(message: any, transfer?: readonly ArrayBuffer[]): Promise<boolean> { if (this._webview.value) { - this._webview.value.postMessage(message, transfer); - } else { - this._pendingMessages.add({ message, transfer }); + return this._webview.value.postMessage(message, transfer); } + + if (this._isFirstLoad) { + let resolve: (x: boolean) => void; + const p = new Promise<boolean>(r => resolve = r); + this._firstLoadPendingMessages.add({ message, transfer, resolve: resolve! }); + return p; + } + + return false; } focus(): void { this._webview.value?.focus(); } |