[Settings] Fix null CmdPal HotKey crash (#39052)

fixed null cmdpal hotkey crash when settings.json not exists or not define hotkey
This commit is contained in:
Davide Giacometti
2025-04-24 12:18:38 +02:00
committed by GitHub
parent 5691c5754b
commit 195ff24a85

View File

@@ -4,9 +4,7 @@
using System; using System;
using System.IO; using System.IO;
using System.IO.Abstractions;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Library namespace Microsoft.PowerToys.Settings.UI.Library
{ {
@@ -46,17 +44,13 @@ namespace Microsoft.PowerToys.Settings.UI.Library
if (doc.RootElement.TryGetProperty(nameof(Hotkey), out JsonElement hotkeyElement)) if (doc.RootElement.TryGetProperty(nameof(Hotkey), out JsonElement hotkeyElement))
{ {
Hotkey = JsonSerializer.Deserialize<HotkeySettings>(hotkeyElement.GetRawText()); Hotkey = JsonSerializer.Deserialize<HotkeySettings>(hotkeyElement.GetRawText());
if (Hotkey == null)
{
Hotkey = DefaultHotkeyValue;
}
} }
} }
catch (Exception) catch (Exception)
{ {
Hotkey = DefaultHotkeyValue;
} }
Hotkey ??= DefaultHotkeyValue;
} }
} }
} }