diff --git a/www/index.html b/www/index.html index 615d7cc..be40a1c 100644 --- a/www/index.html +++ b/www/index.html @@ -421,16 +421,38 @@ async function scheduleNotification() { updateStatus('info', '⏰ Scheduling notification...'); try { + const timeInput = document.getElementById('notificationTime').value; + const [hours, minutes] = timeInput.split(':'); + const now = new Date(); + const scheduledTime = new Date(); + scheduledTime.setHours(parseInt(hours), parseInt(minutes), 0, 0); + + // If scheduled time is in the past, schedule for tomorrow + if (scheduledTime <= now) { + scheduledTime.setDate(scheduledTime.getDate() + 1); + } + + // Calculate prefetch time (5 minutes before notification) + const prefetchTime = new Date(scheduledTime.getTime() - 300000); // 5 minutes + const prefetchTimeReadable = prefetchTime.toLocaleTimeString(); + const notificationTimeReadable = scheduledTime.toLocaleTimeString(); + const prefetchTimeString = prefetchTime.getHours().toString().padStart(2, '0') + ':' + + prefetchTime.getMinutes().toString().padStart(2, '0'); + const notificationTimeString = scheduledTime.getHours().toString().padStart(2, '0') + ':' + + scheduledTime.getMinutes().toString().padStart(2, '0'); + const options = { url: document.getElementById('notificationUrl').value, - time: document.getElementById('notificationTime').value, + time: timeInput, title: document.getElementById('notificationTitle').value, body: document.getElementById('notificationBody').value, sound: true, priority: 'high' }; await plugin.scheduleDailyNotification(options); - updateStatus('success', `⏰ Notification scheduled: ${JSON.stringify(options, null, 2)}`); + updateStatus('success', `✅ Notification scheduled!
` + + `📥 Prefetch: ${prefetchTimeReadable} (${prefetchTimeString})
` + + `🔔 Notification: ${notificationTimeReadable} (${notificationTimeString})`); } catch (error) { updateStatus('error', `❌ Scheduling failed: ${error.message}`); }