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' ;
@@ -52,8 +52,7 @@ export class LocalTerminalBackendContribution implements IWorkbenchContribution
52
52
class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBackend {
53
53
readonly remoteAuthority = undefined ;
54
54
55
- private readonly _proxy : IPtyService ;
56
- private readonly _clientEventually : DeferredPromise < MessagePortClient > = new DeferredPromise ( ) ;
55
+ private _proxy ! : IPtyService ;
57
56
private readonly _ptys : Map < number , LocalPty > = new Map ( ) ;
58
57
59
58
private readonly _whenConnected = new DeferredPromise < void > ( ) ;
@@ -84,12 +83,15 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
84
83
) {
85
84
super ( _localPtyService , logService , historyService , _configurationResolverService , statusBarService , workspaceContextService ) ;
86
85
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
+ } ) ) ;
90
92
}
91
93
92
- private async _connectToDirectProxy ( ) : Promise < void > {
94
+ private async _connectToDirectProxy ( clientEventually : DeferredPromise < MessagePortClient > ) : Promise < void > {
93
95
// The pty host should not get launched until the first window restored phase
94
96
await this . _lifecycleService . when ( LifecyclePhase . Restored ) ;
95
97
@@ -103,7 +105,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
103
105
// used for pty host management messages, it would make sense in the future to use a
104
106
// separate interface/service for this one.
105
107
const client = new MessagePortClient ( port , `window:${ this . _environmentService . window . id } ` ) ;
106
- this . _clientEventually . complete ( client ) ;
108
+ clientEventually . complete ( client ) ;
107
109
108
110
// Attach process listeners
109
111
this . _proxy . onProcessData ( e => this . _ptys . get ( e . id ) ?. handleData ( e . event ) ) ;
0 commit comments