Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998 (#7880)

* Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998

* fix pipelines

* fix strict-null-checks

* add missing files
This commit is contained in:
Anthony Dresser
2019-10-21 22:12:22 -07:00
committed by GitHub
parent 7c9be74970
commit 1e22f47304
913 changed files with 18898 additions and 16536 deletions

View File

@@ -9,8 +9,19 @@ import { IDisposable } from 'vs/base/common/lifecycle';
export const IURLService = createDecorator<IURLService>('urlService');
export interface IOpenURLOptions {
/**
* If not provided or `false`, signals that the
* URL to open did not originate from the product
* but outside. As such, a confirmation dialog
* might be shown to the user.
*/
trusted?: boolean;
}
export interface IURLHandler {
handleURL(uri: URI): Promise<boolean>;
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean>;
}
export interface IURLService {
@@ -24,7 +35,7 @@ export interface IURLService {
*/
create(options?: Partial<UriComponents>): URI;
open(url: URI): Promise<boolean>;
open(url: URI, options?: IOpenURLOptions): Promise<boolean>;
registerHandler(handler: IURLHandler): IDisposable;
}

View File

@@ -6,7 +6,7 @@
import { IChannel, IServerChannel, IClientRouter, IConnectionHub, Client } from 'vs/base/parts/ipc/common/ipc';
import { URI } from 'vs/base/common/uri';
import { Event } from 'vs/base/common/event';
import { IURLHandler } from 'vs/platform/url/common/url';
import { IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
import { CancellationToken } from 'vs/base/common/cancellation';
import { first } from 'vs/base/common/arrays';
@@ -31,7 +31,7 @@ export class URLHandlerChannelClient implements IURLHandler {
constructor(private channel: IChannel) { }
handleURL(uri: URI): Promise<boolean> {
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
return this.channel.call('handleURL', uri.toJSON());
}
}
@@ -49,11 +49,12 @@ export class URLHandlerRouter implements IClientRouter<string> {
const uri = URI.revive(arg);
if (uri && uri.query) {
const match = /\bwindowId=([^&]+)/.exec(uri.query);
const match = /\bwindowId=(\d+)/.exec(uri.query);
if (match) {
const windowId = match[1];
const connection = first(hub.connections, c => c.ctx === windowId);
const regex = new RegExp(`window:${windowId}`);
const connection = first(hub.connections, c => regex.test(c.ctx));
if (connection) {
return connection;

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
import { IURLService, IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
import { URI, UriComponents } from 'vs/base/common/uri';
import { values } from 'vs/base/common/map';
import { first } from 'vs/base/common/async';
@@ -17,9 +17,9 @@ export abstract class AbstractURLService extends Disposable implements IURLServi
abstract create(options?: Partial<UriComponents>): URI;
open(uri: URI): Promise<boolean> {
open(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
const handlers = values(this.handlers);
return first(handlers.map(h => () => h.handleURL(uri)), undefined, false).then(val => val || false);
return first(handlers.map(h => () => h.handleURL(uri, options)), undefined, false).then(val => val || false);
}
registerHandler(handler: IURLHandler): IDisposable {

View File

@@ -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();
}
}