Fix icon theme not updating on reload after Dark/Light mode switch#3493
Conversation
|
Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔 |
|
Fixes #3361 |
|
@romangolev @Wurschdhaud @tay0thman what are you thoughts on this? Shall we leave it as is and document it in the reload button tooltip or adjust the behavior following this PR? |
|
Copilot claims there is no overhead, so why not? 😄 |
|
@jmcouffin to fully cover the issue #3361 we need to implement the event listener that would identify the theme switch and adjust the UI accordingly. With current copilot implementation user is going to be stuck in the same situation without being able to see the difference after he or she changes the theme. The proper implementation should include the event listener like this and also should prompt user to restar pyRevit to properly propagate changes. @jmcouffin fancy implementing this one? or I could take this over if you don't mind |
|
Please, go ahead! |
Subscribe to the Revit UI ThemeChanged event from PyRevitLoader and, on a real theme transition, prompt the user to reload pyRevit so ribbon icons are re-selected against the new theme without restarting Revit. Alternative to the previous reload-time theme cache clear.
|
@jmcouffin much better now 😄 tested locally with Revit 2027 |
|
Inception time: asked copilot review |
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure pyRevit picks up Revit Dark/Light theme changes without requiring a full Revit restart, primarily so ribbon icons update correctly after a mid-session theme switch.
Changes:
- Clear
RevitThemeDetector’s static cache at the beginning of eachSessionManagerService.LoadSession()so theme is re-detected on reload. - Add a
RevitThemeChangeMonitorthat listens for Revit theme changes and prompts the user to reload pyRevit, then triggers reload on the nextIdling. - Add unit tests covering theme-change detection, de-duping, readiness deferral, and disposal behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs | Wires in theme-change monitoring and schedules a reload via Idling after user confirmation. |
| dev/pyRevitLoader/pyRevitAssemblyBuilder/UIManager/SessionManagerService.cs | Clears the theme detector cache at the start of each session load/reload. |
| dev/pyRevitLoader/pyRevitAssemblyBuilder/SessionManager/RevitThemeChangeMonitor.cs | Introduces a monitor + reflection-based theme source to detect theme transitions and request UI refresh. |
| dev/pyRevitLoader/pyRevitExtensionParserTester/RevitThemeChangeMonitorTests.cs | Adds coverage for monitor behavior (transition, duplicates, startup deferral, disposal, idempotent start, reflection forwarding). |
| dev/pyRevitLoader/pyRevitExtensionParserTester/pyRevitExtensionParserTest.csproj | Includes the new test file in the test project build. |
| dev/pyRevitLoader/pyRevitAssemblyBuilder/pyRevitAssemblyBuilder.csproj | Broadens the .NET Core reference condition to TargetFrameworkIdentifier == .NETCoreApp. |
|
Did you test against older versions that didn't have themes? |
I've just gave it a spin with Revit 2022, no issues detected |
sanzoghenzo
left a comment
There was a problem hiding this comment.
Changes look good, but I'm wondering if this should be done automatically instead of asking the user to restart or not.
I don't believe this is a frequent enough operation to justify more work on it, though!
Replaces the TaskDialog prompt and full session reload with a static registry that re-runs each control's theme-aware icon updater when Revit reports a theme change. Clears the registry at session start so stale entries from a previous session do not leak through, and adds unit tests covering replace-on-register, fault isolation, and the no-reload refresh path.
|
@sanzoghenzo yeah, that's going to be so much better UI I've made changes for the Icons to update automatically. Please, take a look again 👀 |
RevitThemeDetectorstores the detected Revit UI theme instaticfields, so after switching themes mid-session the stale value persists for the process lifetime — a full Revit restart was required to see correct icons.Change
Clear the theme cache at the start of each
LoadSession()so the active theme is re-queried on every reload:The cache is repopulated on the first
IsDarkTheme()call within that same load, so there is no performance regression. After this change, a pyRevit reload is sufficient to pick up a Dark ↔ Light mode switch.