chore: sync test app UI with improved logging

- Update test app index.html with JSON.stringify improvements for better log readability
- This file is synced from www/index.html during build process
- Includes date formatting improvements for debugging UI refresh issues
This commit is contained in:
Matthew Raymer
2025-12-30 09:40:38 +00:00
parent ea4bc88808
commit f38b06abed

View File

@@ -196,22 +196,27 @@
console.log('[UI Refresh] Calling getNotificationStatus()...'); console.log('[UI Refresh] Calling getNotificationStatus()...');
window.DailyNotification.getNotificationStatus() window.DailyNotification.getNotificationStatus()
.then(result => { .then(result => {
console.log('[UI Refresh] getNotificationStatus result:', { console.log('[UI Refresh] getNotificationStatus result:', JSON.stringify({
nextNotificationTime: result.nextNotificationTime, nextNotificationTime: result.nextNotificationTime,
nextNotificationTimeDate: result.nextNotificationTime ? new Date(result.nextNotificationTime).toISOString() : null,
isEnabled: result.isEnabled, isEnabled: result.isEnabled,
pending: result.pending, pending: result.pending,
lastNotificationTime: result.lastNotificationTime lastNotificationTime: result.lastNotificationTime,
}); lastNotificationTimeDate: result.lastNotificationTime ? new Date(result.lastNotificationTime).toISOString() : null
}, null, 2));
const nextTime = formatDateTimeNormalized(result.nextNotificationTime); const nextTime = formatDateTimeNormalized(result.nextNotificationTime);
const hasSchedules = result.isEnabled || (result.pending && result.pending > 0); const hasSchedules = result.isEnabled || (result.pending && result.pending > 0);
const statusIcon = hasSchedules ? '✅' : '⏸️'; const statusIcon = hasSchedules ? '✅' : '⏸️';
console.log('[UI Refresh] Updating UI:', { console.log('[UI Refresh] Updating UI:', JSON.stringify({
nextTime: nextTime, nextTime: nextTime,
nextNotificationTimeRaw: result.nextNotificationTime,
nextNotificationTimeDate: result.nextNotificationTime ? new Date(result.nextNotificationTime).toISOString() : null,
hasSchedules: hasSchedules, hasSchedules: hasSchedules,
statusIcon: statusIcon statusIcon: statusIcon,
}); pending: result.pending
}, null, 2));
pluginStatusContent.innerHTML = `${statusIcon} Active Schedules: ${hasSchedules ? 'Yes' : 'No'}<br> pluginStatusContent.innerHTML = `${statusIcon} Active Schedules: ${hasSchedules ? 'Yes' : 'No'}<br>
📅 Next Notification: ${nextTime}<br> 📅 Next Notification: ${nextTime}<br>
@@ -472,11 +477,14 @@
console.log('[Poll] checkNotificationDelivery called'); console.log('[Poll] checkNotificationDelivery called');
window.DailyNotification.getNotificationStatus() window.DailyNotification.getNotificationStatus()
.then(result => { .then(result => {
console.log('[Poll] Status check result:', { console.log('[Poll] Status check result:', JSON.stringify({
nextNotificationTime: result.nextNotificationTime, nextNotificationTime: result.nextNotificationTime,
nextNotificationTimeDate: result.nextNotificationTime ? new Date(result.nextNotificationTime).toISOString() : null,
lastNotificationTime: result.lastNotificationTime, lastNotificationTime: result.lastNotificationTime,
lastKnownNextNotificationTime: lastKnownNextNotificationTime lastNotificationTimeDate: result.lastNotificationTime ? new Date(result.lastNotificationTime).toISOString() : null,
}); lastKnownNextNotificationTime: lastKnownNextNotificationTime,
lastKnownNextNotificationTimeDate: lastKnownNextNotificationTime ? new Date(lastKnownNextNotificationTime).toISOString() : null
}, null, 2));
// Check for notification delivery // Check for notification delivery
if (result.lastNotificationTime) { if (result.lastNotificationTime) {
@@ -520,11 +528,13 @@
// Detect if nextNotificationTime changed (rollover occurred) // Detect if nextNotificationTime changed (rollover occurred)
const currentNextTime = result.nextNotificationTime; const currentNextTime = result.nextNotificationTime;
console.log('[Poll] Comparing nextNotificationTime:', { console.log('[Poll] Comparing nextNotificationTime:', JSON.stringify({
current: currentNextTime, current: currentNextTime,
currentDate: currentNextTime ? new Date(currentNextTime).toISOString() : null,
lastKnown: lastKnownNextNotificationTime, lastKnown: lastKnownNextNotificationTime,
lastKnownDate: lastKnownNextNotificationTime ? new Date(lastKnownNextNotificationTime).toISOString() : null,
changed: currentNextTime && currentNextTime !== lastKnownNextNotificationTime changed: currentNextTime && currentNextTime !== lastKnownNextNotificationTime
}); }, null, 2));
if (currentNextTime && currentNextTime !== lastKnownNextNotificationTime) { if (currentNextTime && currentNextTime !== lastKnownNextNotificationTime) {
if (lastKnownNextNotificationTime !== null) { if (lastKnownNextNotificationTime !== null) {
@@ -580,6 +590,56 @@
}, 500); }, 500);
}); });
// Refresh UI when app comes back to foreground (after force-stop, app resume, etc.)
// This ensures the UI updates after recovery from force-stop
document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
console.log('[Visibility] App became visible, refreshing UI status...');
// Small delay to allow recovery to complete
setTimeout(() => {
loadPluginStatus();
loadPermissionStatus();
loadChannelStatus();
// Also check for recent notifications that might have been missed
if (window.DailyNotification) {
window.DailyNotification.getNotificationStatus()
.then(result => {
// Check if a notification was received recently (within last 2 minutes)
if (result.lastNotificationTime) {
const lastTime = new Date(result.lastNotificationTime);
const now = new Date();
const timeDiff = now - lastTime;
if (timeDiff > 0 && timeDiff < 120000) {
console.log('[Visibility] Recent notification detected, showing indicator');
const indicator = document.getElementById('notificationReceivedIndicator');
const timeSpan = document.getElementById('notificationReceivedTime');
if (indicator && timeSpan) {
indicator.style.display = 'block';
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);
}
}
}
// Update last known next notification time
lastKnownNextNotificationTime = result.nextNotificationTime;
})
.catch(error => {
console.error('[Visibility] Failed to get notification status:', error);
});
}
}, 1000); // Wait 1 second for recovery to complete
}
});
console.log('Functions attached to window:', { console.log('Functions attached to window:', {