Skip to content

Commit

Permalink
feat: #6518 add disconnect tab context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
Clem-Fern committed Jun 15, 2023
1 parent cea5cc7 commit b0350b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tabby-terminal/src/api/connectableTerminalTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -44,6 +45,7 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
*/
async initializeSession (): Promise<void> {
this.reconnectOffered = false
this.isDisconnectedByHand = false
}

/**
Expand All @@ -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()
Expand All @@ -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`,
Expand All @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions tabby-terminal/src/tabContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit b0350b6

Please sign in to comment.