mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 14:34:54 +00:00
tab duplication (fixes #588)
This commit is contained in:
@@ -5,6 +5,7 @@ import { BaseTabComponent } from '../components/baseTab.component'
|
||||
import { Logger, LogService } from './log.service'
|
||||
import { ConfigService } from './config.service'
|
||||
import { HostAppService } from './hostApp.service'
|
||||
import { TabRecoveryService } from './tabRecovery.service'
|
||||
|
||||
export declare type TabComponentType = new (...args: any[]) => BaseTabComponent
|
||||
|
||||
@@ -61,11 +62,25 @@ export class AppService {
|
||||
private config: ConfigService,
|
||||
private hostApp: HostAppService,
|
||||
private injector: Injector,
|
||||
private tabRecovery: TabRecoveryService,
|
||||
log: LogService,
|
||||
) {
|
||||
this.logger = log.create('app')
|
||||
|
||||
this.hostApp.windowCloseRequest$.subscribe(() => this.closeWindow())
|
||||
|
||||
this.tabRecovery.recoverTabs().then(tabs => {
|
||||
for (let tab of tabs) {
|
||||
this.openNewTab(tab.type, tab.options)
|
||||
}
|
||||
|
||||
this.tabsChanged$.subscribe(() => {
|
||||
tabRecovery.saveTabs(this.tabs)
|
||||
})
|
||||
setInterval(() => {
|
||||
tabRecovery.saveTabs(this.tabs)
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
openNewTab (type: TabComponentType, inputs?: any): BaseTabComponent {
|
||||
@@ -162,6 +177,17 @@ export class AppService {
|
||||
this.tabClosed.next(tab)
|
||||
}
|
||||
|
||||
async duplicateTab (tab: BaseTabComponent) {
|
||||
let token = await tab.getRecoveryToken()
|
||||
if (!token) {
|
||||
return
|
||||
}
|
||||
let recoveredTab = await this.tabRecovery.recoverTab(token)
|
||||
if (recoveredTab) {
|
||||
this.openNewTab(recoveredTab.type, recoveredTab.options)
|
||||
}
|
||||
}
|
||||
|
||||
async closeWindow () {
|
||||
for (let tab of this.tabs) {
|
||||
if (!await tab.canClose()) {
|
||||
|
@@ -2,7 +2,6 @@ import { Injectable, Inject } from '@angular/core'
|
||||
import { TabRecoveryProvider, RecoveredTab } from '../api/tabRecovery'
|
||||
import { BaseTabComponent } from '../components/baseTab.component'
|
||||
import { Logger, LogService } from '../services/log.service'
|
||||
import { AppService } from '../services/app.service'
|
||||
import { ConfigService } from '../services/config.service'
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@@ -11,17 +10,10 @@ export class TabRecoveryService {
|
||||
|
||||
constructor (
|
||||
@Inject(TabRecoveryProvider) private tabRecoveryProviders: TabRecoveryProvider[],
|
||||
private app: AppService,
|
||||
private config: ConfigService,
|
||||
log: LogService
|
||||
) {
|
||||
this.logger = log.create('tabRecovery')
|
||||
app.tabsChanged$.subscribe(() => {
|
||||
this.saveTabs(app.tabs)
|
||||
})
|
||||
setInterval(() => {
|
||||
this.saveTabs(app.tabs)
|
||||
}, 30000)
|
||||
}
|
||||
|
||||
async saveTabs (tabs: BaseTabComponent[]) {
|
||||
@@ -34,25 +26,32 @@ export class TabRecoveryService {
|
||||
)
|
||||
}
|
||||
|
||||
async recoverTabs (): Promise<void> {
|
||||
async recoverTab (token: any): Promise<RecoveredTab> {
|
||||
for (let provider of this.config.enabledServices(this.tabRecoveryProviders)) {
|
||||
try {
|
||||
let tab = await provider.recover(token)
|
||||
if (tab) {
|
||||
return tab
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.warn('Tab recovery crashed:', token, provider, error)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async recoverTabs (): Promise<RecoveredTab[]> {
|
||||
if (window.localStorage.tabsRecovery) {
|
||||
let tabs: RecoveredTab[] = []
|
||||
for (let token of JSON.parse(window.localStorage.tabsRecovery)) {
|
||||
for (let provider of this.config.enabledServices(this.tabRecoveryProviders)) {
|
||||
try {
|
||||
let tab = await provider.recover(token)
|
||||
if (tab) {
|
||||
tabs.push(tab)
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.warn('Tab recovery crashed:', token, provider, error)
|
||||
}
|
||||
let tab = await this.recoverTab(token)
|
||||
if (tab) {
|
||||
tabs.push(tab)
|
||||
}
|
||||
}
|
||||
tabs.forEach(tab => {
|
||||
this.app.openNewTab(tab.type, tab.options)
|
||||
})
|
||||
return tabs
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user