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

windows/app theme does not referesh the system after switching! #427

Open
ghost opened this issue Apr 9, 2022 · 40 comments
Open

windows/app theme does not referesh the system after switching! #427

ghost opened this issue Apr 9, 2022 · 40 comments
Labels
bug Something isn't working priority-high
Milestone

Comments

@ghost
Copy link

ghost commented Apr 9, 2022

  • WDD Version: 5.1
  • OS Version: 11 lastest

Steps to Reproduce:

1.change light to dark mode
2. pressing start menu shows whitetext on white surface+app that needs to be updated doesnot referesh unless refreshed manuallY!

Are you using the Microsoft Store version of WDD?: No

@t1m0thyj
Copy link
Owner

t1m0thyj commented Apr 9, 2022

Can you check if the same behavior happens when you manually switch between light and dark themes in Windows 11 Personalization settings? If so, this is a bug in Windows rather than WDD.

@ghost
Copy link
Author

ghost commented Apr 9, 2022

we checked this me and the other app developer, the problem is from your side(maybe the scripts or something)

@snowtyler
Copy link

For me, this issue occurs on the latest Windows 11 Beta build (22593.1) with WDD 5.1. I tick "Enable Night Mode," apps such as browsers switch to dark as expected but the system UI and the background remains light.

@ghost
Copy link
Author

ghost commented Apr 15, 2022

here is a demonstration:
your app does not refresh the system theme properly so the app looks like this:
wrongColor
after refresh(the supposed look of the app):
rightColor

maybe the problem is with the scripts instead of the main app? idk i am not that geek with software engineering! i use it for beautiful looks on my windows pc

@oreomaker
Copy link

The same problem have bothered me for some time.
I just found that when you change the SystemUsesLightTheme in the registry directly to false, the taskbar stay the same while the start menu and icons operate properly. I wonder what changes have been made when you change the color theme in the system settings.

@LinHier
Copy link

LinHier commented Aug 12, 2022

It seems like Microsoft has changed the behavior of the night mode shifting actions in recent preview versions.

@shust
Copy link

shust commented Jan 20, 2023

The problem is still relevant in the latest version of windows 22621.1105

@leostudiooo
Copy link
Contributor

My system:

Version Windows 11 Pro Workstation (Insider Preview)
Version 22H2
Installation Date ‎2023/‎1/‎22
OS Version 25281.1000
Experience Windows Feature Experience Pack 1000.25281.1000.0


I checked the registry mentioned in the script. Things come strange.

Here's how it comes:

  • If I change the color schedule manually in the Settings App, the registry value changes. Meanwhile the app windows and the taskbar changes color.
  • If I click refresh wallpaper in WDD, the registry value changes to the same value as manually triggered. Meanwhile, the app windows changes its color, but the taskbar remains the same. After a restart it will sync the registry.

I guess that the Settings App has got some other ways to communicate with the taskbar, bypassing the registry.

@gaoyang
Copy link

gaoyang commented Feb 16, 2023

Looking for a solution.

@bigplayer-ai
Copy link

bigplayer-ai commented Feb 19, 2023

I have the same issue.
I think the font color and other system parameters must be called after changing the registry.
Furthermore, I think this is more related to WDD scripts than WDD itself. This issue is more about the System Theme switch/Application Theme switch.
Check my mouse script, How I called system parameters to update the new mouse value.

$CSharpSig = @’
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(
             uint uiAction,
             uint uiParam,
             uint pvParam,
             uint fWinIni);
‘@
$CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo –PassThru
$CursorRefresh::SystemParametersInfo(0x0057,0,$null,0)

Pull request for the mouse script:
t1m0thyj/WDD-scripts#31
Mouse script where I called system parameters to update their mouse values:
https://github.com/t1m0thyj/WDD-scripts/blob/a0994e51bab41a0baeb568fa77ef0c4664958909/ChangeMouseScheme.ps1

You just need to know which API needs to be called to update these values. Maybe use Process Monitor v3.92?

@shust
Copy link

shust commented Feb 20, 2023

I noticed such a thing, if you turn off and turn on the transparency effect in the settings, then the theme comes to the desired view.

Perhaps this can somehow be added to the auto-switching day / night theme script?

Untitled-1

@adoginspace
Copy link

Looks like the AutoDarkMode team had the same issue and managed to get it working by updating the colorization: AutoDarkMode/Windows-Auto-Night-Mode#567

