Merge pull request #158604 from microsoft/tyriar/158595

Only persist terminals when they have had interaction
This commit is contained in:
Daniel Imms 2022-08-23 08:26:14 -07:00 committed by GitHub
commit 0380d81838
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 20 deletions

View file

@ -297,7 +297,7 @@ export interface IPtyService extends IPtyHostController {
workspaceName: string
): Promise<number>;
attachToProcess(id: number): Promise<void>;
detachFromProcess(id: number): Promise<void>;
detachFromProcess(id: number, forcePersist?: boolean): Promise<void>;
/**
* Lists all orphaned processes, ie. those without a connected frontend.
@ -642,8 +642,9 @@ export interface ITerminalChildProcess {
/**
* Detach the process from the UI and await reconnect.
* @param forcePersist Whether to force the process to persist if it supports persistence.
*/
detach?(): Promise<void>;
detach?(forcePersist?: boolean): Promise<void>;
/**
* Shutdown the terminal process.

View file

@ -229,8 +229,8 @@ export class PtyHostService extends Disposable implements IPtyService {
attachToProcess(id: number): Promise<void> {
return this._proxy.attachToProcess(id);
}
detachFromProcess(id: number): Promise<void> {
return this._proxy.detachFromProcess(id);
detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
return this._proxy.detachFromProcess(id, forcePersist);
}
listProcesses(): Promise<IProcessDetails[]> {
return this._proxy.listProcesses();

View file

@ -236,8 +236,8 @@ export class PtyService extends Disposable implements IPtyService {
return this._throwIfNoPty(id).updateProperty(type, value);
}
async detachFromProcess(id: number): Promise<void> {
return this._throwIfNoPty(id).detach();
async detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
return this._throwIfNoPty(id).detach(forcePersist);
}
async reduceConnectionGraceTime(): Promise<void> {
@ -595,9 +595,11 @@ export class PersistentTerminalProcess extends Disposable {
this._disconnectRunner2.cancel();
}
async detach(): Promise<void> {
this._logService.trace('persistentTerminalProcess#detach', this._persistentProcessId);
if (this.shouldPersistTerminal) {
async detach(forcePersist?: boolean): Promise<void> {
this._logService.trace('persistentTerminalProcess#detach', this._persistentProcessId, forcePersist);
// Keep the process around if it was indicated to persist and it has had some iteraction or
// was replayed
if (this.shouldPersistTerminal && (this._interactionState !== InteractionState.None || forcePersist)) {
this._disconnectRunner1.schedule();
} else {
this.shutdown(true);

View file

@ -76,9 +76,9 @@ export class RemotePty extends Disposable implements ITerminalChildProcess {
return undefined;
}
async detach(): Promise<void> {
async detach(forcePersist?: boolean): Promise<void> {
await this._startBarrier.wait();
return this._remoteTerminalChannel.detachFromProcess(this.id);
return this._remoteTerminalChannel.detachFromProcess(this.id, forcePersist);
}
shutdown(immediate: boolean): void {

View file

@ -1482,8 +1482,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
async detachProcessAndDispose(reason: TerminalExitReason): Promise<void> {
// Detach the process and dispose the instance, without the instance dispose the terminal
// won't go away
await this._processManager.detachFromProcess();
// won't go away. Force persist if the detach was requested by the user (not shutdown).
await this._processManager.detachFromProcess(reason === TerminalExitReason.User);
this.dispose(reason);
}

View file

@ -195,8 +195,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
});
}
async detachFromProcess(): Promise<void> {
await this._process?.detach?.();
async detachFromProcess(forcePersist?: boolean): Promise<void> {
await this._process?.detach?.(forcePersist);
this._process = null;
}

View file

@ -195,8 +195,8 @@ export class RemoteTerminalChannelClient implements IPtyHostController {
attachToProcess(id: number): Promise<void> {
return this._channel.call('$attachToProcess', [id]);
}
detachFromProcess(id: number): Promise<void> {
return this._channel.call('$detachFromProcess', [id]);
detachFromProcess(id: number, forcePersist?: boolean): Promise<void> {
return this._channel.call('$detachFromProcess', [id, forcePersist]);
}
listProcesses(): Promise<IProcessDetails[]> {
return this._channel.call('$listProcesses');

View file

@ -398,7 +398,7 @@ export interface ITerminalProcessManager extends IDisposable {
readonly onRestoreCommands: Event<ISerializedCommandDetectionCapability>;
dispose(immediate?: boolean): void;
detachFromProcess(): Promise<void>;
detachFromProcess(forcePersist?: boolean): Promise<void>;
createProcess(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean): Promise<ITerminalLaunchError | undefined>;
relaunch(shellLaunchConfig: IShellLaunchConfig, cols: number, rows: number, isScreenReaderModeEnabled: boolean, reset: boolean): Promise<ITerminalLaunchError | undefined>;
write(data: string): Promise<void>;

View file

@ -52,8 +52,8 @@ export class LocalPty extends Disposable implements ITerminalChildProcess {
start(): Promise<ITerminalLaunchError | undefined> {
return this._localPtyService.start(this.id);
}
detach(): Promise<void> {
return this._localPtyService.detachFromProcess(this.id);
detach(forcePersist?: boolean): Promise<void> {
return this._localPtyService.detachFromProcess(this.id, forcePersist);
}
shutdown(immediate: boolean): void {
this._localPtyService.shutdown(this.id, immediate);