mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 16:59:43 +02:00
fix: browser notifications now fire correctly
Three issues fixed: - Default browserNotifications to true (was false, never fired) - Remove tab-visibility gate for critical/warning notifications (monitoring dashboard should alert regardless of tab focus) - Auto-request Notification permission on first attempt instead of silently failing (re-sends the notification after permission granted) - Migrate existing localStorage prefs from v1 default (false → true) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+29
-8
@@ -33,19 +33,30 @@ class NotificationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPreferences() {
|
loadPreferences() {
|
||||||
try {
|
const defaults = {
|
||||||
const saved = localStorage.getItem('claudeman-notification-prefs');
|
|
||||||
if (saved) return JSON.parse(saved);
|
|
||||||
} catch (_e) { /* ignore */ }
|
|
||||||
return {
|
|
||||||
enabled: true,
|
enabled: true,
|
||||||
browserNotifications: false,
|
browserNotifications: true,
|
||||||
audioAlerts: false,
|
audioAlerts: false,
|
||||||
stuckThresholdMs: 600000,
|
stuckThresholdMs: 600000,
|
||||||
muteCritical: false,
|
muteCritical: false,
|
||||||
muteWarning: false,
|
muteWarning: false,
|
||||||
muteInfo: false,
|
muteInfo: false,
|
||||||
|
_version: 2,
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
|
const saved = localStorage.getItem('claudeman-notification-prefs');
|
||||||
|
if (saved) {
|
||||||
|
const prefs = JSON.parse(saved);
|
||||||
|
// Migrate: v1 had browserNotifications defaulting to false
|
||||||
|
if (!prefs._version || prefs._version < 2) {
|
||||||
|
prefs.browserNotifications = true;
|
||||||
|
prefs._version = 2;
|
||||||
|
localStorage.setItem('claudeman-notification-prefs', JSON.stringify(prefs));
|
||||||
|
}
|
||||||
|
return { ...defaults, ...prefs };
|
||||||
|
}
|
||||||
|
} catch (_e) { /* ignore */ }
|
||||||
|
return defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
savePreferences() {
|
savePreferences() {
|
||||||
@@ -104,8 +115,8 @@ class NotificationManager {
|
|||||||
this.updateTabTitle();
|
this.updateTabTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layer 3: Browser notification (when tab hidden, critical/warning only)
|
// Layer 3: Browser notification (critical/warning always, info only when tab hidden)
|
||||||
if (!this.isTabVisible && (urgency === 'critical' || urgency === 'warning')) {
|
if (urgency === 'critical' || urgency === 'warning' || !this.isTabVisible) {
|
||||||
this.sendBrowserNotif(title, message, category, sessionId);
|
this.sendBrowserNotif(title, message, category, sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +195,16 @@ class NotificationManager {
|
|||||||
sendBrowserNotif(title, body, tag, sessionId) {
|
sendBrowserNotif(title, body, tag, sessionId) {
|
||||||
if (!this.preferences.browserNotifications) return;
|
if (!this.preferences.browserNotifications) return;
|
||||||
if (typeof Notification === 'undefined') return;
|
if (typeof Notification === 'undefined') return;
|
||||||
|
if (Notification.permission === 'default') {
|
||||||
|
// Auto-request on first notification attempt
|
||||||
|
Notification.requestPermission().then(result => {
|
||||||
|
if (result === 'granted') {
|
||||||
|
// Re-send this notification now that we have permission
|
||||||
|
this.sendBrowserNotif(title, body, tag, sessionId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Notification.permission !== 'granted') return;
|
if (Notification.permission !== 'granted') return;
|
||||||
|
|
||||||
// Rate limit: max 1 per 3 seconds
|
// Rate limit: max 1 per 3 seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user