11import * as path from 'path' ;
2- import * as os from 'os' ;
32import * as fs from 'fs' ;
4- import * as crypto from 'crypto' ;
53import * as vscode from 'vscode' ;
4+ import { QuickPickItem } from 'vscode' ;
65import * as extProtocol from './extensionProtocol' ;
76import { Services } from '../services/extensionHostServices' ;
8- import { QuickPickItem } from "vscode" ;
7+ import { getSocketId } from "./sockedId" ;
8+
99let ipc = require ( 'node-ipc' ) ;
1010
1111export class ExtensionServer {
1212 private _isRunning : boolean ;
1313
14- public static getTempFilePathForDirectory ( directoryPath : string ) {
15- let fileName : string = 'vsc-ns-ext-' + crypto . createHash ( 'md5' ) . update ( directoryPath ) . digest ( "hex" ) + '.sock' ;
16- return path . join ( os . tmpdir ( ) , fileName ) ;
17- }
18-
1914 constructor ( ) {
2015 this . _isRunning = false ;
2116 }
2217
23- public getPipeHandlePath ( ) : string {
24- return vscode . workspace . rootPath ?
25- ExtensionServer . getTempFilePathForDirectory ( vscode . workspace . rootPath ) :
26- null ;
27- }
28-
2918 public start ( ) {
3019 if ( ! this . _isRunning ) {
31- let pipeHandlePath = this . getPipeHandlePath ( ) ;
32- if ( pipeHandlePath ) {
33- ipc . serve (
34- pipeHandlePath ,
35- ( ) => {
36- ipc . server . on ( 'extension-protocol-message' , ( data : extProtocol . Request , socket ) => {
37- return ( < Promise < Object > > this [ data . method ] . call ( this , data . args ) ) . then ( result => {
38- let response : extProtocol . Response = { requestId : data . id , result : result } ;
39- return ipc . server . emit ( socket , 'extension-protocol-message' , response ) ;
40- } ) ;
20+ ipc . config . id = getSocketId ( ) ;
21+ ipc . serve (
22+ ( ) => {
23+ ipc . server . on ( 'extension-protocol-message' , ( data : extProtocol . Request , socket ) => {
24+ return ( < Promise < Object > > this [ data . method ] . call ( this , data . args ) ) . then ( result => {
25+ let response : extProtocol . Response = { requestId : data . id , result : result } ;
26+ return ipc . server . emit ( socket , 'extension-protocol-message' , response ) ;
4127 } ) ;
4228 } ) ;
43- ipc . server . start ( ) ;
44- this . _isRunning = true ;
45- }
29+ } ) ;
30+ ipc . server . start ( ) ;
31+ this . _isRunning = true ;
4632 }
4733 return this . _isRunning ;
4834 }
@@ -60,7 +46,7 @@ export class ExtensionServer {
6046
6147 public getInitSettings ( ) : Promise < extProtocol . InitSettingsResult > {
6248 let tnsPath = Services . workspaceConfigService ( ) . tnsPath ;
63- return Promise . resolve ( { tnsPath : tnsPath } ) ;
49+ return Promise . resolve ( { tnsPath : tnsPath } ) ;
6450 }
6551
6652 public analyticsLaunchDebugger ( args : extProtocol . AnalyticsLaunchDebuggerArgs ) : Promise < any > {
@@ -115,7 +101,7 @@ export class ExtensionServer {
115101 let teamIds : any = { } ;
116102 for ( let file of files ) {
117103 let filePath = path . join ( dir , file ) ;
118- let data = fs . readFileSync ( filePath , { encoding : "utf8" } ) ;
104+ let data = fs . readFileSync ( filePath , { encoding : "utf8" } ) ;
119105 let teamId = this . getProvisioningProfileValue ( "TeamIdentifier" , data ) ;
120106 let teamName = this . getProvisioningProfileValue ( "TeamName" , data ) ;
121107 if ( teamId ) {
@@ -125,29 +111,28 @@ export class ExtensionServer {
125111
126112 let teamIdsArray = new Array < { id : string , name : string } > ( ) ;
127113 for ( let teamId in teamIds ) {
128- teamIdsArray . push ( { id : teamId , name : teamIds [ teamId ] } ) ;
114+ teamIdsArray . push ( { id : teamId , name : teamIds [ teamId ] } ) ;
129115 }
130116
131117 return teamIdsArray ;
132118 } catch ( e ) {
133119 // no matter what happens, don't break
134120 return new Array < { id : string , name : string } > ( ) ;
135121 }
136- }
122+ }
137123
138124 private getProvisioningProfileValue ( name : string , text : string ) : string {
139- let findStr = "<key>" + name + "</key>" ;
140- let index = text . indexOf ( findStr ) ;
141- if ( index > 0 ) {
142- index = text . indexOf ( "<string>" , index + findStr . length ) ;
143- if ( index > 0 ) {
144- index += "<string>" . length ;
145- let endIndex = text . indexOf ( "</string>" , index ) ;
146- let result = text . substring ( index , endIndex ) ;
147- return result ;
148- }
149- }
150-
151- return null ;
152- }
125+ let findStr = "<key>" + name + "</key>" ;
126+ let index = text . indexOf ( findStr ) ;
127+ if ( index > 0 ) {
128+ index = text . indexOf ( "<string>" , index + findStr . length ) ;
129+ if ( index > 0 ) {
130+ index += "<string>" . length ;
131+ let endIndex = text . indexOf ( "</string>" , index ) ;
132+ let result = text . substring ( index , endIndex ) ;
133+ return result ;
134+ }
135+ }
136+ return null ;
137+ }
153138}
0 commit comments