import OscNotifyMiddleware from "./osc-notify-middleware"; import { Injectable } from "@angular/core"; import { TerminalDecorator, BaseSession, BaseTerminalTabComponent } from "tabby-terminal"; import { AppService, HostWindowService } from "tabby-core"; @Injectable() export default class OscNotifyDecorator extends TerminalDecorator { constructor( private app: AppService, private hostWindow: HostWindowService, ) { super(); } attach(tab: BaseTerminalTabComponent): void { // Subscribe to attach to future sessions in this tab tab.sessionChanged$.subscribe((session) => { if (session) { this.attachToSession(session, tab); } }); // Attach the current session for this tab if (tab.session) { this.attachToSession(tab.session, tab); } } private attachToSession(session: BaseSession, tab: BaseTerminalTabComponent) { const middleware = new OscNotifyMiddleware( () => (tab).customTitle || (tab).title, () => { this.hostWindow.bringToFront(); const parent = this.app.getParentTab(tab); this.app.selectTab(parent ?? tab); parent?.focus(tab); }, ); session.middleware.push(middleware); } }