fix: show a notification even if building it fails

This commit is contained in:
Linus Rath
2026-11-04 03:13:56 +01:00
parent 2c462c304e
commit 33249ca57a
2 changed files with 35 additions and 1 deletions
+22
View File
@@ -187,4 +187,26 @@ describe('which login a push is for', () => {
});
});
describe('when building the notification goes wrong', () => {
it('still shows one', async () => {
const { push, shade } = loadWorker(() => ({ unreadTotal: 1, slot: 0, login: 'fp', email: mail('e1') }), {
globals: { Notification: { get maxActions() { throw new Error('no such thing'); } } },
});
await push(delivery('a', 'e1'));
expect(shade.size).toBe(1);
});
it('shows one for a push that is no JSON at all', async () => {
const { dispatch, shade } = loadWorker(() => null);
await dispatch('push', { data: { json: () => { throw new SyntaxError('not JSON'); } } });
expect(shade.size).toBe(1);
});
it('shows one for a push without any data', async () => {
const { dispatch, shade } = loadWorker(() => null);
await dispatch('push', {});
expect(shade.size).toBe(1);
});
});
// -- end of cases --
+13 -1
View File
@@ -604,7 +604,19 @@ async function handlePush(event) {
? []
: Object.keys(changed).filter((id) => changed[id] && typeof changed[id] === "object" && "EmailDelivery" in changed[id]);
for (const accountId of withNewMail.length > 0 ? withNewMail : [named]) {
await notifyAccount(accountId, emailIds, accountLabel);
try {
await notifyAccount(accountId, emailIds, accountLabel);
} catch (_) {
// Nothing above may cost the user the alert, or a browser its quota for
// this site: see showWithoutAlert.
await self.registration.showNotification(accountLabel ? `New mail (${accountLabel})` : "New mail", {
body: "You have new mail",
tag: "bulwark-mail:" + (accountId || "default"),
icon: `${BASE_PATH}/api/pwa-icon/192`,
badge: `${BASE_PATH}/api/pwa-icon/192`,
data: { kind: "mail-list", accountId },
});
}
}
}