diff options
| author | Jomar Milan <jomarm@pyrodax.com> | 2026-08-25 22:55:39 -0700 |
|---|---|---|
| committer | Jomar Milan <jomarm@pyrodax.com> | 2026-08-25 22:55:39 -0700 |
| commit | cceee3279435b12fd25330447e3f031bbc34a21f (patch) | |
| tree | 9b12bedcabff57f4f7901a7cf2727293ab0b47ab /src | |
| parent | 8e11743a9f0017310d2ba01103df31c9a6ff615d (diff) | |
| parent | d5272ffc9d4103bf3fc2dc6e5df6cfa734582b62 (diff) | |
Merge notification click and OSC 777 feature branch
Merges the branch from https://github.com/MacaylaMarvelous81/tabby-osc-notify/pull/1
which implements tab focus when clicking a notification and handling for OSC 777
notifications.
Diffstat (limited to 'src')
| -rw-r--r-- | src/osc-notify-decorator.ts | 24 | ||||
| -rw-r--r-- | src/osc-notify-middleware.ts | 27 |
2 files changed, 40 insertions, 11 deletions
diff --git a/src/osc-notify-decorator.ts b/src/osc-notify-decorator.ts index 7d32f1c..4beb029 100644 --- a/src/osc-notify-decorator.ts +++ b/src/osc-notify-decorator.ts @@ -1,25 +1,41 @@ 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<any>): void { // Subscribe to attach to future sessions in this tab tab.sessionChanged$.subscribe((session) => { if (session) { - this.attachToSession(session, (<any>tab).title); + this.attachToSession(session, tab); } }); // Attach the current session for this tab if (tab.session) { - this.attachToSession(tab.session, (<any>tab).title); + this.attachToSession(tab.session, tab); } } - private attachToSession(session: BaseSession, tabTitle: string) { - const middleware = new OscNotifyMiddleware(tabTitle); + private attachToSession(session: BaseSession, tab: BaseTerminalTabComponent<any>) { + const middleware = new OscNotifyMiddleware( + () => (<any>tab).customTitle || (<any>tab).title, + () => { + this.hostWindow.bringToFront(); + const parent = this.app.getParentTab(tab); + this.app.selectTab(parent ?? tab); + parent?.focus(tab); + }, + ); session.middleware.push(middleware); } diff --git a/src/osc-notify-middleware.ts b/src/osc-notify-middleware.ts index 15548f4..5bd7108 100644 --- a/src/osc-notify-middleware.ts +++ b/src/osc-notify-middleware.ts @@ -5,12 +5,14 @@ const oscPrefix = Buffer.from("\x1b]"); const oscSuffix = Buffer.from("\x07"); export default class OscNotifyMiddleware extends SessionMiddleware { - tabTitle: string; + getTitle: () => string; + onClick: () => void; - constructor(tabTitle: string) { + constructor(getTitle: () => string, onClick: () => void) { super(); - this.tabTitle = tabTitle; + this.getTitle = getTitle; + this.onClick = onClick; } get cwdReported$(): Observable<string> { @@ -22,6 +24,7 @@ export default class OscNotifyMiddleware extends SessionMiddleware { private cwdReported = new Subject<string>(); private copyRequested = new Subject<string>(); + private notifications: Notification[] = []; feedFromSession(data: Buffer): void { let startIndex = 0; @@ -36,10 +39,12 @@ export default class OscNotifyMiddleware extends SessionMiddleware { const oscCode = parseInt(oscCodeString); if (oscCode === 9) { - // TODO: onclick switch to tab - new Notification(this.tabTitle, { - body: oscParams[0] - }); + const body = oscParams.slice().join(";"); + this.showNotification(this.getTitle(), body); + } else if (oscCode === 777 && oscParams[0] === "notify") { + const title = oscParams[1] || this.getTitle(); + const body = oscParams.slice(2).join(";"); + this.showNotification(title, body); } else { continue; } @@ -48,7 +53,15 @@ export default class OscNotifyMiddleware extends SessionMiddleware { super.feedFromSession(data); } + private showNotification(title: string, body: string): void { + const notification = new Notification(title || "Terminal", { body }); + notification.onclick = () => this.onClick(); + this.notifications.push(notification); + } + close(): void { + this.notifications.forEach((notification) => notification.close()); + this.notifications = []; this.cwdReported.complete(); this.copyRequested.complete(); super.close(); |
