From 5ba0236207a447e2657a34098ea7ac829a823c63 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 2 Sep 2019 15:14:40 +0200 Subject: [PATCH] remove compilerOptions/lib/webworker because it conflicts with lib/dom, #80074 --- src/tsconfig.json | 3 +- .../browser/resourceServiceWorker.ts | 53 ++++++++++++++++++- .../browser/resourceServiceWorkerClient.ts | 13 ----- .../extensions/worker/extensionHostWorker.ts | 3 ++ 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/tsconfig.json b/src/tsconfig.json index 091d1d3acbc..dcff5cff53f 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -9,8 +9,7 @@ "lib": [ "dom", "es5", - "es2015.iterable", - "webworker" + "es2015.iterable" ], "types": [ "keytar", diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts index 3534ef147df..dfad93af11f 100644 --- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts +++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts @@ -5,7 +5,58 @@ import { URI } from 'vs/base/common/uri'; -//https://stackoverflow.com/questions/56356655/structuring-a-typescript-project-with-workers/56374158#56374158 +//#region --- lib.webworker.d.ts madness --- + +interface ExtendableEvent extends Event { + waitUntil(f: any): void; +} + +interface FetchEvent extends ExtendableEvent { + readonly clientId: string; + readonly preloadResponse: Promise; + readonly replacesClientId: string; + readonly request: Request; + readonly resultingClientId: string; + respondWith(r: Response | Promise): void; +} +interface ExtendableMessageEvent extends ExtendableEvent { + readonly data: any; + readonly lastEventId: string; + readonly origin: string; + readonly ports: ReadonlyArray; + readonly source: ServiceWorker | MessagePort | null; +} + +interface ServiceWorkerGlobalScopeEventMap { + 'activate': ExtendableEvent; + 'fetch': FetchEvent; + 'install': ExtendableEvent; + 'message': ExtendableMessageEvent; + 'messageerror': MessageEvent; +} + +interface Clients { + claim(): Promise; + get(id: string): Promise; +} + +interface ServiceWorkerGlobalScope { + readonly clients: Clients; + onactivate: ((this: ServiceWorkerGlobalScope, ev: ExtendableEvent) => any) | null; + onfetch: ((this: ServiceWorkerGlobalScope, ev: FetchEvent) => any) | null; + oninstall: ((this: ServiceWorkerGlobalScope, ev: ExtendableEvent) => any) | null; + onmessage: ((this: ServiceWorkerGlobalScope, ev: ExtendableMessageEvent) => any) | null; + onmessageerror: ((this: ServiceWorkerGlobalScope, ev: MessageEvent) => any) | null; + readonly registration: ServiceWorkerRegistration; + skipWaiting(): Promise; + addEventListener(type: K, listener: (this: ServiceWorkerGlobalScope, ev: ServiceWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; + removeEventListener(type: K, listener: (this: ServiceWorkerGlobalScope, ev: ServiceWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; +} + +//#endregion + declare var self: ServiceWorkerGlobalScope; //#region --- installing/activating diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts index 326dfb49eea..935753f002d 100644 --- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts +++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerClient.ts @@ -7,14 +7,11 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions'; import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { ILogService } from 'vs/platform/log/common/log'; -import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle'; class ResourceServiceWorker { private static _url = require.toUrl('./resourceServiceWorkerMain.js'); - private readonly _disposables = new DisposableStore(); - constructor( @ILogService private readonly _logService: ILogService, ) { @@ -27,18 +24,8 @@ class ResourceServiceWorker { this._logService.error('SW#init', err); }); - const handler = (e: ExtendableMessageEvent) => this._handleMessage(e); - navigator.serviceWorker.addEventListener('message', handler); - this._disposables.add(toDisposable(() => navigator.serviceWorker.removeEventListener('message', handler))); - } - - dispose(): void { - this._disposables.dispose(); } - private _handleMessage(event: ExtendableMessageEvent): void { - this._logService.trace('SW', event.data); - } } Registry.as(Extensions.Workbench).registerWorkbenchContribution( diff --git a/src/vs/workbench/services/extensions/worker/extensionHostWorker.ts b/src/vs/workbench/services/extensions/worker/extensionHostWorker.ts index bda2aa21f4e..3b5706ce76a 100644 --- a/src/vs/workbench/services/extensions/worker/extensionHostWorker.ts +++ b/src/vs/workbench/services/extensions/worker/extensionHostWorker.ts @@ -15,6 +15,9 @@ import 'vs/workbench/services/extensions/worker/extHost.services'; //#region --- Define, capture, and override some globals //todo@joh do not allow extensions to call postMessage and other globals... +// declare WorkerSelf#postMessage +declare function postMessage(data: any, transferables?: Transferable[]): void; + declare namespace self { let close: any; let postMessage: any; -- GitLab