Skip to content

Live-events feature for custom-api widgets and monitoring services#955

Open
frozendark01 wants to merge 23 commits intoglanceapp:devfrom
frozendark01:main
Open

Live-events feature for custom-api widgets and monitoring services#955
frozendark01 wants to merge 23 commits intoglanceapp:devfrom
frozendark01:main

Conversation

@frozendark01
Copy link

What was implemented:
Server-side background polling (glance.go):

Added recursive polling that dives into container widgets (groups, split-columns)
Polls monitor and custom-api widgets every 15 seconds
Detects content changes and emits events
Custom-api widget change detection (widget-custom-api.go):

Added PrevCompiledHTML field to track previous content
Compares rendered HTML to detect changes
Emits custom-api:data_changed event when changes detected
Event hub with caching (events.go):

Server-Sent Events broadcast to connected clients
Event caching: Stores recent events for reconnecting clients
Debouncing per widget to prevent event spam
Robust numeric type handling for widget IDs
Browser-side DOM updates (page.js):

Listens for custom-api:data_changed events
Fetches updated widget HTML via /api/widgets/{id}/content/
Replaces widget DOM with new content
Re-initializes all widget setup functions
Widget registration fix:

Widgets inside containers are now registered in widgetByID map
Allows endpoint to fetch child widgets by ID

svilenmarkov and others added 22 commits December 10, 2025 09:44
…ntation

- Complete architecture overview with diagrams
- Detailed server-side components (event hub, background worker, status detection)
- Client-side implementation with SSE setup
- Guard mechanisms to prevent duplicate initialization
- Event flow diagrams
- Testing procedures and troubleshooting
- Performance characteristics and known limitations
- Future enhancement suggestions

Covers all backend files (events.go, glance.go, widget-monitor.go, main.go, config.go)
and frontend changes (widget-base.html, page.js)
ci: build & push docker image
Added problem statement and solution for real-time notifications. Updated installation instructions and configuration details.
Updated volume mapping to include config folder for glance.yml.
Enable real-time updates for custom-api widgets when their data changes:

Backend:
- Add PrevCompiledHTML field to customAPIWidget for change detection
- Detect HTML content changes in update() method
- Emit 'custom-api:data_changed' events when data changes
- Add customAPIWidget to background polling loop (15s interval)
- Apply same event emission pattern as monitorWidget

Frontend:
- Add SSE handler for 'custom-api:data_changed' events
- Fetch updated widget content via /api/widgets/{id}/content/
- Re-initialize all setup functions with guard checks
- Identical handling to monitor:site_changed for consistency

Result: custom-api widgets with status=1m cache now show updates
instantly without manual page refresh (previously only on page reload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants