Clean up debug logging from notification system

- Remove verbose debug console logs from alarm scheduler
- Remove debug logs from notification manager
- Keep essential error logging for troubleshooting
- Maintain clean, production-ready code
- System functionality unchanged

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-09-21 21:22:19 -04:00
parent 1538869f4a
commit 7caf3539f7
3 changed files with 13 additions and 202 deletions

View File

@@ -244,7 +244,6 @@ pub fn App() -> Html {
let interval = {
let alarm_scheduler_ref = alarm_scheduler.clone();
Interval::new(30_000, move || {
web_sys::console::log_1(&"🕐 DEBUG: Alarm check interval firing".into());
// Get a fresh copy of the current scheduler state each time
let mut scheduler = (*alarm_scheduler_ref).clone();
let triggered_count = scheduler.check_and_trigger_alarms();
@@ -253,8 +252,6 @@ pub fn App() -> Html {
web_sys::console::log_1(
&format!("🔔 Triggered {} alarm(s)", triggered_count).into()
);
} else {
web_sys::console::log_1(&"🕐 DEBUG: No alarms triggered this check".into());
}
// Update the scheduler state with any changes (like alarm status updates)
@@ -918,9 +915,6 @@ pub fn App() -> Html {
crate::components::event_form::RecurrenceType::Monthly |
crate::components::event_form::RecurrenceType::Yearly);
web_sys::console::log_1(&format!("🐛 FRONTEND DEBUG: is_recurring={}, edit_scope={:?}, original_uid={:?}",
is_recurring, event_data_for_update.edit_scope, event_data_for_update.original_uid).into());
let update_result = if is_recurring && event_data_for_update.edit_scope.is_some() {
// Only use series endpoint for existing recurring events being edited
// Singleton→series conversion should use regular update_event endpoint

View File

@@ -53,12 +53,6 @@ impl AlarmScheduler {
fn load_alarms_from_storage(&mut self) {
if let Ok(alarms) = LocalStorage::get::<HashMap<String, ScheduledAlarm>>(ALARMS_STORAGE_KEY) {
self.scheduled_alarms = alarms;
web_sys::console::log_1(
&format!("🔔 DEBUG: [{}] Loaded {} alarms from localStorage",
self.instance_id,
self.scheduled_alarms.len()
).into()
);
}
}
@@ -68,47 +62,17 @@ impl AlarmScheduler {
web_sys::console::error_1(
&format!("Failed to save alarms to localStorage: {:?}", e).into()
);
} else {
web_sys::console::log_1(
&format!("🔔 DEBUG: [{}] Saved {} alarms to localStorage",
self.instance_id,
self.scheduled_alarms.len()
).into()
);
}
}
/// Schedule alarms for an event
pub fn schedule_event_alarms(&mut self, event: &VEvent) {
web_sys::console::log_1(
&format!("🔔 DEBUG: [{}] schedule_event_alarms called for event '{}' with {} alarms",
self.instance_id,
event.summary.as_ref().unwrap_or(&"Unknown".to_string()),
event.alarms.len()
).into()
);
// Check notification permission before scheduling
let permission = NotificationManager::get_permission();
if permission != web_sys::NotificationPermission::Granted && !event.alarms.is_empty() {
web_sys::console::warn_1(
&format!("⚠️ Scheduling alarms but notification permission is {:?}. Will request permission.", permission).into()
);
// Try to force request permission asynchronously
wasm_bindgen_futures::spawn_local(async move {
match NotificationManager::force_request_permission().await {
Ok(new_permission) => {
web_sys::console::log_1(
&format!("🔔 Force requested notification permission: {:?}", new_permission).into()
);
}
Err(e) => {
web_sys::console::error_1(
&format!("❌ Failed to force request notification permission: {:?}", e).into()
);
}
}
let _ = NotificationManager::force_request_permission().await;
});
}
@@ -129,36 +93,12 @@ impl AlarmScheduler {
&event_location,
event_start,
) {
web_sys::console::log_1(
&format!("🔔 DEBUG: [{}] Adding alarm to scheduler: {}", self.instance_id, scheduled_alarm.id).into()
);
self.scheduled_alarms.insert(scheduled_alarm.id.clone(), scheduled_alarm);
web_sys::console::log_1(
&format!("🔔 DEBUG: [{}] Scheduler now has {} total alarms", self.instance_id, self.scheduled_alarms.len()).into()
);
}
}
web_sys::console::log_1(
&format!("Scheduled {} alarms for event: {}", event.alarms.len(), event_summary).into()
);
// Save to localStorage
self.save_alarms_to_storage();
// Debug: Log scheduled alarm details
for alarm in &event.alarms {
if let Some(scheduled_alarm) = self.create_scheduled_alarm(event, alarm, &event_summary, &event_location, event_start) {
web_sys::console::log_1(
&format!("🔔 DEBUG: Scheduled alarm ID {} for event '{}' to trigger at {} (event starts at {})",
scheduled_alarm.id,
scheduled_alarm.event_summary,
scheduled_alarm.trigger_time.format("%Y-%m-%d %H:%M:%S"),
scheduled_alarm.event_start.format("%Y-%m-%d %H:%M:%S")
).into()
);
}
}
}
/// Create a scheduled alarm from a VAlarm
@@ -246,8 +186,6 @@ impl AlarmScheduler {
// Also close any active notifications for this event
self.notification_manager.close_notification(event_uid);
web_sys::console::log_1(&format!("Removed alarms for event: {}", event_uid).into());
// Save to localStorage
self.save_alarms_to_storage();
}
@@ -260,61 +198,24 @@ impl AlarmScheduler {
let now = Local::now().naive_local();
let mut triggered_count = 0;
web_sys::console::log_1(
&format!("🕐 DEBUG: [{}] Checking alarms at {} - total {} alarms, {} pending",
self.instance_id,
now.format("%Y-%m-%d %H:%M:%S"),
self.scheduled_alarms.len(),
self.scheduled_alarms.values().filter(|a| a.status == AlarmStatus::Pending).count()
).into()
);
// Find alarms that should trigger (within 30 seconds tolerance)
let alarms_to_trigger: Vec<ScheduledAlarm> = self.scheduled_alarms
.values()
.filter(|alarm| {
let should_trigger = alarm.status == AlarmStatus::Pending &&
alarm.status == AlarmStatus::Pending &&
alarm.trigger_time <= now + Duration::seconds(30) &&
alarm.trigger_time >= now - Duration::seconds(30);
if alarm.status == AlarmStatus::Pending {
web_sys::console::log_1(
&format!("🔍 DEBUG: Pending alarm '{}' trigger: {} vs now: {} - should trigger: {}",
alarm.event_summary,
alarm.trigger_time.format("%Y-%m-%d %H:%M:%S"),
now.format("%Y-%m-%d %H:%M:%S"),
should_trigger
).into()
);
}
should_trigger
alarm.trigger_time >= now - Duration::seconds(30)
})
.cloned()
.collect();
web_sys::console::log_1(
&format!("🔔 DEBUG: Found {} alarms to trigger", alarms_to_trigger.len()).into()
);
for alarm in alarms_to_trigger {
web_sys::console::log_1(
&format!("⏰ DEBUG: Attempting to trigger alarm for '{}'", alarm.event_summary).into()
);
if self.trigger_alarm(&alarm) {
// Mark alarm as triggered
if let Some(scheduled_alarm) = self.scheduled_alarms.get_mut(&alarm.id) {
scheduled_alarm.status = AlarmStatus::Triggered;
}
triggered_count += 1;
web_sys::console::log_1(
&format!("✅ DEBUG: Successfully triggered alarm for '{}'", alarm.event_summary).into()
);
} else {
web_sys::console::log_1(
&format!("❌ DEBUG: Failed to trigger alarm for '{}'", alarm.event_summary).into()
);
}
}
@@ -331,21 +232,8 @@ impl AlarmScheduler {
/// Trigger a specific alarm
fn trigger_alarm(&mut self, alarm: &ScheduledAlarm) -> bool {
web_sys::console::log_1(
&format!("🔔 DEBUG: trigger_alarm called for '{}'", alarm.event_summary).into()
);
// Check notification permission
let permission = NotificationManager::get_permission();
web_sys::console::log_1(
&format!("🔔 DEBUG: Notification permission: {:?}", permission).into()
);
// Don't trigger if already showing notification for this event
if self.notification_manager.has_notification(&alarm.event_uid) {
web_sys::console::log_1(
&format!("🔔 DEBUG: Skipping alarm for '{}' - notification already showing", alarm.event_summary).into()
);
return false;
}
@@ -356,20 +244,11 @@ impl AlarmScheduler {
alarm_time: alarm.event_start,
};
web_sys::console::log_1(
&format!("🔔 DEBUG: About to call show_alarm_notification for '{}'", alarm.event_summary).into()
);
match self.notification_manager.show_alarm_notification(alarm_notification) {
Ok(()) => {
web_sys::console::log_1(
&format!("✅ Triggered alarm for: {}", alarm.event_summary).into()
);
true
}
Ok(()) => true,
Err(err) => {
web_sys::console::error_1(
&format!("Failed to trigger alarm: {:?}", err).into()
&format!("Failed to trigger alarm: {:?}", err).into()
);
false
}

View File

@@ -30,21 +30,14 @@ impl NotificationManager {
if let Some(window) = window() {
let has_notification = js_sys::Reflect::has(&window, &"Notification".into()).unwrap_or(false);
// Additional debugging - try to access Notification directly via JsValue
// Additional check - try to access Notification directly via JsValue
let window_js: &wasm_bindgen::JsValue = window.as_ref();
let direct_check = js_sys::Reflect::get(window_js, &"Notification".into()).unwrap_or(wasm_bindgen::JsValue::UNDEFINED);
let has_direct = !direct_check.is_undefined();
web_sys::console::log_1(
&format!("🔔 DEBUG: Notification API checks - Reflect.has: {}, direct access: {}",
has_notification, has_direct).into()
);
// Use either check
let result = has_notification || has_direct;
result
has_notification || has_direct
} else {
web_sys::console::log_1(&"🔔 DEBUG: No window object available".into());
false
}
}
@@ -60,109 +53,63 @@ impl NotificationManager {
/// Force request notification permission (even if previously denied)
pub async fn force_request_permission() -> Result<NotificationPermission, JsValue> {
web_sys::console::log_1(&"🔔 DEBUG: force_request_permission called".into());
if !Self::is_supported() {
web_sys::console::log_1(&"🔔 DEBUG: Notifications not supported".into());
return Ok(NotificationPermission::Denied);
}
// Always request permission, regardless of current status
web_sys::console::log_1(&"🔔 DEBUG: Force calling Notification::request_permission()".into());
let promise = Notification::request_permission()?;
let js_value = JsFuture::from(promise).await?;
web_sys::console::log_1(
&format!("🔔 DEBUG: Force permission request completed with result: {:?}", js_value).into()
);
// Convert JS string back to NotificationPermission
if let Some(permission_str) = js_value.as_string() {
let result = match permission_str.as_str() {
match permission_str.as_str() {
"granted" => Ok(NotificationPermission::Granted),
"denied" => Ok(NotificationPermission::Denied),
_ => Ok(NotificationPermission::Default),
};
web_sys::console::log_1(
&format!("🔔 DEBUG: Force returning permission: {:?}", result).into()
);
result
}
} else {
web_sys::console::log_1(&"🔔 DEBUG: Force permission result was not a string, returning Denied".into());
Ok(NotificationPermission::Denied)
}
}
/// Request notification permission from the user
pub async fn request_permission() -> Result<NotificationPermission, JsValue> {
web_sys::console::log_1(&"🔔 DEBUG: request_permission called".into());
if !Self::is_supported() {
web_sys::console::log_1(&"🔔 DEBUG: Notifications not supported".into());
return Ok(NotificationPermission::Denied);
}
// Check current permission status
let current_permission = Notification::permission();
web_sys::console::log_1(
&format!("🔔 DEBUG: Current permission status: {:?}", current_permission).into()
);
if current_permission != NotificationPermission::Default {
web_sys::console::log_1(
&format!("🔔 DEBUG: Permission already set to {:?}, not requesting again", current_permission).into()
);
return Ok(current_permission);
}
// Request permission
web_sys::console::log_1(&"🔔 DEBUG: Calling Notification::request_permission()".into());
let promise = Notification::request_permission()?;
let js_value = JsFuture::from(promise).await?;
web_sys::console::log_1(
&format!("🔔 DEBUG: Permission request completed with result: {:?}", js_value).into()
);
// Convert JS string back to NotificationPermission
if let Some(permission_str) = js_value.as_string() {
let result = match permission_str.as_str() {
match permission_str.as_str() {
"granted" => Ok(NotificationPermission::Granted),
"denied" => Ok(NotificationPermission::Denied),
_ => Ok(NotificationPermission::Default),
};
web_sys::console::log_1(
&format!("🔔 DEBUG: Returning permission: {:?}", result).into()
);
result
}
} else {
web_sys::console::log_1(&"🔔 DEBUG: Permission result was not a string, returning Denied".into());
Ok(NotificationPermission::Denied)
}
}
/// Display a notification for an alarm
pub fn show_alarm_notification(&mut self, alarm: AlarmNotification) -> Result<(), JsValue> {
web_sys::console::log_1(
&format!("🔔 DEBUG: show_alarm_notification called for '{}'", alarm.event_summary).into()
);
// Check permission
let permission = Self::get_permission();
web_sys::console::log_1(
&format!("🔔 DEBUG: Permission check: {:?}", permission).into()
);
if permission != NotificationPermission::Granted {
web_sys::console::warn_1(&"❌ Notification permission not granted".into());
if Self::get_permission() != NotificationPermission::Granted {
return Ok(()); // Don't error, just skip
}
// Check if notification already exists for this event
if self.active_notifications.contains_key(&alarm.event_uid) {
web_sys::console::log_1(
&format!("🔔 DEBUG: Skipping - notification already exists for event: {}", alarm.event_uid).into()
);
return Ok(()); // Already showing notification for this event
}
@@ -190,14 +137,8 @@ impl NotificationManager {
options.set_require_interaction(true);
// Create and show notification
web_sys::console::log_1(
&format!("🔔 DEBUG: Creating notification with title: '{}' and body: '{}'", alarm.event_summary, body).into()
);
let notification = Notification::new_with_options(&alarm.event_summary, &options)?;
web_sys::console::log_1(&"🔔 DEBUG: Notification created successfully".into());
// Store reference to track active notifications
self.active_notifications.insert(alarm.event_uid.clone(), notification.clone());
@@ -209,7 +150,6 @@ impl NotificationManager {
let _ = window.focus();
}
web_sys::console::log_1(&format!("Notification clicked for event: {}", event_uid).into());
}) as Box<dyn FnMut(_)>);
notification.set_onclick(Some(onclick_closure.as_ref().unchecked_ref()));
@@ -225,8 +165,6 @@ impl NotificationManager {
notification.set_onclose(Some(onclose_closure.as_ref().unchecked_ref()));
onclose_closure.forget(); // Keep closure alive
web_sys::console::log_1(&format!("Displayed notification for: {}", alarm.event_summary).into());
Ok(())
}