[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:
Andrey Nekrasov
2022-07-05 15:25:25 +03:00
committed by GitHub
parent 32fc88abd2
commit d4b62d8118

View File

@@ -12,6 +12,7 @@ using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events; using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Telemetry; using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Windows.UI.Popups; using Windows.UI.Popups;
@@ -58,6 +59,8 @@ namespace Microsoft.PowerToys.Settings.UI
public static Action<string> IPCMessageReceivedCallback { get; set; } public static Action<string> IPCMessageReceivedCallback { get; set; }
private static bool loggedImmersiveDarkException;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="App"/> class. /// Initializes a new instance of the <see cref="App"/> class.
/// Initializes the singleton application object. This is the first line of authored code /// Initializes the singleton application object. This is the first line of authored code
@@ -215,6 +218,8 @@ namespace Microsoft.PowerToys.Settings.UI
} }
public static void HandleThemeChange() public static void HandleThemeChange()
{
try
{ {
var isDark = IsDarkTheme(); var isDark = IsDarkTheme();
if (settingsWindow != null) if (settingsWindow != null)
@@ -241,6 +246,15 @@ namespace Microsoft.PowerToys.Settings.UI
themeListener = null; themeListener = null;
} }
} }
catch (Exception e)
{
if (!loggedImmersiveDarkException)
{
Logger.LogError($"HandleThemeChange exception. Please install .NET 4.", e);
loggedImmersiveDarkException = true;
}
}
}
private static ISettingsUtils settingsUtils = new SettingsUtils(); private static ISettingsUtils settingsUtils = new SettingsUtils();