[fxcop] Settings UI (#7559)

* Remove redundant default initializations

* Implement IDisposable in HotkeySettingsControl

* Mark classes and methods as static

* Move Interop.ShowWindow to NativeMethods class

* Fix string-related warnings

* Remove unused argument for KeyEventHandler

* Log caught general exceptions

* Use safe navigation operator for null argument checks

* Suppress CA2007 warnings and enable FxCop

* Suppress warning for unused event handler params

* Use TryParse in ImageResizerPage

* Use ConfigureAwait(false) for CA2007
This commit is contained in:
Luthfi Mawarid
2020-10-29 14:24:16 -07:00
committed by GitHub
parent 7ec2ff5513
commit 215c353dee
18 changed files with 120 additions and 65 deletions

View File

@@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
@@ -27,6 +29,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// Initializes a new instance of the <see cref="GeneralPage"/> class.
/// General Settings page constructor.
/// </summary>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions from the IPC response handler should be caught and logged.")]
public GeneralPage()
{
InitializeComponent();
@@ -58,28 +61,30 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_VersionIsLatest");
}
else if (version != string.Empty)
else if (!string.IsNullOrEmpty(version))
{
str = ResourceLoader.GetForCurrentView().GetString("GeneralSettings_NewVersionIsAvailable");
if (str != string.Empty)
if (!string.IsNullOrEmpty(str))
{
str += ": " + version;
}
}
ViewModel.LatestAvailableVersion = string.Format(str);
// Using CurrentCulture since this is user-facing
ViewModel.LatestAvailableVersion = string.Format(CultureInfo.CurrentCulture, str);
}
catch (Exception)
catch (Exception e)
{
Logger.LogError("Exception encountered when reading the version.", e);
}
});
DataContext = ViewModel;
}
public int UpdateUIThemeMethod(string themeName)
public static int UpdateUIThemeMethod(string themeName)
{
switch (themeName.ToUpperInvariant())
switch (themeName?.ToUpperInvariant())
{
case "LIGHT":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Light;
@@ -90,6 +95,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
case "SYSTEM":
ShellPage.ShellHandler.RequestedTheme = ElementTheme.Default;
break;
default:
Logger.LogError($"Unexpected theme name: {themeName}");
break;
}
return 0;