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' ;
@@ -52,8 +52,7 @@ export class LocalTerminalBackendContribution implements IWorkbenchContribution
5252class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBackend {
5353 readonly remoteAuthority = undefined ;
5454
55- private readonly _proxy : IPtyService ;
56- private readonly _clientEventually : DeferredPromise < MessagePortClient > = new DeferredPromise ( ) ;
55+ private _proxy ! : IPtyService ;
5756 private readonly _ptys : Map < number , LocalPty > = new Map ( ) ;
5857
5958 private readonly _whenConnected = new DeferredPromise < void > ( ) ;
@@ -84,12 +83,15 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
8483 ) {
8584 super ( _localPtyService , logService , historyService , _configurationResolverService , statusBarService , workspaceContextService ) ;
8685
87- this . _proxy = ProxyChannel . toService < IPtyService > ( getDelayedChannel ( this . _clientEventually . p . then ( client => client . getChannel ( TerminalIpcChannels . PtyHostWindow ) ) ) ) ;
88-
89- this . _connectToDirectProxy ( ) ;
86+ this . _register ( Event . runAndSubscribe ( this . onPtyHostRestart , ( ) => {
87+ this . _logService . debug ( 'Starting pty host' ) ;
88+ const clientEventually = new DeferredPromise < MessagePortClient > ( ) ;
89+ this . _proxy = ProxyChannel . toService < IPtyService > ( getDelayedChannel ( clientEventually . p . then ( client => client . getChannel ( TerminalIpcChannels . PtyHostWindow ) ) ) ) ;
90+ this . _connectToDirectProxy ( clientEventually ) ;
91+ } ) ) ;
9092 }
9193
92- private async _connectToDirectProxy ( ) : Promise < void > {
94+ private async _connectToDirectProxy ( clientEventually : DeferredPromise < MessagePortClient > ) : Promise < void > {
9395 // The pty host should not get launched until the first window restored phase
9496 await this . _lifecycleService . when ( LifecyclePhase . Restored ) ;
9597
@@ -103,7 +105,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
103105 // used for pty host management messages, it would make sense in the future to use a
104106 // separate interface/service for this one.
105107 const client = new MessagePortClient ( port , `window:${ this . _environmentService . window . id } ` ) ;
106- this . _clientEventually . complete ( client ) ;
108+ clientEventually . complete ( client ) ;
107109
108110 // Attach process listeners
109111 this . _proxy . onProcessData ( e => this . _ptys . get ( e . id ) ?. handleData ( e . event ) ) ;
0 commit comments