test: improve rollover detection and UI auto-refresh
- Normalize alarm time seconds to :00 for consistent comparison - Compare dates (YYYY-MM-DD) instead of full timestamps to detect rollover - Expand logcat search patterns to catch all rollover logs (DN|RESCHEDULE, etc.) - Add 5-second wait after notification fire to allow rollover processing - UI: Normalize seconds display to :00 in all time displays - UI: Add auto-refresh mechanism that detects nextNotificationTime changes - UI: Poll every 3 seconds and force refresh when rollover detected - UI: Initialize tracking variable on page load for change detection Fixes issue where test passed but alarm time didn't actually change, and UI wasn't updating to show rescheduled notification time after rollover.
This commit is contained in:
@@ -162,6 +162,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Format date/time with seconds normalized to :00
|
||||
function formatDateTimeNormalized(timestamp) {
|
||||
if (!timestamp || timestamp === 0) return 'None scheduled';
|
||||
const date = new Date(timestamp);
|
||||
// Normalize seconds to :00
|
||||
date.setSeconds(0, 0);
|
||||
// Format as: MM/DD/YYYY, HH:MM:00 AM/PM
|
||||
const options = {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: true
|
||||
};
|
||||
return date.toLocaleString('en-US', options);
|
||||
}
|
||||
|
||||
function loadPluginStatus() {
|
||||
console.log('loadPluginStatus called');
|
||||
const pluginStatusContent = document.getElementById('pluginStatusContent');
|
||||
@@ -175,7 +194,7 @@
|
||||
}
|
||||
window.DailyNotification.getNotificationStatus()
|
||||
.then(result => {
|
||||
const nextTime = result.nextNotificationTime ? new Date(result.nextNotificationTime).toLocaleString() : 'None scheduled';
|
||||
const nextTime = formatDateTimeNormalized(result.nextNotificationTime);
|
||||
const hasSchedules = result.isEnabled || (result.pending && result.pending > 0);
|
||||
const statusIcon = hasSchedules ? '✅' : '⏸️';
|
||||
pluginStatusContent.innerHTML = `${statusIcon} Active Schedules: ${hasSchedules ? 'Yes' : 'No'}<br>
|
||||
@@ -233,8 +252,11 @@
|
||||
priority: 'high'
|
||||
})
|
||||
.then(() => {
|
||||
const prefetchTimeReadable = prefetchTime.toLocaleTimeString();
|
||||
const notificationTimeReadable = notificationTime.toLocaleTimeString();
|
||||
// Normalize seconds to :00 for display
|
||||
prefetchTime.setSeconds(0, 0);
|
||||
notificationTime.setSeconds(0, 0);
|
||||
const prefetchTimeReadable = prefetchTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true });
|
||||
const notificationTimeReadable = notificationTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true });
|
||||
status.innerHTML = '✅ Notification scheduled!<br>' +
|
||||
'📥 Prefetch: ' + prefetchTimeReadable + ' (' + prefetchTimeString + ')<br>' +
|
||||
'🔔 Notification: ' + notificationTimeReadable + ' (' + notificationTimeString + ')<br><br>' +
|
||||
@@ -417,12 +439,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Check for notification delivery periodically
|
||||
// Track last known nextNotificationTime to detect changes
|
||||
let lastKnownNextNotificationTime = null;
|
||||
|
||||
// Check for notification delivery and status updates periodically
|
||||
function checkNotificationDelivery() {
|
||||
if (!window.DailyNotification) return;
|
||||
|
||||
window.DailyNotification.getNotificationStatus()
|
||||
.then(result => {
|
||||
// Check for notification delivery
|
||||
if (result.lastNotificationTime) {
|
||||
const lastTime = new Date(result.lastNotificationTime);
|
||||
const now = new Date();
|
||||
@@ -435,15 +461,37 @@
|
||||
|
||||
if (indicator && timeSpan) {
|
||||
indicator.style.display = 'block';
|
||||
timeSpan.textContent = `Received at ${lastTime.toLocaleTimeString()}`;
|
||||
// Normalize seconds to :00
|
||||
lastTime.setSeconds(0, 0);
|
||||
timeSpan.textContent = `Received at ${lastTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: true })}`;
|
||||
|
||||
// Hide after 30 seconds
|
||||
setTimeout(() => {
|
||||
indicator.style.display = 'none';
|
||||
}, 30000);
|
||||
|
||||
// Force immediate refresh when notification is received (rollover may have occurred)
|
||||
setTimeout(() => {
|
||||
loadPluginStatus();
|
||||
}, 1000); // Wait 1 second for rollover to complete
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect if nextNotificationTime changed (rollover occurred)
|
||||
const currentNextTime = result.nextNotificationTime;
|
||||
if (currentNextTime && currentNextTime !== lastKnownNextNotificationTime) {
|
||||
if (lastKnownNextNotificationTime !== null) {
|
||||
console.log('Next notification time changed - rollover detected!');
|
||||
// Force immediate refresh
|
||||
loadPluginStatus();
|
||||
}
|
||||
lastKnownNextNotificationTime = currentNextTime;
|
||||
}
|
||||
|
||||
// Auto-refresh plugin status periodically to show updated next notification time after rollover
|
||||
// This ensures the UI updates when the plugin reschedules the notification
|
||||
loadPluginStatus();
|
||||
})
|
||||
.catch(error => {
|
||||
// Silently fail - this is just for visual feedback
|
||||
@@ -459,8 +507,19 @@
|
||||
loadPermissionStatus();
|
||||
loadChannelStatus();
|
||||
|
||||
// Check for notification delivery every 5 seconds
|
||||
setInterval(checkNotificationDelivery, 5000);
|
||||
// Initialize last known next notification time
|
||||
if (window.DailyNotification) {
|
||||
window.DailyNotification.getNotificationStatus()
|
||||
.then(result => {
|
||||
lastKnownNextNotificationTime = result.nextNotificationTime;
|
||||
console.log('Initialized nextNotificationTime:', lastKnownNextNotificationTime);
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
// Check for notification delivery and status updates every 3 seconds (more frequent)
|
||||
// This ensures UI updates quickly when rollover occurs
|
||||
setInterval(checkNotificationDelivery, 3000);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user