@ -421,16 +421,38 @@
async function scheduleNotification() {
async function scheduleNotification() {
updateStatus('info', '⏰ Scheduling notification...');
updateStatus('info', '⏰ Scheduling notification...');
try {
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 = {
const options = {
url: document.getElementById('notificationUrl').value,
url: document.getElementById('notificationUrl').value,
time: document.getElementById('notificationTime').value,
time: timeInput ,
title: document.getElementById('notificationTitle').value,
title: document.getElementById('notificationTitle').value,
body: document.getElementById('notificationBody').value,
body: document.getElementById('notificationBody').value,
sound: true,
sound: true,
priority: 'high'
priority: 'high'
};
};
await plugin.scheduleDailyNotification(options);
await plugin.scheduleDailyNotification(options);
updateStatus('success', `⏰ Notification scheduled: ${JSON.stringify(options, null, 2)}`);
updateStatus('success', `✅ Notification scheduled!< br > ` +
`📥 Prefetch: ${prefetchTimeReadable} (${prefetchTimeString})< br > ` +
`🔔 Notification: ${notificationTimeReadable} (${notificationTimeString})`);
} catch (error) {
} catch (error) {
updateStatus('error', `❌ Scheduling failed: ${error.message}`);
updateStatus('error', `❌ Scheduling failed: ${error.message}`);
}
}