Skip to content

Commit d9e50d2

Browse files
committed
feat: limit the number of notifications shown simultaneously
1 parent cf8a442 commit d9e50d2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/thunderbird/background_util/notification_tray.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import type { INotificationTray } from "src/ghosttext-adaptor"
22
import type { MessageId } from "src/util"
33
import type { ManifestInfo } from "."
44

5+
/** Wraps the Notification API */
56
export class NotificationTray implements INotificationTray {
67
static isSingleton = true
78

9+
/** Maximum number of notifications to show simultaneously */
10+
private readonly slotCount = 5
11+
private lastId = 0
812
private title: string | undefined
913

1014
constructor(
@@ -13,7 +17,8 @@ export class NotificationTray implements INotificationTray {
1317
) {}
1418

1519
async showNotification(iconUrl: string, messageId: MessageId): Promise<void> {
16-
await this.messenger.notifications.create(this.makeNotification(iconUrl, messageId))
20+
const opts = this.makeNotification(iconUrl, messageId)
21+
await this.messenger.notifications.create(this.makeId(), opts)
1722
}
1823

1924
private makeNotification(iconUrl: string, messageId: MessageId): messenger.notifications.CreateNotificationOptions {
@@ -25,4 +30,9 @@ export class NotificationTray implements INotificationTray {
2530
message: this.messenger.i18n.getMessage(messageId),
2631
}
2732
}
33+
34+
private makeId(): string {
35+
this.lastId = (this.lastId + 1) % this.slotCount
36+
return `NotificationTray-${this.lastId}`
37+
}
2838
}

0 commit comments

Comments
 (0)