mirror of
https://github.com/Eugeny/tabby.git
synced 2025-02-11 14:41:13 +08:00
feat: Eugeny/tabby#6518 add disconnect tab context menu item
This commit is contained in:
parent
cea5cc73ff
commit
b0350b6a35
@ -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()
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user