Live-events feature for custom-api widgets and monitoring services#955
Open
frozendark01 wants to merge 23 commits intoglanceapp:devfrom
Open
Live-events feature for custom-api widgets and monitoring services#955frozendark01 wants to merge 23 commits intoglanceapp:devfrom
frozendark01 wants to merge 23 commits intoglanceapp:devfrom
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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