diff --git a/docs/FEATURES.md b/docs/FEATURES.md index aca49ed9..6eeb3520 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -6,7 +6,7 @@ NetAlertX is a lightweight, flexible platform for monitoring networks, tracking ## Network Discovery & Device Tracking -[Network Discovery & Device Tracking](./img/FEATURES/Network_Discovery_Device_Tracking.png) +![Network Discovery & Device Tracking](./img/FEATURES/Network_Discovery_Device_Tracking.png) - **Automatic Device Detection**: Continuously scans your local network to detect all connected devices via ARP, DHCP, SNMP, and compatible controllers. - **Presence Monitoring**: Track when devices appear, disappear, or reconnect on the network. diff --git a/front/js/sse_manager.js b/front/js/sse_manager.js index 3afda1c6..2c53d31d 100644 --- a/front/js/sse_manager.js +++ b/front/js/sse_manager.js @@ -23,10 +23,19 @@ class NetAlertXStateManager { */ init() { if (this.initialized) return; + // waiting until cache ready + const waitForInit = () => { + if (!isAppInitialized()) { + setTimeout(waitForInit, 300); + return; + } - console.log("[NetAlertX State] Initializing state manager..."); - this.trySSE(); - this.initialized = true; + console.log("[NetAlertX State] App initialized, starting state manager"); + this.trySSE(); + this.initialized = true; + }; + + waitForInit(); } /** diff --git a/server/api_server/api_server_start.py b/server/api_server/api_server_start.py index de68c90d..1dc7e436 100755 --- a/server/api_server/api_server_start.py +++ b/server/api_server/api_server_start.py @@ -1401,7 +1401,7 @@ def api_create_event(mac, payload=None): def api_events_by_mac(mac, payload=None): """Delete events for a specific device MAC; string converter keeps this distinct from /events/.""" device_handler = DeviceInstance() - + result = device_handler.deleteDeviceEvents(mac) return jsonify(result) @@ -1740,7 +1740,8 @@ def api_write_notification(payload=None): auth_callable=is_authorized ) def api_get_unread_notifications(payload=None): - return get_unread_notifications() + notifications = get_unread_notifications() + return jsonify(notifications) @app.route("/messaging/in-app/read/all", methods=["POST"]) diff --git a/server/messaging/in_app.py b/server/messaging/in_app.py index ca90962a..ae35c1bd 100755 --- a/server/messaging/in_app.py +++ b/server/messaging/in_app.py @@ -231,7 +231,7 @@ def get_unread_notifications(): notifications = json.load(f) unread = [n for n in notifications if n.get("read", 0) == 0] - return jsonify(unread) + return unread def mark_notification_as_read(guid=None, max_attempts=3): @@ -283,6 +283,13 @@ def mark_notification_as_read(guid=None, max_attempts=3): return {"success": False, "error": error_msg} +def update_unread_notifications_count(): + """ + Re-broadcast unread notifications for the frontend . + """ + broadcast_unread_notifications_count(len(get_unread_notifications())) + + def delete_notification(guid): """ Delete a notification from the notifications file based on its GUID. diff --git a/server/scan/session_events.py b/server/scan/session_events.py index 049ed591..3f9f1022 100755 --- a/server/scan/session_events.py +++ b/server/scan/session_events.py @@ -17,6 +17,7 @@ from db.db_helper import print_table_schema from utils.datetime_utils import timeNowDB from logger import mylog, Logger from messaging.reporting import skip_repeated_notifications +from messaging.in_app import update_unread_notifications_count # Make sure log level is initialized correctly @@ -104,6 +105,9 @@ def process_scan(db): # 🐛 CurrentScan DEBUG: comment out below when debugging to keep the CurrentScan table after restarts/scan finishes db.sql.execute("DELETE FROM CurrentScan") + # re-broadcast unread notifiation count to update FE + update_unread_notifications_count() + # Commit changes db.commitDB()