Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

fix(push): close the previous rest-over notification before showing the next

2baek239b80c6fbb1c
diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.js
index 061256e16..8e3cedcf6 100644
--- a/frontend/src/store/useUI.js
+++ b/frontend/src/store/useUI.js
@@ -69,6 +69,9 @@ const maybeRestNotification = async () => {
// Android Chrome forbids the Notification constructor (Illegal constructor) - the
// service-worker registration path is the one that actually pops there.
const opts = { tag: 'rest-timer', icon: 'icon-512.png' }
+ // iOS ignores the tag replacement (issue #172): close the previous one by hand, as the
+ // worker does on a push, or the end of a rest leaves two banners stacked there.
+ try { for (const n of (await reg?.getNotifications?.({ tag: 'rest-timer' })) || []) n.close() } catch { /* no getNotifications: the tag is all there is */ }
if (reg?.showNotification) { reg.showNotification(t('Rest’s over. Next set!'), opts); return }
new Notification(t('Rest’s over. Next set!'), opts)
} catch {
diff --git a/frontend/src/store/useUI.rest-alert.test.js b/frontend/src/store/useUI.rest-alert.test.js
index c9ade2241..d0a674da2 100644
--- a/frontend/src/store/useUI.rest-alert.test.js
+++ b/frontend/src/store/useUI.rest-alert.test.js
@@ -6,7 +6,7 @@ import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'
import { useUI } from './useUI.js'
import { useStore } from './useStore.js'
-let showNotification, requestPermission, subscription, originalSettings
+let showNotification, getNotifications, requestPermission, subscription, originalSettings
const hide = hidden => {
Object.defineProperty(document, 'hidden', { configurable: true, get: () => hidden })
Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => hidden ? 'hidden' : 'visible' })
@@ -24,13 +24,14 @@ beforeEach(() => {
useStore.setState({ S: { ...originalSettings, sound: false }, user: null })
useUI.setState({ timer: null })
showNotification = vi.fn()
+ getNotifications = vi.fn(async () => [])
requestPermission = vi.fn(async () => 'granted')
subscription = null
globalThis.Notification = Object.assign(vi.fn(), { permission: 'granted', requestPermission })
window.Notification = globalThis.Notification
Object.defineProperty(navigator, 'serviceWorker', {
configurable: true,
- value: { getRegistration: async () => ({ showNotification, pushManager: { getSubscription: async () => subscription } }) },
+ value: { getRegistration: async () => ({ showNotification, getNotifications, pushManager: { getSubscription: async () => subscription } }) },
})
})
afterEach(() => {
@@ -57,6 +58,18 @@ describe('the local rest-over alert follows the Push switch', () => {
expect(opts.body).toBeUndefined()
})
+ // iOS ignores a tag's replacement (issue #172), so the page closes the previous one by hand
+ // before showing its own — the worker already does this on a push.
+ it('closes the previous rest-timer notification before showing the next', async () => {
+ subscription = { endpoint: 'https://push.example/x' }
+ const order = []
+ getNotifications.mockImplementation(async ({ tag }) => [{ tag, close: () => order.push('close') }])
+ showNotification.mockImplementation(() => order.push('show'))
+ await runOut()
+ expect(getNotifications).toHaveBeenCalledWith({ tag: 'rest-timer' })
+ expect(order).toEqual(['close', 'show'])
+ })
+
it('never asks for the permission by itself — only the switch does', async () => {
globalThis.Notification.permission = 'default'
await runOut()