mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[arm64][Settings]Handle the case when .NET load crash on System.Management (#19176)
Prevent crashing with "System.Management requires native modules from the .NET Framework to operate." on creating ThemeListener.
This commit is contained in:
@@ -12,6 +12,7 @@ using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Windows.UI.Popups;
|
||||
@@ -58,6 +59,8 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
||||
|
||||
private static bool loggedImmersiveDarkException;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="App"/> class.
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
@@ -216,29 +219,40 @@ namespace Microsoft.PowerToys.Settings.UI
|
||||
|
||||
public static void HandleThemeChange()
|
||||
{
|
||||
var isDark = IsDarkTheme();
|
||||
if (settingsWindow != null)
|
||||
try
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(settingsWindow);
|
||||
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
||||
}
|
||||
var isDark = IsDarkTheme();
|
||||
if (settingsWindow != null)
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(settingsWindow);
|
||||
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
||||
}
|
||||
|
||||
if (oobeWindow != null)
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(oobeWindow);
|
||||
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
||||
}
|
||||
if (oobeWindow != null)
|
||||
{
|
||||
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(oobeWindow);
|
||||
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
|
||||
}
|
||||
|
||||
var selectedTheme = SelectedTheme();
|
||||
if (selectedTheme == "SYSTEM")
|
||||
{
|
||||
themeListener = new ThemeListener();
|
||||
themeListener.ThemeChanged += (_) => HandleThemeChange();
|
||||
var selectedTheme = SelectedTheme();
|
||||
if (selectedTheme == "SYSTEM")
|
||||
{
|
||||
themeListener = new ThemeListener();
|
||||
themeListener.ThemeChanged += (_) => HandleThemeChange();
|
||||
}
|
||||
else if (themeListener != null)
|
||||
{
|
||||
themeListener.Dispose();
|
||||
themeListener = null;
|
||||
}
|
||||
}
|
||||
else if (themeListener != null)
|
||||
catch (Exception e)
|
||||
{
|
||||
themeListener.Dispose();
|
||||
themeListener = null;
|
||||
if (!loggedImmersiveDarkException)
|
||||
{
|
||||
Logger.LogError($"HandleThemeChange exception. Please install .NET 4.", e);
|
||||
loggedImmersiveDarkException = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user