3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { Emitter } from 'vs/base/common/event' ;
6
+ import { Emitter , Event } from 'vs/base/common/event' ;
7
7
import { IProcessEnvironment , isMacintosh , isWindows , OperatingSystem } from 'vs/base/common/platform' ;
8
8
import { withNullAsUndefined } from 'vs/base/common/types' ;
9
9
import { URI } from 'vs/base/common/uri' ;
@@ -51,8 +51,7 @@ export class LocalTerminalBackendContribution implements IWorkbenchContribution
51
51
class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBackend {
52
52
readonly remoteAuthority = undefined ;
53
53
54
- private readonly _proxy : IPtyService ;
55
- private readonly _clientEventually : DeferredPromise < MessagePortClient > = new DeferredPromise ( ) ;
54
+ private _proxy ! : IPtyService ;
56
55
private readonly _ptys : Map < number , LocalPty > = new Map ( ) ;
57
56
58
57
private readonly _whenConnected = new DeferredPromise < void > ( ) ;
@@ -83,12 +82,15 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
83
82
) {
84
83
super ( _localPtyService , logService , historyService , _configurationResolverService , statusBarService , workspaceContextService ) ;
85
84
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
+ } ) ) ;
89
91
}
90
92
91
- private async _connectToDirectProxy ( ) : Promise < void > {
93
+ private async _connectToDirectProxy ( clientEventually : DeferredPromise < MessagePortClient > ) : Promise < void > {
92
94
// The pty host should not get launched until the first window restored phase
93
95
await this . _lifecycleService . when ( LifecyclePhase . Restored ) ;
94
96
@@ -102,7 +104,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
102
104
// used for pty host management messages, it would make sense in the future to use a
103
105
// separate interface/service for this one.
104
106
const client = new MessagePortClient ( port , `window:${ this . _environmentService . window . id } ` ) ;
105
- this . _clientEventually . complete ( client ) ;
107
+ clientEventually . complete ( client ) ;
106
108
107
109
// Attach process listeners
108
110
this . _proxy . onProcessData ( e => this . _ptys . get ( e . id ) ?. handleData ( e . event ) ) ;
0 commit comments