@t1m0thyj
Copy link
Owner

t1m0thyj commented Mar 4, 2023

It seems like Microsoft has made theme switching more difficult in Windows 11, so there is no longer a simple way to do it from a PowerShell script. I would suggest using AutoDarkMode alongside WinDynamicDesktop if you want both features - dynamic wallpaper and automatic dark theme.

@leostudiooo
Copy link
Contributor

It seems like Microsoft has made theme switching more difficult in Windows 11, so there is no longer a simple way to do it from a PowerShell script. I would suggest using AutoDarkMode alongside WinDynamicDesktop if you want both features - dynamic wallpaper and automatic dark theme.

This solution seems less elegant since one has to run one more app in the background for that. Maybe I can try to fix this when I have more spare time but that will be months later.

@bigplayer-ai
Copy link

bigplayer-ai commented Mar 4, 2023 via email

@t1m0thyj
Copy link
Owner

t1m0thyj commented Mar 9, 2023

Prior to WinDD v4, there were built-in options to change app/system theme. I removed them since the purpose of the core app is only to display dynamic wallpapers, and moved them into separate PowerShell scripts.

Contributions to the WDD-scripts repo are welcome to fix the behavior of the Change App Theme and Change System Theme scripts 🙂

@Spiritreader
Copy link

If that’s the case I think WDD should have a built in options to change dark/light theme switch that uses the way mentioned

@bigplayer-ai Honestly maintaining a functioning theme switch is nightmare territory. It almost never works reliably and you're chasing behavior that often breaks the entire windows UI for no apparent reason.

I would assume maintaining WDD by itself is already enough work as is (and so is ADM as a matter of fact)

This solution seems less elegant since one has to run one more app in the background for that. Maybe I can try to fix this when I have more spare time but that will be months late

@leostudiooo It's already possible to call ADM via CLI, perform the operations you desire and then shut it down again, so you get no background app. You can also hide the tray icon so you won't even know its running temporarily.
Yes you have to configure ADM a bit, but it should work.

As far as elegance is concerned. Automatic theme switching is absolutely not approved by Microsoft and hacks to achieve said theme switching cannot be elegant by design. We're not even sure that ADM will work in the future.

@bigplayer-ai
Copy link

bigplayer-ai commented Mar 9, 2023 via email

@Spiritreader
Copy link

Spiritreader commented Mar 9, 2023

Can you explain more about ADM clis?

We have documentation available here:
https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/wiki/Command-line-arguments-%7C-parameters

You would call something like this in WDD:

AutoDarkModeShell.exe --switch 10 --and-launch-service
AutoDarkModeShell.exe --exit

while having automatic switching and tray icon disabled in the AutoDarkMode settings, which can be configured using the app.

@Spiritreader
Copy link

Looks like the AutoDarkMode team had the same issue and managed to get it working by updating the colorization: AutoDarkMode/Windows-Auto-Night-Mode#567

Updating colorization works, but is done for a different reason, namely updating the titlebars/colors.
It should not be used when performing actual theme switching because it introduces lag. The only reason ADM makes use of this is to ensure changing the titlebar color setting takes effect immediately when no other values in a theme file are changed.
I strongly dissuade anyone from using this in order to fix light/dark theme switching.

@bigplayer-ai
Copy link

@Spiritreader
Do you have any idea How can I change mouse scheme using ADM CLI while using WDD? I tried thinking of a solution. as they support this feature.

@Spiritreader
Copy link

Spiritreader commented Mar 9, 2023

@Spiritreader Do you have any idea How can I change mouse scheme using ADM CLI while using WDD? I tried thinking of a solution. as they support this feature.

Use windows theme mode, configure two themes with different mouse cursors, then set the "ignore background" flag.

If you have further questions feel free to use the discussions tab in the Auto dark Mode repository to keep the discussion in this issue on topic.

@Spiritreader
Copy link

Spiritreader commented Mar 9, 2023

Oh Thanks I just needed to update my ADM. Btw, I am not succeeding running this in powershell 7 script, What could be the reason? I think my problem is purely syntax.

AutoDarkModeShell.exe --force-light --and-launch-service
AutoDarkModeShell.exe --exit

I'm sadly not proficient in powershell, but yes, it's probably related to escaping arguments and using the correct call syntax I would assume.
Also make sure you include the full path to the AutoDarkModeShell executable if you haven't put the ADM directory in your path variables.

I would also recommend specifying a custom timeout here:

AutoDarkModeShell.exe --force-light 10 --and-launch-service

There was a bug in older versions (including current stable, so ensure you're using the latest beta) that caused problems if it was omitted with the launch service argument present.

@bigplayer-ai
Copy link

bigplayer-ai commented Mar 9, 2023

I found the correct syntax for PowerShell 7:

$params = @("--light", "10", "--and-launch-service")
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params
$params2 = @("--exit")
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params2

What does the custom timeout do, and why do you recommend it (I thought the timeout value is a parameter that you can use with Auto Dark Mode to specify how long you want to switch your theme for.)? Why should I use it?
And do you think should I use force-dark or regular dark CLI in ADM?

@Spiritreader
Copy link

Spiritreader commented Mar 9, 2023

I found the correct syntax for PowerShell 7:

$params = @("--light", "10", "--and-launch-service")
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params
$params2 = @("--exit")
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params2

What does the custom timeout do, and why do you recommend it (I thought the timeout value is a parameter that you can use with Auto Dark Mode to specify how long you want to switch your theme for.)? Why should I use it? And do you think should I use force-dark or regular dark CLI in ADM?

The custom timeout specifies how long the shell waits for the ADM service to respond. It's to ensure compatibility as mentioned before. Some older versions don't support the --and-launch-service parameter without also specifying the timeout. Mainly because of the order in which cli arguments were parsed.

In your case it doesn't really matter if you use --force-light or --light and --force-dark or --dark since you exit the ADM service afterwards. Setting the force flag will bypass ADM's internal postpone mechanism and theme state checks. It will also prevent ADM from switching again on its own. Clearing the force status only matters if you want to keep the service alive, so I would recommend making use of the force flags.

@bigplayer-ai
Copy link

bigplayer-ai commented Mar 9, 2023

In your case it doesn't really matter if you use --force-light or --light and --force-dark or --dark since you exit the ADM service afterwards. Setting the force flag will bypass ADM's internal postpone mechanism and theme state checks. It will also prevent ADM from switching again on its own. Clearing the force status only matters if you want to keep the service alive, so I would recommend making use of the force flags.

Actually it does differ. If you force night mode while using non forced dark mode. The theme won't switch if you set it for different time.
Can you check my last version of ADM specific code snippet?

# Use a ternary operator to assign different values to $params based on $nightMode
$params = $nightMode ? @("--force-dark", "10", "--and-launch-service") : @("dark", "10", "--and-launch-service")

# Invoke AutoDarkModeShell.exe with $params
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params

# Invoke AutoDarkModeShell.exe with --exit
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" --exit

@Spiritreader
Copy link

Spiritreader commented Mar 9, 2023

In your case it doesn't really matter if you use --force-light or --light and --force-dark or --dark since you exit the ADM service afterwards. Setting the force flag will bypass ADM's internal postpone mechanism and theme state checks. It will also prevent ADM from switching again on its own. Clearing the force status only matters if you want to keep the service alive, so I would recommend making use of the force flags.

Actually it does differ. If you force night mode while using non forced dark mode. The theme won't switch if you set it for different time. Can you check my last version of ADM specific code snippet?

# Use a ternary operator to assign different values to $params based on $nightMode
$params = $nightMode ? @("--force-dark", "10", "--and-launch-service") : @("dark", "10", "--and-launch-service")

# Invoke AutoDarkModeShell.exe with $params
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params

# Invoke AutoDarkModeShell.exe with --exit
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" --exit

No. If you have set up everything correctly, it doesn't matter if you use the force method or not. Please ensure that automatic switching is disabled in ADM and that your theme is configured correctly.

Your snippet only generates --force-dark and --dark as parameters, that doesn't seem right.

I'm not involved with WDD. I merely reached out as courtesy for people that want to get theme switching to work alongside it without actually having to use the ADM background service. Which is technically not how the program is supposed to be used.

My main focus lies with maintaining ADM.
What you're doing currently should eventually lead to success though, but might require a bit of tinkering.

Good luck!

@bigplayer-ai
Copy link

bigplayer-ai commented Mar 9, 2023

Ok thanks, It seems working pretty well atm. Also, It helped me with my mouse scheme (less clutter).
I just noticed that you are part of auto dark mode program. Thank you for this amazing utility.

@Spiritreader
Copy link

Ok thanks, It seems working pretty well atm. Also, It helped me with my mouse scheme (less clutter). I just noticed that you are part of auto dark mode program. Thank you for this amazing utility.

Sure thing, glad you like it!
Just wanted to clarify that I don't really know much about WDD and powershell, as such I can't really help out there.

@t1m0thyj
Copy link
Owner

t1m0thyj commented Mar 12, 2023

Honestly maintaining a functioning theme switch is nightmare territory. It almost never works reliably and you're chasing behavior that often breaks the entire windows UI for no apparent reason.

I would assume maintaining WDD by itself is already enough work as is (and so is ADM as a matter of fact)

@Spiritreader Thanks for developing ADM ❤️ You are right, it's kind of a nightmare to maintain some features that are not approved by Microsoft 🙂 Setting a wallpaper across all virtual desktops is similar because it keeps breaking with new versions of Win11.

It's already possible to call ADM via CLI, perform the operations you desire and then shut it down again, so you get no background app. You can also hide the tray icon so you won't even know its running temporarily. Yes you have to configure ADM a bit, but it should work.

This is awesome for folks who want to use WinDD and ADM together. Would you approve of having a PowerShell script in the WDD-scripts repo that would invoke the ADM CLI to change theme? If so I can add one along with some documentation for how to set it up.

@Spiritreader
Copy link

Spiritreader commented Mar 12, 2023

@Spiritreader Thanks for developing ADM ❤️ You are right, it's kind of a nightmare to maintain some features that are not approved by Microsoft 🙂 Setting a wallpaper across all virtual desktops is similar because it keeps breaking with new versions of Win11.

@t1m0thyj Absolutely. I've been loosely following the whole virtual desktop fiasco and every time a new Windows build releases it's an "oh no" scenario where the question pops up what broke this time because they changed the import GUIDs again.
And thanks for developing and maintaining WDD. Over the years we've been pointing users to your repo whenever we noticed they wanted fancier wallpaper functionality.

This is awesome for folks who want to use WinDD and ADM together.

The easiest way still is to just run both apps simultaneously, we've made sure to include options such that other wallpaper tools don't cause collisions with ADM's theming engine.

Would you approve of having a PowerShell script in the WDD-scripts repo that would invoke the ADM CLI to change theme? If so I can add one along with some documentation for how to set it up.

Of course, go ahead! If you need more specific knowledge about the CLI than our doc on it provides, feel free to reach out.

In case you would like a more tight integration, it's possible to send the CLI messages to ADM directly via a namedpipe C# API that we provide (although in that case starting ADM has to be handled via a Process class or similar).
Doing that would have the advantage of being agnostic to the ADM installation path once it's running. That could be useful in case users want ADM running, but controlled externally by WDD without having to do any additonal setup.

https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/master/AutoDarkModeComms/PipeClient.cs
https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/master/AutoDarkModeComms/IMessageClient.cs
https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/master/AutoDarkModeSvc/Communication/Command.cs

class MessageHandler
{
    public static IMessageClient Client { get; } = new PipeClient();
}
ApiResponse result = ApiResponse.FromString(MessageHandler.Client.SendMessageAndGetReply(Command.Dark));

The extra class is not required, PipeClients can be instantiated anywhere and used concurrently in a safe manner.

Something like this works too:

IMessageClient Client = new PipeClient();
ApiResponse result = ApiResponse.FromString(Client.SendMessageAndGetReply(Command.Dark));

@meddouribadis
Copy link

meddouribadis commented Apr 16, 2023

Hello everyone and thank for your messages.
Here is the corrected bigplayer-ai script which seems to work at present.

param (
    [Parameter(Mandatory=$true)][int]$daySegment2,  # 0 = Day, 1 = Night
    [Parameter(Mandatory=$true)][int]$daySegment4,  # -1 = N/A, 0 = Sunrise, 1 = Day, 2 = Sunset, 3 = Night
    [Parameter(Mandatory=$true)][bool]$nightMode,   # True if night mode is enabled
    [Parameter(Mandatory=$false)][string]$imagePath # Path to current wallpaper image
)

# Use a ternary operator to assign different values to $params based on $nightMode
$params = $nightMode ? @("--force-dark", "10", "--and-launch-service") : @("--force-light", "10", "--and-launch-service")

# Invoke AutoDarkModeShell.exe with $params
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" @params

# Invoke AutoDarkModeShell.exe with --exit
& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" --exit

@adoginspace
Copy link

Works perfectly on my ARM64 device but throws the following error on my desktop:

Error(s) running PowerShell script
'scripts\ChangeWindowsTheme.ps1':

At
C:\Users\...\AppData\local\Programs\WinDynamicDesktop\scripts\ChangeWindowsTheme.ps1:9 char:22
+ $params = $nightMode ? @("--force-dark", "10", "--and-launch-service" ...
+            ~
Unexpected token '?' in expression or statement.
+ Categorylnfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorld : UnexpectedToken

Tried reinstalling both apps but no luck.

@Spiritreader
Copy link

Works perfectly on my ARM64 device but throws the following error on my desktop:

Error(s) running PowerShell script
'scripts\ChangeWindowsTheme.ps1':

At
C:\Users\...\AppData\local\Programs\WinDynamicDesktop\scripts\ChangeWindowsTheme.ps1:9 char:22
+ $params = $nightMode ? @("--force-dark", "10", "--and-launch-service" ...
+            ~
Unexpected token '?' in expression or statement.
+ Categorylnfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorld : UnexpectedToken

Tried reinstalling both apps but no luck.

Looks like your desktop doesn't have Powershell 7 or newer, the ternary operator didn't exist before that. in PS. Maybe that could be it.

@meddouribadis
Copy link

meddouribadis commented May 23, 2023

Works perfectly on my ARM64 device but throws the following error on my desktop:

Error(s) running PowerShell script
'scripts\ChangeWindowsTheme.ps1':

At
C:\Users\...\AppData\local\Programs\WinDynamicDesktop\scripts\ChangeWindowsTheme.ps1:9 char:22
+ $params = $nightMode ? @("--force-dark", "10", "--and-launch-service" ...
+            ~
Unexpected token '?' in expression or statement.
+ Categorylnfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorld : UnexpectedToken

Tried reinstalling both apps but no luck.

Hello, you can use this script that should works :

param (
    [Parameter(Mandatory = $true)][int]$daySegment2, # 0 = Day, 1 = Night
    [Parameter(Mandatory = $true)][int]$daySegment4, # -1 = N/A, 0 = Sunrise, 1 = Day, 2 = Sunset, 3 = Night
    [Parameter(Mandatory = $true)][bool]$nightMode, # True if night mode is enabled
    [Parameter(Mandatory = $false)][string]$imagePath # Path to current wallpaper image
)

$dark = If ($daySegment2 -eq 1) { "--force-dark" } Else { "--force-light" }

& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" $dark 10 --and-launch-service

& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" --exit

@adoginspace
Copy link

Thank you! that worked!

@freecodecampster
Copy link

TLDR; Windows 11 Settings>Personalisation>Colours>Choose your mode> Choose custom here rather than just light or dark for both seems to have fixed the inconsistent updating of system colours for me.

I'm using the powershell scripts with the desktop version to switch between light/dark mode as well as update the wallpaper. I noticed app theme would update but not always the system theme, taskbar would still be old colour mode. After killing process explorer.exe and starting again the system theme would update. Not an ideal solution. Seeing as both app and system themes are updated with two separate commands I thought I'd try setting colour mode to custom just in case there is a state bug with using powershell commands. Seems to have worked so far it's been two days and system colour theme is updating. Not sure if this is exactly related to OP or subsequent thread but thought I'd shave a workaround for a similar problem I was having.

@t1m0thyj t1m0thyj added this to the Next Release milestone Mar 17, 2024
@adoginspace
Copy link

Getting this problem again with the new update, even after changing the personalization options to custom. Does anyone know how to get the old AutoDarkMode script working for the new engine?

@t1m0thyj
Copy link
Owner

t1m0thyj commented May 28, 2024

Here's an updated version of the AutoDarkMode script in #427 (comment):

$params = $Input | ConvertFrom-Json

$dark = If ($params.daySegment2 -eq 1) { "--force-dark" } Else { "--force-light" }

& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" $dark 10 --and-launch-service

& "C:\Program Files (x86)\AutoDarkMode\AutoDarkModeShell.exe" --exit

@adoginspace
Copy link

Thank you! This worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high
Projects
None yet
Development

No branches or pull requests