Skip to content

Fix icon theme not updating on reload after Dark/Light mode switch - #3493

Open
jmcouffin with Copilot wants to merge 4 commits into
developfrom
copilot/propose-alternative-icon-caching
Open

Fix icon theme not updating on reload after Dark/Light mode switch#3493
jmcouffin with Copilot wants to merge 4 commits into
developfrom
copilot/propose-alternative-icon-caching

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

RevitThemeDetector stores the detected Revit UI theme in static fields, 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:

// SessionManagerService.LoadSession()
_extensionManager?.ClearParserCaches();
RevitThemeDetector.ClearCache();   // ← added

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.

@devloai

devloai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

Copilot AI changed the title Fix stale icon theme cache: reload now picks up Dark/Light mode switch Fix icon theme not updating on reload after Dark/Light mode switch Jul 20, 2026
Copilot AI requested a review from jmcouffin July 20, 2026 18:05
@jmcouffin

Copy link
Copy Markdown
Contributor

Fixes #3361

@jmcouffin
jmcouffin marked this pull request as ready for review July 20, 2026 20:07
@jmcouffin

Copy link
Copy Markdown
Contributor

@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?

@Wurschdhaud

Copy link
Copy Markdown
Contributor

Copilot claims there is no overhead, so why not? 😄
But the bug report claims he did restart anyway, so this shouldn't be the root cause. I don't have 2027 installed to verify.

@romangolev

Copy link
Copy Markdown
Member

@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.

private void OnThemeChanged(object sender, ThemeChangedEventArgs e)
{
    if (e.ThemeChangedType == ThemeType.UITheme)
    {
        // Ribbon/UI theme changed
    }
}

@jmcouffin fancy implementing this one? or I could take this over if you don't mind

@jmcouffin

Copy link
Copy Markdown
Contributor

Please, go ahead!
@romangolev

@romangolev romangolev self-assigned this Aug 3, 2026
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.
@romangolev

Copy link
Copy Markdown
Member

@jmcouffin much better now 😄 tested locally with Revit 2027

@jmcouffin
jmcouffin requested a lite review from Copilot August 5, 2026 05:21
@jmcouffin

Copy link
Copy Markdown
Contributor

Inception time: asked copilot review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 each SessionManagerService.LoadSession() so theme is re-detected on reload.
  • Add a RevitThemeChangeMonitor that listens for Revit theme changes and prompts the user to reload pyRevit, then triggers reload on the next Idling.
  • 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.

Comment thread dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs
@Wurschdhaud

Copy link
Copy Markdown
Contributor

Did you test against older versions that didn't have themes?

@romangolev

Copy link
Copy Markdown
Member

Did you test against older versions that didn't have themes?

I've just gave it a spin with Revit 2022, no issues detected

romangolev
romangolev previously approved these changes Aug 7, 2026
sanzoghenzo
sanzoghenzo previously approved these changes Aug 11, 2026

@sanzoghenzo sanzoghenzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@romangolev
romangolev dismissed stale reviews from sanzoghenzo and themself via 34699f6 August 11, 2026 08:37
@romangolev

Copy link
Copy Markdown
Member

@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 👀

@romangolev
romangolev requested a review from sanzoghenzo August 11, 2026 08:40
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.

6 participants