Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF demo does not show a dark title bar, fails on CI but not locally #3

Closed
Aldaviva opened this issue Oct 5, 2022 · 3 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Aldaviva
Copy link
Owner

Aldaviva commented Oct 5, 2022

Affects version 2.0.0. Not sure why it's different, since it's the same SDK (.NET 6), similar OS (Windows 10 vs Server 2022), and codebase. The build command should be the same (dotnet publish). The Windows Forms demo is not affected.

Working and non-working artifacts

@Aldaviva
Copy link
Owner Author

Aldaviva commented Oct 5, 2022

This seems to be a difference between the packed binaries generated by MSBuild (local, working) and dotnet (not working).

A workaround is to explicitly call

DarkNet.Instance.SetWindowThemeWpf(this, Theme.Auto);

before any windows are shown.

I don't know if there are any additional arguments that can be passed to dotnet pack to make it work more like MSBuild.

@Aldaviva
Copy link
Owner Author

Aldaviva commented Oct 5, 2022

This was caused by a logical error in the implicit SetCurrentProcessTheme behavior introduced in 2.0.0. When invoked implicitly, it was never calling SetPreferredAppMode or AllowDarkModeForApp, even when it was being called for the first time and should have called at least one of those Win32 API methods. The root cause was marking this first-time call as having been finished too early, then checking it again before actually running it for the first time, and erroneously skipping it because it was marked as having already run, even though it hadn't.

I am not sure why the published app generated by Visual Studio and MSBuild did not reproduce this error, as the code flow was the same as the binary generated by dotnet publish.

In any case, fixing the first-run check makes it work for both compilers.

@Aldaviva
Copy link
Owner Author

Aldaviva commented Oct 5, 2022

@Aldaviva Aldaviva closed this as completed Oct 5, 2022
@Aldaviva Aldaviva self-assigned this Oct 5, 2022
@Aldaviva Aldaviva added the bug Something isn't working label Oct 5, 2022
@Aldaviva Aldaviva added this to the 2.0.1 milestone Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant