From 17c93aa3fc8a809e39d624c45b9dc1aa3fa72e65 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Thu, 13 Jan 2022 23:45:11 +0100 Subject: [PATCH] plug some leaks --- .../src/api/baseTerminalTab.component.ts | 13 ++++---- tabby-terminal/src/index.ts | 4 +-- .../src/services/terminalFrontend.service.ts | 33 ------------------- 3 files changed, 8 insertions(+), 42 deletions(-) delete mode 100644 tabby-terminal/src/services/terminalFrontend.service.ts diff --git a/tabby-terminal/src/api/baseTerminalTab.component.ts b/tabby-terminal/src/api/baseTerminalTab.component.ts index a4318b72..34386ef7 100644 --- a/tabby-terminal/src/api/baseTerminalTab.component.ts +++ b/tabby-terminal/src/api/baseTerminalTab.component.ts @@ -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(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 { 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() }) } diff --git a/tabby-terminal/src/index.ts b/tabby-terminal/src/index.ts index 4a8120c5..c8e59f2a 100644 --- a/tabby-terminal/src/index.ts +++ b/tabby-terminal/src/index.ts @@ -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' diff --git a/tabby-terminal/src/services/terminalFrontend.service.ts b/tabby-terminal/src/services/terminalFrontend.service.ts deleted file mode 100644 index a910d858..00000000 --- a/tabby-terminal/src/services/terminalFrontend.service.ts +++ /dev/null @@ -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() - - /** @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)! - } -}