Replies: 2 comments 4 replies
-
Beta Was this translation helpful? Give feedback.
-
|
Because it would create require more maintainable code just for an edge case, which in the end doesn't matter for the user experience of "your theme is being switched to what you expect it to look like". The reason why we have an UnmanagedLight and UnmanagedDark theme in the first place is because of ignore flags. Ignore flags generally aren't supported by default Windows themes, but they are if you create your own custom themes. If you set an ignore flag, Windows will report "Custom" as selected theme, because the theme you chose to apply with more than 0 ignore flags may not exactly match that configuration, if you, for example, chose to ignore wallpapers. In order to still keep track of where it comes from, AutoDarkMode injects its own Here is the relevant logic for theme state synchronization in Windows theme mode: /// <summary>
/// This method is responsible for updating the internal UnmanagedActiveThemePath variable. <br/>
/// Without this ADM would have no idea if the applied theme is correct. <br/>
/// We append an UnmanagedOriginalName entry to each of adm's light or dark unmanaged theme
/// file. <br/> That tells us on what theme file it was based on. This way we can prevent unnecessary theme switches <br/>
/// Appending this extra parameter is done in ThemeHandler.ApplyTheme
/// </summary>
/// <param name="config">current adm config object</param>
public void RefreshThemes(AdmConfig config)
{
if (config.WindowsThemeMode.Enabled)
{
try
{
UnmanagedActiveThemePath = RegistryHandler.GetActiveThemePath();
// for unmanaged with flags we need to set the unmanagedactivethemepath to our internal names
// This is because when using apply flags, the theme is reported as custom. However, our UnmanagedOriginalName
// persists because we have set it originally when applying the theme, so if we read that then we are aware of the origin theme
if (config.WindowsThemeMode.ApplyFlags != null && config.WindowsThemeMode.ApplyFlags.Count > 0)
{
string customPath = Path.Combine(Helper.PathThemeFolder, "Custom.theme");
bool unmanagedCustom = UnmanagedActiveThemePath.Equals(customPath);
if (unmanagedCustom)
{
UnmanagedActiveThemePath = "";
// retrieve theme names from configuration file and then compare them to the custom path
(_, _, string displayNameLight) = ThemeFile.GetDisplayNameFromRaw(config.WindowsThemeMode.LightThemePath);
(_, _, string displayNameDark) = ThemeFile.GetDisplayNameFromRaw(config.WindowsThemeMode.DarkThemePath);
string sourceThemeNameCustom = ThemeFile.GetOriginalNameFromRaw(customPath);
if (sourceThemeNameCustom == displayNameDark)
{
UnmanagedActiveThemePath = Helper.PathUnmanagedDarkTheme;
}
else if (sourceThemeNameCustom == displayNameLight)
{
UnmanagedActiveThemePath = Helper.PathUnmanagedLightTheme;
}
Logger.Debug($"refresh theme state with apply flags enabled, active theme: {(UnmanagedActiveThemePath == "" ? "undefined" : UnmanagedActiveThemePath)}");
}
}
// for unmanaged without applyflags
else
{
bool unmanagedLight = UnmanagedActiveThemePath.Equals(Helper.PathUnmanagedLightTheme);
bool unmanagedDark = UnmanagedActiveThemePath.Equals(Helper.PathUnmanagedDarkTheme);
// check if an unmanaged theme is active. If so, extract the original name from the theme path
// This way, we know which origin theme is active and don't have to switch
if (unmanagedLight)
{
string displayNameUnmanaged = ThemeFile.GetOriginalNameFromRaw(Helper.PathUnmanagedLightTheme);
(_, _, string displayNameSource) = ThemeFile.GetDisplayNameFromRaw(config.WindowsThemeMode.LightThemePath);
if (displayNameUnmanaged != displayNameSource)
{
Logger.Debug($"detected change in unmanaged light theme, new origin: {config.WindowsThemeMode.LightThemePath}");
UnmanagedActiveThemePath = "";
}
}
if (unmanagedDark)
{
string displayNameUnmanaged = ThemeFile.GetOriginalNameFromRaw(Helper.PathUnmanagedDarkTheme);
(_, _, string displayNameSource) = ThemeFile.GetDisplayNameFromRaw(config.WindowsThemeMode.DarkThemePath);
if (displayNameUnmanaged != displayNameSource)
{
Logger.Debug($"detected change in unmanaged light theme, new origin: {config.WindowsThemeMode.DarkThemePath}");
UnmanagedActiveThemePath = "";
}
}
}
}
catch (Exception ex)
{
Logger.Error(ex, "could not retrieve active theme path: ");
}
}
else
{
// we're only reading here, so we can't apply the theme fix safely
ManagedThemeFile.SyncWithActiveTheme(patch: false, keepDisplayNameAndGuid: false, logging: true);
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I use the settings where I use standard "Windows Light" and "Windows Dark" themes. Seems simple to apply, but ADM still creates its own versions, like "ADMUnmanagedLight". Why?
Beta Was this translation helpful? Give feedback.
All reactions