DOCS+FE+BE: cleanup, SSE wait for app initialization #1440

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2026-02-01 10:36:31 +11:00
parent f52a7c112a
commit 4c9c89050b
5 changed files with 28 additions and 7 deletions

View File

@@ -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.

View File

@@ -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();
}
/**

View File

@@ -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/<int:days>."""
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"])

View File

@@ -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.

View File

@@ -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()