66'use strict' ;
77
88import { mapEvent , fromNodeEventEmitter , filterEvent } from 'vs/base/common/event' ;
9- import { IURLService , IURLHandler } from 'vs/platform/url/common/url' ;
9+ import { IURLService } from 'vs/platform/url/common/url' ;
1010import product from 'vs/platform/node/product' ;
1111import { app } from 'electron' ;
1212import URI from 'vs/base/common/uri' ;
13- import { ILogService } from 'vs/platform/log/common/log' ;
14- import { IDisposable , dispose , toDisposable } from 'vs/base/common/lifecycle' ;
15- import { TPromise } from 'vs/base/common/winjs.base' ;
16- import { Limiter } from 'vs/base/common/async' ;
13+ import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
1714import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows' ;
1815import { ReadyState } from 'vs/platform/windows/common/windows' ;
1916
@@ -25,93 +22,6 @@ function uriFromRawUrl(url: string): URI | null {
2522 }
2623}
2724
28- export class URLService implements IURLService {
29-
30- _serviceBrand : any ;
31-
32- private buffer : URI [ ] ;
33- private handlers : IURLHandler [ ] = [ ] ;
34- private handlerLimiter = new Limiter < void > ( 1 ) ;
35- private disposables : IDisposable [ ] = [ ] ;
36-
37- constructor (
38- initial : string | string [ ] ,
39- @ILogService private logService : ILogService
40- ) {
41- const globalBuffer = ( global . getOpenUrls ( ) || [ ] ) as string [ ] ;
42- const rawBuffer = [
43- ...( typeof initial === 'string' ? [ initial ] : initial ) ,
44- ...globalBuffer
45- ] ;
46-
47- this . buffer = rawBuffer . map ( uriFromRawUrl ) . filter ( uri => ! ! uri ) ;
48-
49- app . setAsDefaultProtocolClient ( product . urlProtocol , process . execPath , [ '--open-url' , '--' ] ) ;
50-
51- const onOpenElectronUrl = mapEvent (
52- fromNodeEventEmitter ( app , 'open-url' , ( event : Electron . Event , url : string ) => ( { event, url } ) ) ,
53- ( { event, url } ) => {
54- // always prevent default and return the url as string
55- event . preventDefault ( ) ;
56- return url ;
57- } ) ;
58-
59- const onOpenUrl = filterEvent ( mapEvent ( onOpenElectronUrl , uriFromRawUrl ) , uri => ! ! uri ) ;
60- onOpenUrl ( this . openURI , this , this . disposables ) ;
61- }
62-
63- open ( uri : URI ) : TPromise < boolean > {
64- // const uri = uriFromRawUrl(url);
65-
66- // if (!uri) {
67- // return ;
68- // }
69-
70- return this . openURI ( uri ) ;
71- }
72-
73- private async openURI ( uri : URI , handlers = this . handlers ) : TPromise < boolean > {
74- this . logService . trace ( 'urlService#handleURI' , uri . toString ( ) ) ;
75-
76- for ( const handler of handlers ) {
77- if ( await handler . handleURL ( uri ) ) {
78- return true ;
79- }
80- }
81-
82- return false ;
83- }
84-
85- private async flushBuffer ( handler : IURLHandler ) : TPromise < void > {
86- const buffer = [ ...this . buffer ] ;
87-
88- for ( const uri of buffer ) {
89- if ( await handler . handleURL ( uri ) ) {
90- this . buffer . splice ( this . buffer . indexOf ( uri , 1 ) ) ;
91- }
92- }
93- }
94-
95- registerHandler ( handler : IURLHandler ) : IDisposable {
96- this . handlers . push ( handler ) ;
97- this . handlerLimiter . queue ( ( ) => this . flushBuffer ( handler ) ) ;
98-
99- return toDisposable ( ( ) => {
100- const index = this . handlers . indexOf ( handler ) ;
101-
102- if ( index === - 1 ) {
103- return ;
104- }
105-
106- this . handlers . splice ( index , 1 ) ;
107- } ) ;
108- }
109-
110- dispose ( ) : void {
111- this . disposables = dispose ( this . disposables ) ;
112- }
113- }
114-
11525export class ElectronURLListener {
11626
11727 private buffer : URI [ ] = [ ] ;
0 commit comments