From a7c890319db4c574d8897a8fb315e92c719c136e Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Sun, 12 May 2024 10:41:31 +0200 Subject: [PATCH 1/4] add NaN check to PluginOption ViewModel --- .../ViewModels/PluginAdditionalOptionViewModel.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs index d1c22ad0b5d..f15f28e256a 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs @@ -105,7 +105,15 @@ public double NumberValue get => _additionalOption.NumberValue; set { - if (value != _additionalOption.NumberValue) + if (double.IsNaN(value)) + { + // If the user clears the number box and presses enter or moves focus awai then `value` convertet to double results in `double.NaN`. This crashes the setiings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) + // To prevent the crash an provide a nice user experienece we reset the numberbox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. + // (Yes we could use 0, but this needs additional code for checking 0 against min and max. + // And yes we could also use the min value of the NumberBox, but is not user firendly as NumberBoxMin can be `double.MinValue`.) + NotifyPropertyChanged(); + } + else if (value != _additionalOption.NumberValue) { _additionalOption.NumberValue = value; NotifyPropertyChanged(); From 880befda18fe6db7d510c7f13e8234ed95e50bd5 Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Sun, 12 May 2024 10:53:34 +0200 Subject: [PATCH 2/4] fix spelling --- .../ViewModels/PluginAdditionalOptionViewModel.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs index f15f28e256a..4786c0012f6 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs @@ -107,10 +107,10 @@ public double NumberValue { if (double.IsNaN(value)) { - // If the user clears the number box and presses enter or moves focus awai then `value` convertet to double results in `double.NaN`. This crashes the setiings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) - // To prevent the crash an provide a nice user experienece we reset the numberbox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. + // If the user clears the number box and presses enter or moves focus away then `value` converted to double results in `double. NaN`. This crashes the settings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) + // To prevent the crash an provide a nice user experience we reset the number box to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. // (Yes we could use 0, but this needs additional code for checking 0 against min and max. - // And yes we could also use the min value of the NumberBox, but is not user firendly as NumberBoxMin can be `double.MinValue`.) + // And yes we could also use the min value of the NumberBox, but is not user friendly as NumberBoxMin can be `double. MinValue`.) NotifyPropertyChanged(); } else if (value != _additionalOption.NumberValue) From 008854194bb9c8d08ca7dca097a696a58f539b65 Mon Sep 17 00:00:00 2001 From: htcfreek <61519853+htcfreek@users.noreply.github.com> Date: Sun, 12 May 2024 10:56:41 +0200 Subject: [PATCH 3/4] fix spelling --- .../ViewModels/PluginAdditionalOptionViewModel.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs index 4786c0012f6..213038f9358 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs @@ -107,10 +107,10 @@ public double NumberValue { if (double.IsNaN(value)) { - // If the user clears the number box and presses enter or moves focus away then `value` converted to double results in `double. NaN`. This crashes the settings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) - // To prevent the crash an provide a nice user experience we reset the number box to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. + // If the user clears the NumberBox and presses enter or moves focus away then `value` converted to double results in `double.NaN`. This crashes the settings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) + // To prevent the crash an provide a nice user experience we reset the NumberBox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. // (Yes we could use 0, but this needs additional code for checking 0 against min and max. - // And yes we could also use the min value of the NumberBox, but is not user friendly as NumberBoxMin can be `double. MinValue`.) + // And yes we could also use the min value of the NumberBox, but this is not user friendly as the minimum value of NumberBox can be `double.MinValue`.) NotifyPropertyChanged(); } else if (value != _additionalOption.NumberValue) From aaf43b47416083a8f2f6c6c89b1b2dea67ab68d0 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Sun, 12 May 2024 18:58:23 +0200 Subject: [PATCH 4/4] Update PluginAdditionalOptionViewModel.cs --- .../Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs index 213038f9358..02b83228c7e 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PluginAdditionalOptionViewModel.cs @@ -108,7 +108,7 @@ public double NumberValue if (double.IsNaN(value)) { // If the user clears the NumberBox and presses enter or moves focus away then `value` converted to double results in `double.NaN`. This crashes the settings app. (https://github.com/microsoft/PowerToys/issues/32738#issuecomment-2105983967) - // To prevent the crash an provide a nice user experience we reset the NumberBox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. + // To prevent the crash and provide a nice user experience we reset the NumberBox to the last valid value. This happens by sending a `NotifyPropertyChanged()` command and let the NumberBox reload its value. // (Yes we could use 0, but this needs additional code for checking 0 against min and max. // And yes we could also use the min value of the NumberBox, but this is not user friendly as the minimum value of NumberBox can be `double.MinValue`.) NotifyPropertyChanged();