1
1
mirror of https://github.com/Eugeny/tabby.git synced 2025-01-03 16:12:50 +03:00

better tab recovery (fixes #501, fixes #2214, fixes #2185)

This commit is contained in:
Eugene Pankov 2020-03-16 21:40:22 +01:00
parent eb0d8615e1
commit 6cb5505ded
4 changed files with 40 additions and 28 deletions

View File

@ -133,9 +133,7 @@ export class AppRootComponent {
})
this.hostApp.windowCloseRequest$.subscribe(async () => {
if (await this.app.closeAllTabs()) {
this.hostApp.closeWindow()
}
this.app.closeWindow()
})
if (window['safeModeReason']) {

View File

@ -13,8 +13,6 @@ export class WindowControlsComponent {
constructor (public hostApp: HostAppService, public app: AppService) { }
async closeWindow () {
if (await this.app.closeAllTabs()) {
this.hostApp.closeWindow()
}
this.app.closeWindow()
}
}

View File

@ -74,32 +74,30 @@ export class AppService {
private tabsService: TabsService,
private ngbModal: NgbModal,
) {
if (hostApp.getWindow().id === 1) {
if (config.store.terminal.recoverTabs) {
this.tabRecovery.recoverTabs().then(tabs => {
for (const tab of tabs) {
this.openNewTabRaw(tab.type, tab.options)
}
this.startTabStorage()
})
} else {
/** Continue to store the tabs even if the setting is currently off */
this.startTabStorage()
}
}
hostApp.windowFocused$.subscribe(() => {
this._activeTab?.emitFocused()
})
}
startTabStorage (): void {
this.tabsChanged$.subscribe(() => {
this.tabRecovery.saveTabs(this.tabs)
})
setInterval(() => {
this.tabRecovery.saveTabs(this.tabs)
}, 30000)
if (hostApp.getWindow().id === 1) {
if (config.store.terminal.recoverTabs) {
this.tabRecovery.recoverTabs().then(tabs => {
for (const tab of tabs) {
this.openNewTabRaw(tab.type, tab.options)
}
this.tabRecovery.enabled = true
})
} else {
/** Continue to store the tabs even if the setting is currently off */
this.tabRecovery.enabled = true
}
}
hostApp.windowFocused$.subscribe(() => {
this._activeTab?.emitFocused()
})
}
addTabRaw (tab: BaseTabComponent, index: number|null = null): void {
@ -295,6 +293,16 @@ export class AppService {
return true
}
async closeWindow (): Promise<void> {
this.tabRecovery.enabled = false
await this.tabRecovery.saveTabs(this.tabs)
if (await this.closeAllTabs()) {
this.hostApp.closeWindow()
} else {
this.tabRecovery.enabled = true
}
}
/** @hidden */
emitReady (): void {
this.ready.next()

View File

@ -8,6 +8,7 @@ import { ConfigService } from '../services/config.service'
@Injectable({ providedIn: 'root' })
export class TabRecoveryService {
logger: Logger
enabled = false
constructor (
@Inject(TabRecoveryProvider) private tabRecoveryProviders: TabRecoveryProvider[],
@ -18,6 +19,9 @@ export class TabRecoveryService {
}
async saveTabs (tabs: BaseTabComponent[]): Promise<void> {
if (!this.enabled) {
return
}
window.localStorage.tabsRecovery = JSON.stringify(
await Promise.all(
tabs
@ -25,8 +29,11 @@ export class TabRecoveryService {
let token = tab.getRecoveryToken()
if (token) {
token = token.then(r => {
if (r && tab.color) {
r.tabColor = tab.color
if (r) {
r.tabTitle = tab.title
if (tab.color) {
r.tabColor = tab.color
}
}
return r
})
@ -45,6 +52,7 @@ export class TabRecoveryService {
if (tab !== null) {
tab.options = tab.options || {}
tab.options.color = token.tabColor || null
tab.options.title = token.tabTitle || ''
return tab
}
} catch (error) {