mirror of
https://github.com/Eugeny/tabby.git
synced 2025-08-14 13:21:52 +00:00
tab duplication (fixes #588)
This commit is contained in:
@@ -9,7 +9,6 @@ import { HotkeysService } from '../services/hotkeys.service'
|
||||
import { Logger, LogService } from '../services/log.service'
|
||||
import { ConfigService } from '../services/config.service'
|
||||
import { DockingService } from '../services/docking.service'
|
||||
import { TabRecoveryService } from '../services/tabRecovery.service'
|
||||
import { ThemesService } from '../services/themes.service'
|
||||
import { UpdaterService } from '../services/updater.service'
|
||||
import { TouchbarService } from '../services/touchbar.service'
|
||||
@@ -69,7 +68,6 @@ export class AppRootComponent {
|
||||
constructor (
|
||||
private docking: DockingService,
|
||||
private electron: ElectronService,
|
||||
private tabRecovery: TabRecoveryService,
|
||||
private hotkeys: HotkeysService,
|
||||
private updater: UpdaterService,
|
||||
private touchbar: TouchbarService,
|
||||
@@ -199,9 +197,7 @@ export class AppRootComponent {
|
||||
}
|
||||
|
||||
async ngOnInit () {
|
||||
await this.tabRecovery.recoverTabs()
|
||||
this.ready = true
|
||||
this.tabRecovery.saveTabs(this.app.tabs)
|
||||
|
||||
this.app.emitReady()
|
||||
}
|
||||
|
@@ -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 []
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -67,6 +67,7 @@ export class CommonOptionsContextMenu extends TabContextMenuItemProvider {
|
||||
|
||||
constructor (
|
||||
private zone: NgZone,
|
||||
private app: AppService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -77,6 +78,10 @@ export class CommonOptionsContextMenu extends TabContextMenuItemProvider {
|
||||
label: 'Rename',
|
||||
click: () => this.zone.run(() => tabHeader.showRenameTabModal())
|
||||
},
|
||||
{
|
||||
label: 'Duplicate',
|
||||
click: () => this.zone.run(() => this.app.duplicateTab(tab))
|
||||
},
|
||||
{
|
||||
label: 'Color',
|
||||
sublabel: COLORS.find(x => x.value === tab.color).name,
|
||||
|
Reference in New Issue
Block a user