plug some leaks

This commit is contained in:
Eugene Pankov 2022-01-13 23:45:11 +01:00
parent 5b4a1a5581
commit 17c93aa3fc
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
3 changed files with 8 additions and 42 deletions

View File

@ -6,13 +6,12 @@ import { trigger, transition, style, animate, AnimationTriggerMetadata } from '@
import { AppService, ConfigService, BaseTabComponent, HostAppService, HotkeysService, NotificationsService, Platform, LogService, Logger, TabContextMenuItemProvider, SplitTabComponent, SubscriptionContainer, MenuItemOptions, PlatformService, HostWindowService, ResettableTimeout, TranslateService } from 'tabby-core'
import { BaseSession } from '../session'
import { TerminalFrontendService } from '../services/terminalFrontend.service'
import { Frontend } from '../frontends/frontend'
import { XTermFrontend, XTermWebGLFrontend } from '../frontends/xtermFrontend'
import { ResizeEvent } from './interfaces'
import { TerminalDecorator } from './decorator'
/**
* A class to base your custom terminal tabs on
*/
@ -112,7 +111,6 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
protected hostApp: HostAppService
protected hotkeys: HotkeysService
protected platform: PlatformService
protected terminalContainersService: TerminalFrontendService
protected notifications: NotificationsService
protected log: LogService
protected decorators: TerminalDecorator[] = []
@ -181,7 +179,6 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.hostApp = injector.get(HostAppService)
this.hotkeys = injector.get(HotkeysService)
this.platform = injector.get(PlatformService)
this.terminalContainersService = injector.get(TerminalFrontendService)
this.notifications = injector.get(NotificationsService)
this.log = injector.get(LogService)
this.decorators = injector.get<any>(TerminalDecorator, null, InjectFlags.Optional) as TerminalDecorator[]
@ -294,7 +291,11 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.frontend?.focus()
})
this.frontend = this.terminalContainersService.getFrontend(this.session)
const cls: new (..._) => Frontend = {
xterm: XTermFrontend,
'xterm-webgl': XTermWebGLFrontend,
}[this.config.store.terminal.frontend] ?? XTermFrontend
this.frontend = new cls(this.injector)
this.frontendReady$.pipe(first()).subscribe(() => {
this.onFrontendReady()
@ -555,6 +556,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
async destroy (): Promise<void> {
this.frontend?.detach(this.content.nativeElement)
this.frontend?.destroy()
this.frontend = undefined
this.content.nativeElement.remove()
this.detachTermContainerHandlers()
@ -731,7 +733,6 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
if (destroyOnSessionClose) {
this.attachSessionHandler(this.session.closed$, () => {
this.frontend?.destroy()
this.destroy()
})
}

View File

@ -16,8 +16,6 @@ import { SearchPanelComponent } from './components/searchPanel.component'
import { StreamProcessingSettingsComponent } from './components/streamProcessingSettings.component'
import { LoginScriptsSettingsComponent } from './components/loginScriptsSettings.component'
import { TerminalFrontendService } from './services/terminalFrontend.service'
import { TerminalDecorator } from './api/decorator'
import { TerminalContextMenuItemProvider } from './api/contextMenuProvider'
import { TerminalColorSchemeProvider } from './api/colorSchemeProvider'
@ -83,7 +81,7 @@ import { TerminalCLIHandler } from './cli'
})
export default class TerminalModule { } // eslint-disable-line @typescript-eslint/no-extraneous-class
export { TerminalFrontendService, TerminalDecorator, TerminalContextMenuItemProvider, TerminalColorSchemeProvider }
export { TerminalDecorator, TerminalContextMenuItemProvider, TerminalColorSchemeProvider }
export { Frontend, XTermFrontend, XTermWebGLFrontend }
export { BaseTerminalTabComponent } from './api/baseTerminalTab.component'
export * from './api/interfaces'

View File

@ -1,33 +0,0 @@
import { Injectable, Injector } from '@angular/core'
import { ConfigService } from 'tabby-core'
import { Frontend } from '../frontends/frontend'
import { XTermFrontend, XTermWebGLFrontend } from '../frontends/xtermFrontend'
import { BaseSession } from '../session'
@Injectable({ providedIn: 'root' })
export class TerminalFrontendService {
private containers = new WeakMap<BaseSession, Frontend>()
/** @hidden */
private constructor (
private config: ConfigService,
private injector: Injector,
) { }
getFrontend (session?: BaseSession|null): Frontend {
if (!session) {
const cls = {
xterm: XTermFrontend,
'xterm-webgl': XTermWebGLFrontend,
}[this.config.store.terminal.frontend] ?? XTermFrontend
return new cls(this.injector)
}
if (!this.containers.has(session)) {
this.containers.set(
session,
this.getFrontend(),
)
}
return this.containers.get(session)!
}
}