@@ -205,6 +205,12 @@ const App = () => {
205
205
}
206
206
} ;
207
207
208
+ // Detect if we're on a mobile device
209
+ const isMobileDevice = ( ) => {
210
+ return / A n d r o i d | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i / i. test ( navigator . userAgent ) ||
211
+ ( navigator . maxTouchPoints && navigator . maxTouchPoints > 2 ) ;
212
+ } ;
213
+
208
214
// Request notification permission
209
215
const requestNotificationPermission = async ( ) => {
210
216
if ( 'Notification' in window && Notification . permission === 'default' ) {
@@ -213,9 +219,28 @@ const App = () => {
213
219
} ;
214
220
215
221
// Show notification when rest timer completes
216
- const showRestCompleteNotification = ( ) => {
222
+ const showRestCompleteNotification = async ( ) => {
217
223
try {
218
224
if ( 'Notification' in window && Notification . permission === 'granted' ) {
225
+ // For mobile devices, try to use service worker for better reliability
226
+ if ( isMobileDevice ( ) && 'serviceWorker' in navigator ) {
227
+ const registration = await navigator . serviceWorker . ready ;
228
+
229
+ // Check if the service worker supports showNotification
230
+ if ( registration . showNotification ) {
231
+ await registration . showNotification ( 'Get back to work!' , {
232
+ body : 'Your rest time is over. Time for the next set!' ,
233
+ icon : '/icon-192x192.png' ,
234
+ badge : '/icon-192x192.png' ,
235
+ tag : 'rest-timer' ,
236
+ requireInteraction : false ,
237
+ silent : false
238
+ } ) ;
239
+ return ;
240
+ }
241
+ }
242
+
243
+ // Fallback to regular notification for desktop or when service worker isn't available
219
244
new Notification ( 'Get back to work!' , {
220
245
body : 'Your rest time is over. Time for the next set!' ,
221
246
icon : '/icon-192x192.png' ,
0 commit comments