diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index c01cd8dbe..411560030 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -12,15 +12,12 @@ using Wox.Infrastructure.Storage; using Wox.Plugin.Program.Programs; using Wox.Plugin.Program.Views; -using Stopwatch = Wox.Infrastructure.Stopwatch; using System.Threading; -using Windows.ApplicationModel.Background; namespace Wox.Plugin.Program { public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable { - private static readonly object IndexLock = new object(); internal static Win32[] _win32s { get; set; } internal static UWP.Application[] _uwps { get; set; } internal static Settings _settings { get; set; } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index ce40d1e70..1cd5e971d 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -125,6 +125,7 @@ public static void InitializePlugins(IPublicAPI api) { e.Data.Add(nameof(pair.Metadata.ID), pair.Metadata.ID); e.Data.Add(nameof(pair.Metadata.Name), pair.Metadata.Name); + e.Data.Add(nameof(pair.Metadata.PluginDirectory), pair.Metadata.PluginDirectory); e.Data.Add(nameof(pair.Metadata.Website), pair.Metadata.Website); Logger.WoxError($"Fail to Init plugin: {pair.Metadata.Name}", e); pair.Metadata.Disabled = true; @@ -191,6 +192,7 @@ public static List QueryForPlugin(PluginPair pair, Query query) { e.Data.Add(nameof(pair.Metadata.ID), pair.Metadata.ID); e.Data.Add(nameof(pair.Metadata.Name), pair.Metadata.Name); + e.Data.Add(nameof(pair.Metadata.PluginDirectory), pair.Metadata.PluginDirectory); e.Data.Add(nameof(pair.Metadata.Website), pair.Metadata.Website); Logger.WoxError($"Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e); return new List(); diff --git a/Wox.Core/Plugin/PluginsLoader.cs b/Wox.Core/Plugin/PluginsLoader.cs index 5f1233a95..365109bf0 100644 --- a/Wox.Core/Plugin/PluginsLoader.cs +++ b/Wox.Core/Plugin/PluginsLoader.cs @@ -54,6 +54,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Couldn't load assembly for {metadata.Name}", e); return; @@ -68,6 +69,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Can't find class implement IPlugin for <{metadata.Name}>", e); return; @@ -81,6 +83,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Can't create instance for <{metadata.Name}>", e); return; diff --git a/Wox.Infrastructure/Exception/ExceptionFormatter.cs b/Wox.Infrastructure/Exception/ExceptionFormatter.cs index 904be0770..707e91e40 100644 --- a/Wox.Infrastructure/Exception/ExceptionFormatter.cs +++ b/Wox.Infrastructure/Exception/ExceptionFormatter.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Xml; using Microsoft.Win32; +using Wox.Infrastructure.UserSettings; namespace Wox.Infrastructure.Exception { @@ -141,6 +142,7 @@ public static string RuntimeInfo() StringBuilder sb = new StringBuilder(); sb.AppendLine("## Runtime Info"); sb.AppendLine($"* Command Line: {Environment.CommandLine}"); + sb.AppendLine($"* Portable Mode: {DataLocation.PortableDataLocationInUse()}"); sb.AppendLine($"* Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); sb.AppendLine($"* Wox version: {Constant.Version}"); sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}"); diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 359726856..2ec678519 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -101,7 +101,23 @@ public static void updateSettingsInfo(string woxLanguage) public static void SendException(System.Exception exception) { - SentrySdk.CaptureException(exception); + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + string pluginDirectory = exception.Data[pluginDiretoryKey] as string; + bool debug = pluginDirectory.Contains(@"\Output\Release") || pluginDirectory.Contains(@"\Output\Release"); + bool thirdParty = !pluginDirectory.Contains(Constant.ProgramDirectory); + if (debug || thirdParty) + { + return; + } + } + + SentrySdk.WithScope(scope => + { + scope.Level = Sentry.Protocol.SentryLevel.Error; + SentrySdk.CaptureException(exception); + }); } } } \ No newline at end of file diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs index efd7e2791..4dd711fe6 100644 --- a/Wox/Helper/ErrorReporting.cs +++ b/Wox/Helper/ErrorReporting.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; @@ -10,6 +11,7 @@ using Sentry.Protocol; using Wox.Infrastructure; using Wox.Infrastructure.Exception; +using Wox.Infrastructure.UserSettings; namespace Wox.Helper { @@ -26,7 +28,7 @@ private static void Report(Exception e, string id, [CallerMemberName] string met public static void UnhandledExceptionHandleTask(Task t) { - SentryId id = SentrySdk.CaptureException(t.Exception); + string id = SendException(t.Exception); Application.Current.Dispatcher.Invoke(() => { Report(t.Exception, id.ToString()); @@ -35,7 +37,7 @@ public static void UnhandledExceptionHandleTask(Task t) public static void UnhandledExceptionHandleMain(object sender, UnhandledExceptionEventArgs e) { - SentryId id = SentrySdk.CaptureException(e.ExceptionObject as Exception); + string id = SendException(e.ExceptionObject as Exception); //handle non-ui main thread exceptions Application.Current.Dispatcher.Invoke(() => { @@ -45,8 +47,8 @@ public static void UnhandledExceptionHandleMain(object sender, UnhandledExceptio public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - SentryId id = SentrySdk.CaptureException(e.Exception); - Report(e.Exception, id.ToString()); + string id = SendException(e.Exception); + Report(e.Exception, id); //prevent application exist, so the user can copy prompted error info e.Handled = true; } @@ -63,10 +65,37 @@ public static IDisposable InitializedSentry(string systemLanguage) }); SentrySdk.ConfigureScope(scope => { + scope.SetExtra("commandLine", Environment.CommandLine); + scope.SetExtra("portableMode", DataLocation.PortableDataLocationInUse()); scope.SetTag("systemLanguage", systemLanguage); scope.SetTag("timezone", TimeZoneInfo.Local.DisplayName); + scope.SetExtra("x64OS", Environment.Is64BitOperatingSystem); + scope.SetExtra("x64Process", Environment.Is64BitProcess); }); return s; } + + public static string SendException(Exception exception) + { + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + string pluginDirectory = exception.Data[pluginDiretoryKey] as string; + bool debug = pluginDirectory.Contains(@"\Output\Release") || pluginDirectory.Contains(@"\Output\Release"); + bool thirdParty = !pluginDirectory.Contains(Constant.ProgramDirectory); + if (debug || thirdParty) + { + return SentryId.Empty.ToString(); + } + } + + SentryId id = SentryId.Empty; + SentrySdk.WithScope(scope => + { + scope.Level = SentryLevel.Fatal; + id = SentrySdk.CaptureException(exception); + }); + return id.ToString(); + } } } diff --git a/Wox/ReportWindow.xaml.cs b/Wox/ReportWindow.xaml.cs index 5866d2d67..30a7858fa 100644 --- a/Wox/ReportWindow.xaml.cs +++ b/Wox/ReportWindow.xaml.cs @@ -38,6 +38,11 @@ private void SetException(Exception exception, string id) { paragraph.Inlines.Add($"Plugin Name {exception.Data[nameKey]}"); } + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + paragraph.Inlines.Add($"Plugin Directory {exception.Data[pluginDiretoryKey]}"); + } string idKey = nameof(Plugin.PluginPair.Metadata.ID); if (exception.Data.Contains(idKey)) {