[Settings]Fix crash on dashboard when KBM settings update (#33872)

## Summary of the Pull Request
Fixed crash of Settings when KBM settings update by any mechanism.

## Detailed Description of the Pull Request / Additional comments
To show updated KBM remappings on the dashboard, the Settings app
watches for changes to the KBM settings file and reloads the file on
change. Reloading the file can fail (most likely because the writing
process takes an exclusive lock and isn't yet done writing) and the
process crashes when this happens. This change guards against this.
This commit is contained in:
Ani 2024-07-17 17:09:00 +02:00 committed by GitHub
parent fb36e6ced9
commit 7457ff5202
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,12 +87,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
private void LoadKBMSettingsFromJson()
{
try
{
KeyboardManagerProfile kbmProfile = GetKBMProfile();
_kbmItem.RemapKeys = kbmProfile?.RemapKeys.InProcessRemapKeys;
_kbmItem.RemapShortcuts = KeyboardManagerViewModel.CombineShortcutLists(kbmProfile?.RemapShortcuts.GlobalRemapShortcuts, kbmProfile?.RemapShortcuts.AppSpecificRemapShortcuts);
dispatcher.Invoke(new Action(() => UpdateKBMItems()));
}
catch (Exception ex)
{
Logger.LogError($"Failed to load KBM settings: {ex.Message}");
}
}
private void UpdateKBMItems()
{