mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
fixes #82869
This commit is contained in:
parent
0b347ca8cf
commit
53c0d13e17
|
@ -8,10 +8,11 @@ import { IURLService } from 'vs/platform/url/common/url';
|
|||
import product from 'vs/platform/product/common/product';
|
||||
import { app, Event as ElectronEvent } from 'electron';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { coalesce } from 'vs/base/common/arrays';
|
||||
import { disposableTimeout } from 'vs/base/common/async';
|
||||
|
||||
function uriFromRawUrl(url: string): URI | null {
|
||||
try {
|
||||
|
@ -23,7 +24,10 @@ function uriFromRawUrl(url: string): URI | null {
|
|||
|
||||
export class ElectronURLListener {
|
||||
|
||||
private disposables: IDisposable[] = [];
|
||||
private uris: URI[] = [];
|
||||
private retryCount = 0;
|
||||
private flushDisposable: IDisposable = Disposable.None;
|
||||
private disposables = new DisposableStore();
|
||||
|
||||
constructor(
|
||||
initial: string | string[],
|
||||
|
@ -36,12 +40,7 @@ export class ElectronURLListener {
|
|||
...globalBuffer
|
||||
];
|
||||
|
||||
const buffer = coalesce(rawBuffer.map(uriFromRawUrl));
|
||||
const flush = () => buffer.forEach(uri => {
|
||||
if (uri) {
|
||||
urlService.open(uri);
|
||||
}
|
||||
});
|
||||
this.uris = coalesce(rawBuffer.map(uriFromRawUrl));
|
||||
|
||||
if (isWindows) {
|
||||
app.setAsDefaultProtocolClient(product.urlProtocol, process.execPath, ['--open-url', '--']);
|
||||
|
@ -63,13 +62,37 @@ export class ElectronURLListener {
|
|||
.length > 0;
|
||||
|
||||
if (isWindowReady) {
|
||||
flush();
|
||||
this.flush();
|
||||
} else {
|
||||
Event.once(windowsMainService.onWindowReady)(flush);
|
||||
Event.once(windowsMainService.onWindowReady)(this.flush, this, this.disposables);
|
||||
}
|
||||
}
|
||||
|
||||
private async flush(): Promise<void> {
|
||||
if (this.retryCount++ > 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uris: URI[] = [];
|
||||
|
||||
for (const uri of this.uris) {
|
||||
const handled = await this.urlService.open(uri);
|
||||
|
||||
if (!handled) {
|
||||
uris.push(uri);
|
||||
}
|
||||
}
|
||||
|
||||
if (uris.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.uris = uris;
|
||||
this.flushDisposable = disposableTimeout(() => this.flush(), 500);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
this.disposables.dispose();
|
||||
this.flushDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,9 +363,13 @@ class ExtensionUrlBootstrapHandler implements IWorkbenchContribution, IURLHandle
|
|||
ExtensionUrlBootstrapHandler.disposable = urlService.registerHandler(this);
|
||||
}
|
||||
|
||||
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
|
||||
async handleURL(uri: URI): Promise<boolean> {
|
||||
if (!isExtensionId(uri.authority)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExtensionUrlBootstrapHandler._cache.push(uri);
|
||||
return Promise.resolve(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue