From 195ff24a854eca63b5deaafe6c172bb9ed8a9743 Mon Sep 17 00:00:00 2001 From: Davide Giacometti <25966642+davidegiacometti@users.noreply.github.com> Date: Thu, 24 Apr 2025 12:18:38 +0200 Subject: [PATCH] [Settings] Fix null CmdPal HotKey crash (#39052) fixed null cmdpal hotkey crash when settings.json not exists or not define hotkey --- .../Settings.UI.Library/CmdPalProperties.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/settings-ui/Settings.UI.Library/CmdPalProperties.cs b/src/settings-ui/Settings.UI.Library/CmdPalProperties.cs index 406f67c2a4..9102609b6b 100644 --- a/src/settings-ui/Settings.UI.Library/CmdPalProperties.cs +++ b/src/settings-ui/Settings.UI.Library/CmdPalProperties.cs @@ -4,9 +4,7 @@ using System; using System.IO; -using System.IO.Abstractions; using System.Text.Json; -using System.Text.Json.Serialization; 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)) { Hotkey = JsonSerializer.Deserialize(hotkeyElement.GetRawText()); - - if (Hotkey == null) - { - Hotkey = DefaultHotkeyValue; - } } } catch (Exception) { - Hotkey = DefaultHotkeyValue; } + + Hotkey ??= DefaultHotkeyValue; } } }