diff options
Diffstat (limited to 'src/osc-notify-middleware.ts')
| -rw-r--r-- | src/osc-notify-middleware.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/osc-notify-middleware.ts b/src/osc-notify-middleware.ts index 15548f4..ad2946c 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,11 @@ export default class OscNotifyMiddleware extends SessionMiddleware { const oscCode = parseInt(oscCodeString); if (oscCode === 9) { - // TODO: onclick switch to tab - new Notification(this.tabTitle, { + const notification = new Notification(this.getTitle() || "Terminal", { body: oscParams[0] }); + notification.onclick = () => this.onClick(); + this.notifications.push(notification); } else { continue; } @@ -49,6 +53,8 @@ export default class OscNotifyMiddleware extends SessionMiddleware { } close(): void { + this.notifications.forEach((notification) => notification.close()); + this.notifications = []; this.cwdReported.complete(); this.copyRequested.complete(); super.close(); |
