Make CssReloadHelper watch CSS new style on appearance change#4804
Make CssReloadHelper watch CSS new style on appearance change#4804BBaoVanC wants to merge 1 commit intoAlexays:masterfrom
Conversation
858adf8 to
277bf02
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where CSS file reload monitoring doesn't update when the application appearance changes between light and dark themes. When users have reload_style_on_change enabled and switch between style-dark.css and style-light.css, the file watcher continues monitoring the old CSS file instead of switching to the new one.
Changes:
- Modified
CssReloadHelpercallback signature to pass the CSS file path as a parameter - Added
changeCssFilemethod to update the monitored CSS file - Updated appearance change handler to call
changeCssFilewhen switching themes
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| include/util/css_reload_helper.hpp | Updated callback signature to include CSS file parameter; added changeCssFile method declaration |
| src/util/css_reload_helper.cpp | Implemented changeCssFile to clear old monitors and set up new ones; updated callback invocation to pass CSS file |
| src/client.cpp | Modified callback lambda to accept CSS file parameter; added call to changeCssFile in appearance change handler |
| test/utils/css_reload_helper.cpp | Updated test callback signature to match new API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| m_fileMonitors.clear(); | ||
| m_cssFile = newCssFile; |
There was a problem hiding this comment.
There's a potential race condition in changeCssFile. If a file change event from the old monitors fires after m_fileMonitors.clear() but during or after m_cssFile = newCssFile, the handleFileChange callback will be invoked with the new CSS file path for a change in the old file. To fix this, the new CSS file path should be assigned after setting up the new monitors, or the old signal connections should be explicitly disconnected before clearing the monitors.
| m_fileMonitors.clear(); | |
| m_cssFile = newCssFile; | |
| // Cancel existing monitors to avoid receiving further events from the old CSS file. | |
| for (auto& monitor : m_fileMonitors) { | |
| if (monitor) { | |
| monitor->cancel(); | |
| } | |
| } | |
| m_fileMonitors.clear(); | |
| m_cssFile = std::move(newCssFile); |
There was a problem hiding this comment.
If I am not mistaken, clearing m_fileMonitors drops all of the old monitors since they no longer have any references.
| class CssReloadHelperTest : public waybar::CssReloadHelper { | ||
| public: | ||
| CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this]() { callback(); }) {} | ||
| CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this](const std::string&) { callback(); }) {} |
There was a problem hiding this comment.
The new changeCssFile method lacks test coverage. Since the test file already contains comprehensive tests for other methods in CssReloadHelper, tests should be added for changeCssFile to verify that it correctly updates the monitored CSS file and clears/re-establishes file monitors.
If you have reload_style_on_change enabled, and use dynamic appearance styling (style-dark.css and style-light.css), then changing the appearance doesn't update the files that are being watched for reload. Add a method to CssReloadHelper to change the CSS file being watched, and also provide the CSS file as a parameter to the callback so setupCss can be called on the right file when the file watcher triggers.
b480df5 to
86284c1
Compare
If you have reload_style_on_change enabled, and use dynamic appearance styling (style-dark.css and style-light.css), then changing the appearance doesn't update the files that are being watched for reload.
Add a method to CssReloadHelper to change the CSS file being watched, and also provide the CSS file as a parameter to the callback so setupCss can be called on the right file when the file watcher triggers.
To me this API was the most obvious way to fix it, but I'm open to other ideas.
TODO: tests?