Refactor: Prevent nchan updates on browsers not in focus#2081
Conversation
WalkthroughThis update enhances several components in the Dynamix plugin. The dashboard-related objects now invoke a monitoring method after starting, and a window blur event resets key data arrays. A server post call has been disabled. Additionally, copyright years were updated, and a new form dropdown was introduced to control real-time updates on inactive browsers. A corresponding configuration entry was added to disable live updates by default. Finally, the DefaultPageLayout now handles Nchan subscribers with a new monitor method and improved focus/blur events for managing live updates. Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (18)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
emhttp/plugins/dynamix/include/DefaultPageLayout.php (1)
1239-1270: Added window focus/blur event handlers to manage live updatesNew event handlers have been implemented to stop Nchan subscribers when the window loses focus and restart them when focus is regained. This prevents unnecessary updates and potential server load for inactive browser tabs.
There's a minor issue in the error handling syntax.
On line 1259, the
catchblock should include the error parameter ascatch(e)instead of justcatch:- } catch { + } catch(e) { newsub.splice(newsub.indexOf(e,1)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
emhttp/plugins/dynamix/DashStats.page(2 hunks)emhttp/plugins/dynamix/DisplaySettings.page(2 hunks)emhttp/plugins/dynamix/default.cfg(1 hunks)emhttp/plugins/dynamix/include/DefaultPageLayout.php(3 hunks)
🔇 Additional comments (11)
emhttp/plugins/dynamix/default.cfg (1)
38-38: Added configuration option for live update controlA new configuration entry
liveUpdate="no"has been added to the[display]section, which disables real-time updates for browsers not in focus by default. This aligns with the changes in the DisplaySettings page.emhttp/plugins/dynamix/DisplaySettings.page (2)
7-8: Updated copyright years to 2025The copyright years have been updated from 2023 to 2025 for both Lime Technology and Bergware International.
326-330: Added UI control for real-time updates on inactive browsersA new dropdown has been added to control whether real-time updates should occur when the browser is not in focus. This corresponds to the
liveUpdateoption added in the default.cfg file.emhttp/plugins/dynamix/include/DefaultPageLayout.php (3)
108-108: Added newmonitormethod to track Nchan subscribersThis method pushes the current Nchan subscriber instance to a global array for centralized management.
114-114: Added global array to store Nchan subscribersA new global array
subscribershas been created to keep track of all Nchan subscribers, allowing them to be controlled centrally when the window loses or gains focus.
726-726: Modified page reload to respect focus stateThe page reload mechanism now checks the
nchanPausedflag before reloading, preventing unnecessary reloads when the browser tab is not in focus.emhttp/plugins/dynamix/DashStats.page (5)
1798-1798: Added monitoring capability to dashboardThe
.monitor()method call adds the ability to track browser focus state to the dashboard object, which aligns with the PR objective of preventing nchan updates on inactive browsers.
1800-1800: Added monitoring capability to VM dashboard usageSimilar to the dashboard object, the VM dashboard usage object now has monitoring capabilities to detect when the browser is not in focus.
1803-1803: Added monitoring capability to APC UPS objectThe UPS monitoring object is now also equipped with focus tracking capability through the
.monitor()method.
1821-1821: Removed unnecessary data posting on window unloadThe code previously posted chart data to the server when the window was unloaded. This has been commented out, likely to reduce unnecessary server interactions for inactive browsers.
1826-1832: Reset graph data when window loses focusThis new code block implements the core functionality of the PR by clearing graph data arrays when the browser tab loses focus, but only if the user has disabled live updates in their settings. This prevents unnecessary resource consumption and aligns perfectly with the PR objective.
Summary by CodeRabbit