chore: remove debug logging from browser notifications
- Cleaned up verbose notification logs - Kept error logging for troubleshooting - Notifications confirmed working on Chrome/macOS
This commit is contained in:
@@ -213,13 +213,10 @@ pub fn provide_torrent_store() {
|
|||||||
global_stats.set(stats);
|
global_stats.set(stats);
|
||||||
}
|
}
|
||||||
AppEvent::Notification(n) => {
|
AppEvent::Notification(n) => {
|
||||||
log::info!("📬 Received notification: {} - {}", n.level == shared::NotificationLevel::Success, n.message);
|
|
||||||
|
|
||||||
// Show toast notification
|
// Show toast notification
|
||||||
show_toast_with_signal(notifications, n.level.clone(), n.message.clone());
|
show_toast_with_signal(notifications, n.level.clone(), n.message.clone());
|
||||||
|
|
||||||
// Show browser notification for critical events
|
// Show browser notification for critical events
|
||||||
// (torrent completed, connection lost/restored, errors)
|
|
||||||
let is_critical = n.message.contains("tamamlandı")
|
let is_critical = n.message.contains("tamamlandı")
|
||||||
|| n.message.contains("Reconnected")
|
|| n.message.contains("Reconnected")
|
||||||
|| n.message.contains("yeniden kuruldu")
|
|| n.message.contains("yeniden kuruldu")
|
||||||
@@ -227,7 +224,6 @@ pub fn provide_torrent_store() {
|
|||||||
|| n.level == shared::NotificationLevel::Error;
|
|| n.level == shared::NotificationLevel::Error;
|
||||||
|
|
||||||
if is_critical {
|
if is_critical {
|
||||||
log::info!("🔴 Critical notification detected: {}", n.message);
|
|
||||||
let title = match n.level {
|
let title = match n.level {
|
||||||
shared::NotificationLevel::Success => "✅ VibeTorrent",
|
shared::NotificationLevel::Success => "✅ VibeTorrent",
|
||||||
shared::NotificationLevel::Error => "❌ VibeTorrent",
|
shared::NotificationLevel::Error => "❌ VibeTorrent",
|
||||||
|
|||||||
@@ -34,9 +34,7 @@ pub async fn request_notification_permission() -> bool {
|
|||||||
/// Check if browser notifications are supported and permitted
|
/// Check if browser notifications are supported and permitted
|
||||||
pub fn is_notification_supported() -> bool {
|
pub fn is_notification_supported() -> bool {
|
||||||
let window = web_sys::window().expect("no global window");
|
let window = web_sys::window().expect("no global window");
|
||||||
let supported = js_sys::Reflect::has(&window, &JsValue::from_str("Notification")).unwrap_or(false);
|
js_sys::Reflect::has(&window, &JsValue::from_str("Notification")).unwrap_or(false)
|
||||||
log::debug!("📢 Notification API supported: {}", supported);
|
|
||||||
supported
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current notification permission status
|
/// Get current notification permission status
|
||||||
@@ -60,15 +58,11 @@ pub fn get_notification_permission() -> String {
|
|||||||
pub fn show_browser_notification(title: &str, body: &str, icon: Option<&str>) -> bool {
|
pub fn show_browser_notification(title: &str, body: &str, icon: Option<&str>) -> bool {
|
||||||
// Check permission first
|
// Check permission first
|
||||||
let permission = get_notification_permission();
|
let permission = get_notification_permission();
|
||||||
log::info!("📢 Notification permission: {}", permission);
|
|
||||||
|
|
||||||
if permission != "granted" {
|
if permission != "granted" {
|
||||||
log::warn!("❌ Notification permission not granted: {}", permission);
|
log::warn!("Notification permission not granted: {}", permission);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("✅ Permission granted, creating notification: {}", title);
|
|
||||||
|
|
||||||
// Create notification options
|
// Create notification options
|
||||||
let opts = NotificationOptions::new();
|
let opts = NotificationOptions::new();
|
||||||
opts.set_body(body);
|
opts.set_body(body);
|
||||||
@@ -78,17 +72,13 @@ pub fn show_browser_notification(title: &str, body: &str, icon: Option<&str>) ->
|
|||||||
opts.set_require_interaction(false);
|
opts.set_require_interaction(false);
|
||||||
opts.set_silent(Some(false));
|
opts.set_silent(Some(false));
|
||||||
|
|
||||||
log::info!("🔧 Notification options created");
|
|
||||||
|
|
||||||
// Create and show notification
|
// Create and show notification
|
||||||
match Notification::new_with_options(title, &opts) {
|
match Notification::new_with_options(title, &opts) {
|
||||||
Ok(_notification) => {
|
Ok(_notification) => {
|
||||||
log::info!("🔔 Browser notification shown: {}", title);
|
|
||||||
// Note: Tarayıcı 5 saniye sonra otomatik kapatıyor, close() çağrısı gerekmiyor
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("❌ Failed to create notification: {:?}", e);
|
log::error!("Failed to create notification: {:?}", e);
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,8 +86,6 @@ pub fn show_browser_notification(title: &str, body: &str, icon: Option<&str>) ->
|
|||||||
|
|
||||||
/// Show notification only if enabled in settings and permission granted
|
/// Show notification only if enabled in settings and permission granted
|
||||||
pub fn show_notification_if_enabled(title: &str, body: &str) -> bool {
|
pub fn show_notification_if_enabled(title: &str, body: &str) -> bool {
|
||||||
log::info!("📬 Checking if notification should be shown: {}", title);
|
|
||||||
|
|
||||||
// Check localStorage for user preference
|
// Check localStorage for user preference
|
||||||
let window = web_sys::window().expect("no global window");
|
let window = web_sys::window().expect("no global window");
|
||||||
let storage = window.local_storage().ok().flatten();
|
let storage = window.local_storage().ok().flatten();
|
||||||
@@ -109,17 +97,9 @@ pub fn show_notification_if_enabled(title: &str, body: &str) -> bool {
|
|||||||
.flatten()
|
.flatten()
|
||||||
.unwrap_or("true".to_string());
|
.unwrap_or("true".to_string());
|
||||||
|
|
||||||
log::info!("💾 Browser notification enabled in settings: {}", enabled);
|
|
||||||
|
|
||||||
if enabled == "true" {
|
if enabled == "true" {
|
||||||
let result = show_browser_notification(title, body, None);
|
return show_browser_notification(title, body, None);
|
||||||
log::info!("📬 Notification result: {}", if result { "✅ shown" } else { "❌ failed" });
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
log::info!("📭 Browser notifications disabled in settings");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log::warn!("⚠️ localStorage not available");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
|
|||||||
Reference in New Issue
Block a user