mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-14 16:04:09 +01:00
+14
-1
@@ -132,9 +132,22 @@ app.on('open-file', function (event, path) {
|
||||
global.macOpenFiles.push(path);
|
||||
});
|
||||
|
||||
const openUrls = [];
|
||||
const onOpenUrl = (event, url) => {
|
||||
event.preventDefault();
|
||||
openUrls.push(url);
|
||||
};
|
||||
|
||||
app.on('will-finish-launching', () => app.on('open-url', onOpenUrl));
|
||||
|
||||
global.getOpenUrls = () => {
|
||||
app.removeListener('open-url', onOpenUrl);
|
||||
return openUrls;
|
||||
};
|
||||
|
||||
// Load our code once ready
|
||||
app.once('ready', function () {
|
||||
var nlsConfig = getNLSConfiguration();
|
||||
process.env['VSCODE_NLS_CONFIG'] = JSON.stringify(nlsConfig);
|
||||
require('./bootstrap-amd').bootstrap('vs/code/electron-main/main');
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import Event, {chain} from 'vs/base/common/event';
|
||||
import Event, {chain, mapEvent, buffer} from 'vs/base/common/event';
|
||||
import {fromEventEmitter} from 'vs/base/node/event';
|
||||
import {IURLService} from 'vs/platform/url/common/url';
|
||||
import product from 'vs/platform/product';
|
||||
@@ -19,12 +19,21 @@ export class URLService implements IURLService {
|
||||
onOpenURL: Event<URI>;
|
||||
|
||||
constructor() {
|
||||
app.setAsDefaultProtocolClient(product.urlProtocol);
|
||||
|
||||
const rawOnOpenUrl = fromEventEmitter(app, 'open-url', (event: Electron.Event, url: string) => ({ event, url }));
|
||||
|
||||
this.onOpenURL = chain(rawOnOpenUrl)
|
||||
.map(({ event, url }) => {
|
||||
event.preventDefault();
|
||||
// always prevent default and return the url as string
|
||||
const onOpenUrl = mapEvent(rawOnOpenUrl, ({ event, url }) => {
|
||||
event.preventDefault();
|
||||
return url;
|
||||
});
|
||||
|
||||
// buffer all `onOpenUrl` events until someone starts listening
|
||||
const bufferedOnOpenUrl = buffer(onOpenUrl, true, global.getOpenUrls());
|
||||
|
||||
this.onOpenURL = chain(bufferedOnOpenUrl)
|
||||
.map(url => {
|
||||
try {
|
||||
return URI.parse(url);
|
||||
} catch(e) {
|
||||
@@ -33,7 +42,5 @@ export class URLService implements IURLService {
|
||||
})
|
||||
.filter(uri => !!uri)
|
||||
.event;
|
||||
|
||||
app.setAsDefaultProtocolClient(product.urlProtocol);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user