[fxcop] Settings UI runner (#7485)

* Enable FxCop for Microsoft.PowerToys.Settings.UI.Runner

* Log exceptions in WindowsXamlHost_ChildChanged

* Add Debugger.Break in debug mode

* Move Debugger.Break into Logger class
This commit is contained in:
Luthfi Mawarid
2020-10-26 11:09:18 -07:00
committed by GitHub
parent ec22bc40bc
commit 39ebd82e20
4 changed files with 24 additions and 6 deletions

View File

@@ -32,6 +32,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
Log(message, "INFO");
}
public static void LogError(string message)
{
Log(message, "ERROR");
#if DEBUG
Debugger.Break();
#endif
}
public static void LogError(string message, Exception e)
{
Log(
@@ -42,6 +50,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
"Stack trace: " + Environment.NewLine +
e?.StackTrace,
"ERROR");
#if DEBUG
Debugger.Break();
#endif
}
private static void Log(string message, string type)

View File

@@ -5,6 +5,7 @@
using System;
using System.Windows;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
@@ -67,16 +68,17 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
{
if (ShellPage.ShellHandler.IPCResponseHandleList != null)
{
try
var success = JsonObject.TryParse(msg, out JsonObject json);
if (success)
{
JsonObject json = JsonObject.Parse(msg);
foreach (Action<JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList)
{
handle(json);
}
}
catch (Exception)
else
{
Logger.LogError("Failed to parse JSON from IPC message.");
}
}
};

View File

@@ -69,6 +69,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.3.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View File

@@ -13,7 +13,7 @@ using Windows.UI.Popups;
namespace Microsoft.PowerToys.Settings.UI.Runner
{
public class Program
public static class Program
{
// Quantity of arguments
private const int ArgumentsQty = 5;
@@ -37,9 +37,9 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
App app = new App();
app.InitializeComponent();
if (args.Length >= ArgumentsQty)
if (args != null && args.Length >= ArgumentsQty)
{
int.TryParse(args[2], out int powerToysPID);
_ = int.TryParse(args[2], out int powerToysPID);
PowerToysPID = powerToysPID;
if (args[4] == "true")