提交 5ba02362 编写于 作者: J Johannes Rieken

remove compilerOptions/lib/webworker because it conflicts with lib/dom, #80074

上级 db0d5ee0
......@@ -9,8 +9,7 @@
"lib": [
"dom",
"es5",
"es2015.iterable",
"webworker"
"es2015.iterable"
],
"types": [
"keytar",
......
......@@ -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<any>;
readonly replacesClientId: string;
readonly request: Request;
readonly resultingClientId: string;
respondWith(r: Response | Promise<Response>): void;
}
interface ExtendableMessageEvent extends ExtendableEvent {
readonly data: any;
readonly lastEventId: string;
readonly origin: string;
readonly ports: ReadonlyArray<MessagePort>;
readonly source: ServiceWorker | MessagePort | null;
}
interface ServiceWorkerGlobalScopeEventMap {
'activate': ExtendableEvent;
'fetch': FetchEvent;
'install': ExtendableEvent;
'message': ExtendableMessageEvent;
'messageerror': MessageEvent;
}
interface Clients {
claim(): Promise<void>;
get(id: string): Promise<any>;
}
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<void>;
addEventListener<K extends keyof ServiceWorkerGlobalScopeEventMap>(type: K, listener: (this: ServiceWorkerGlobalScope, ev: ServiceWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof ServiceWorkerGlobalScopeEventMap>(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
......
......@@ -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<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册