33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { Emitter } from 'vs/base/common/event' ;
6+ import { Emitter , Event } from 'vs/base/common/event' ;
77import { IProcessEnvironment , isMacintosh , isWindows , OperatingSystem } from 'vs/base/common/platform' ;
88import { withNullAsUndefined } from 'vs/base/common/types' ;
99import { URI } from 'vs/base/common/uri' ;
@@ -51,8 +51,7 @@ export class LocalTerminalBackendContribution implements IWorkbenchContribution
5151class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBackend {
5252 readonly remoteAuthority = undefined ;
5353
54- private readonly _proxy : IPtyService ;
55- private readonly _clientEventually : DeferredPromise < MessagePortClient > = new DeferredPromise ( ) ;
54+ private _proxy ! : IPtyService ;
5655 private readonly _ptys : Map < number , LocalPty > = new Map ( ) ;
5756
5857 private readonly _whenConnected = new DeferredPromise < void > ( ) ;
@@ -83,12 +82,15 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
8382 ) {
8483 super ( _localPtyService , logService , historyService , _configurationResolverService , statusBarService , workspaceContextService ) ;
8584
86- this . _proxy = ProxyChannel . toService < IPtyService > ( getDelayedChannel ( this . _clientEventually . p . then ( client => client . getChannel ( TerminalIpcChannels . PtyHostWindow ) ) ) ) ;
87-
88- this . _connectToDirectProxy ( ) ;
85+ this . _register ( Event . runAndSubscribe ( this . onPtyHostRestart , ( ) => {
86+ this . _logService . debug ( 'Starting pty host' ) ;
87+ const clientEventually = new DeferredPromise < MessagePortClient > ( ) ;
88+ this . _proxy = ProxyChannel . toService < IPtyService > ( getDelayedChannel ( clientEventually . p . then ( client => client . getChannel ( TerminalIpcChannels . PtyHostWindow ) ) ) ) ;
89+ this . _connectToDirectProxy ( clientEventually ) ;
90+ } ) ) ;
8991 }
9092
91- private async _connectToDirectProxy ( ) : Promise < void > {
93+ private async _connectToDirectProxy ( clientEventually : DeferredPromise < MessagePortClient > ) : Promise < void > {
9294 // The pty host should not get launched until the first window restored phase
9395 await this . _lifecycleService . when ( LifecyclePhase . Restored ) ;
9496
@@ -102,7 +104,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
102104 // used for pty host management messages, it would make sense in the future to use a
103105 // separate interface/service for this one.
104106 const client = new MessagePortClient ( port , `window:${ this . _environmentService . window . id } ` ) ;
105- this . _clientEventually . complete ( client ) ;
107+ clientEventually . complete ( client ) ;
106108
107109 // Attach process listeners
108110 this . _proxy . onProcessData ( e => this . _ptys . get ( e . id ) ?. handleData ( e . event ) ) ;
0 commit comments