From fcb6f7f9ee63816bfb4bf3566281ba797a315fd2 Mon Sep 17 00:00:00 2001 From: Matt Irvine Date: Fri, 12 Jan 2018 12:59:43 -0800 Subject: [PATCH] open-url changes --- src/vs/code/electron-main/launch.ts | 8 ++++---- src/vs/code/electron-main/main.ts | 2 +- src/vs/code/node/paths.ts | 5 +++++ src/vs/platform/environment/common/environment.ts | 3 ++- src/vs/platform/environment/node/argv.ts | 2 +- src/vs/platform/url/electron-main/urlService.ts | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/vs/code/electron-main/launch.ts b/src/vs/code/electron-main/launch.ts index 1587144978..a1d892940f 100644 --- a/src/vs/code/electron-main/launch.ts +++ b/src/vs/code/electron-main/launch.ts @@ -83,10 +83,10 @@ export class LaunchService implements ILaunchService { this.logService.log('Received data from other instance: ', args, userEnv); // Check early for open-url which is handled in URL service - const openUrlArg = args['open-url'] || []; - const openUrl = typeof openUrlArg === 'string' ? [openUrlArg] : openUrlArg; - if (openUrl.length > 0) { - openUrl.forEach(url => this.urlService.open(url)); + if (args['open-url'] && args._urls && args._urls.length > 0) { + // --open-url must contain -- followed by the url(s) + // process.argv is used over args._ as args._ are resolved to file paths at this point + args._urls.forEach(url => this.urlService.open(url)); return TPromise.as(null); } diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 335376d320..8775508821 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -49,7 +49,7 @@ function createServices(args: ParsedArgs): IInstantiationService { services.set(IStorageService, new SyncDescriptor(StorageService)); services.set(IConfigurationService, new SyncDescriptor(ConfigurationService)); services.set(IRequestService, new SyncDescriptor(RequestService)); - services.set(IURLService, new SyncDescriptor(URLService, args['open-url'])); + services.set(IURLService, new SyncDescriptor(URLService, args['open-url'] ? args._urls : [])); services.set(IBackupMainService, new SyncDescriptor(BackupMainService)); return new InstantiationService(services, true); diff --git a/src/vs/code/node/paths.ts b/src/vs/code/node/paths.ts index 0515b1170e..26cb1ff744 100644 --- a/src/vs/code/node/paths.ts +++ b/src/vs/code/node/paths.ts @@ -15,6 +15,11 @@ import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { realpathSync } from 'vs/base/node/extfs'; export function validatePaths(args: ParsedArgs): ParsedArgs { + // Track URLs if they're going to be used + if (args['open-url']) { + args._urls = args._; + args._ = []; + } // Realpath/normalize paths and watch out for goto line mode const paths = doValidatePaths(args._, args.goto); diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index ad82e8ef65..b2115478ba 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -8,6 +8,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' export interface ParsedArgs { [arg: string]: any; _: string[]; + _urls?: string[]; help?: boolean; version?: boolean; wait?: boolean; @@ -38,7 +39,7 @@ export interface ParsedArgs { 'install-extension'?: string | string[]; 'uninstall-extension'?: string | string[]; 'enable-proposed-api'?: string | string[]; - 'open-url'?: string | string[]; + 'open-url'?: boolean; 'skip-getting-started'?: boolean; 'sticky-quickopen'?: boolean; 'disable-telemetry'?: boolean; diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index bd799ca2a6..2dd6f21e9e 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -24,7 +24,6 @@ const options: minimist.Opts = { 'debugBrkPluginHost', 'debugSearch', 'debugBrkSearch', - 'open-url', 'enable-proposed-api', 'export-default-configuration', 'install-source' @@ -39,6 +38,7 @@ const options: minimist.Opts = { 'new-window', 'unity-launch', 'reuse-window', + 'open-url', 'performance', 'prof-startup', 'verbose', diff --git a/src/vs/platform/url/electron-main/urlService.ts b/src/vs/platform/url/electron-main/urlService.ts index 30daa2bc75..a3b14e4aba 100644 --- a/src/vs/platform/url/electron-main/urlService.ts +++ b/src/vs/platform/url/electron-main/urlService.ts @@ -26,7 +26,7 @@ export class URLService implements IURLService { ...globalBuffer ]; - app.setAsDefaultProtocolClient(product.urlProtocol, process.execPath, ['--open-url']); + app.setAsDefaultProtocolClient(product.urlProtocol, process.execPath, ['--open-url', '--']); const rawOnOpenUrl = fromEventEmitter(app, 'open-url', (event: Electron.Event, url: string) => ({ event, url }));