feat: Eugeny/tabby#6518 add disconnect tab context menu item

This commit is contained in:
Clem Fern 2023-06-15 21:17:58 +02:00
parent cea5cc73ff
commit b0350b6a35
2 changed files with 27 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import { GetRecoveryTokenOptions, RecoveryToken } from 'tabby-core'
export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProfile> extends BaseTerminalTabComponent<P> {
protected reconnectOffered = false
protected isDisconnectedByHand = false
constructor (protected injector: Injector) {
super(injector)
@ -44,6 +45,7 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
*/
async initializeSession (): Promise<void> {
this.reconnectOffered = false
this.isDisconnectedByHand = false
}
/**
@ -53,7 +55,7 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
super.onSessionDestroyed()
if (this.frontend) {
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
if (this.profile.behaviorOnSessionEnd === 'reconnect' && !this.isDisconnectedByHand) {
this.reconnect()
} else if (this.profile.behaviorOnSessionEnd === 'keep' || !this.doesTabShouldBeDestroyedOnSessionClosed()) {
this.offerReconnection()
@ -77,6 +79,16 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
}
}
/**
* Return true if tab should be destroyed on session closed.
*/
protected doesTabShouldBeDestroyedOnSessionClosed (): boolean {
if (this.isDisconnectedByHand) {
return false
}
return super.doesTabShouldBeDestroyedOnSessionClosed()
}
async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise<RecoveryToken> {
return {
type: `app:${this.profile.type}-tab`,
@ -85,6 +97,11 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
}
}
async disconnect (): Promise<void> {
this.isDisconnectedByHand = true
await this.session?.destroy()
}
async reconnect (): Promise<void> {
this.session?.destroy()
await this.initializeSession()

View File

@ -99,6 +99,15 @@ export class ReconnectContextMenu extends TabContextMenuItemProvider {
async getItems (tab: BaseTabComponent): Promise<MenuItemOptions[]> {
if (tab instanceof ConnectableTerminalTabComponent) {
return [
{
label: this.translate.instant('Disconnect'),
click: (): void => {
setTimeout(() => {
tab.disconnect()
this.notifications.notice(this.translate.instant('Disconnect'))
})
},
},
{
label: this.translate.instant('Reconnect'),
click: (): void => {