mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 05:20:01 +00: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> {
|
export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProfile> extends BaseTerminalTabComponent<P> {
|
||||||
|
|
||||||
protected reconnectOffered = false
|
protected reconnectOffered = false
|
||||||
|
protected isDisconnectedByHand = false
|
||||||
|
|
||||||
constructor (protected injector: Injector) {
|
constructor (protected injector: Injector) {
|
||||||
super(injector)
|
super(injector)
|
||||||
@ -44,6 +45,7 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
|
|||||||
*/
|
*/
|
||||||
async initializeSession (): Promise<void> {
|
async initializeSession (): Promise<void> {
|
||||||
this.reconnectOffered = false
|
this.reconnectOffered = false
|
||||||
|
this.isDisconnectedByHand = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +55,7 @@ export abstract class ConnectableTerminalTabComponent<P extends BaseTerminalProf
|
|||||||
super.onSessionDestroyed()
|
super.onSessionDestroyed()
|
||||||
|
|
||||||
if (this.frontend) {
|
if (this.frontend) {
|
||||||
if (this.profile.behaviorOnSessionEnd === 'reconnect') {
|
if (this.profile.behaviorOnSessionEnd === 'reconnect' && !this.isDisconnectedByHand) {
|
||||||
this.reconnect()
|
this.reconnect()
|
||||||
} else if (this.profile.behaviorOnSessionEnd === 'keep' || !this.doesTabShouldBeDestroyedOnSessionClosed()) {
|
} else if (this.profile.behaviorOnSessionEnd === 'keep' || !this.doesTabShouldBeDestroyedOnSessionClosed()) {
|
||||||
this.offerReconnection()
|
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> {
|
async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise<RecoveryToken> {
|
||||||
return {
|
return {
|
||||||
type: `app:${this.profile.type}-tab`,
|
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> {
|
async reconnect (): Promise<void> {
|
||||||
this.session?.destroy()
|
this.session?.destroy()
|
||||||
await this.initializeSession()
|
await this.initializeSession()
|
||||||
|
@ -99,6 +99,15 @@ export class ReconnectContextMenu extends TabContextMenuItemProvider {
|
|||||||
async getItems (tab: BaseTabComponent): Promise<MenuItemOptions[]> {
|
async getItems (tab: BaseTabComponent): Promise<MenuItemOptions[]> {
|
||||||
if (tab instanceof ConnectableTerminalTabComponent) {
|
if (tab instanceof ConnectableTerminalTabComponent) {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
label: this.translate.instant('Disconnect'),
|
||||||
|
click: (): void => {
|
||||||
|
setTimeout(() => {
|
||||||
|
tab.disconnect()
|
||||||
|
this.notifications.notice(this.translate.instant('Disconnect'))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: this.translate.instant('Reconnect'),
|
label: this.translate.instant('Reconnect'),
|
||||||
click: (): void => {
|
click: (): void => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user