mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Plugin Exception Draft (#1147)
This commit is contained in:
parent
af7efd8347
commit
fa7057ae8f
3 changed files with 62 additions and 11 deletions
24
Flow.Launcher.Core/ExternalPlugins/FlowPluginException.cs
Normal file
24
Flow.Launcher.Core/ExternalPlugins/FlowPluginException.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Flow.Launcher.Plugin;
|
||||
using System;
|
||||
|
||||
namespace Flow.Launcher.Core.ExternalPlugins
|
||||
{
|
||||
public class FlowPluginException : Exception
|
||||
{
|
||||
public PluginMetadata Metadata { get; set; }
|
||||
|
||||
public FlowPluginException(PluginMetadata metadata, Exception e) : base(e.Message, e)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $@"{Metadata.Name} Exception:
|
||||
Websites: {Metadata.Website}
|
||||
Author: {Metadata.Author}
|
||||
Version: {Metadata.Version}
|
||||
{base.ToString()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -182,13 +183,11 @@ namespace Flow.Launcher.Core.Plugin
|
|||
public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
var metadata = pair.Metadata;
|
||||
|
||||
try
|
||||
{
|
||||
var metadata = pair.Metadata;
|
||||
|
||||
long milliseconds = -1L;
|
||||
|
||||
milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
|
||||
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
|
||||
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
@ -206,7 +205,10 @@ namespace Flow.Launcher.Core.Plugin
|
|||
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
|
||||
return null;
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new FlowPluginException(metadata, e);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
|
@ -22,13 +23,34 @@ namespace Flow.Launcher
|
|||
SetException(exception);
|
||||
}
|
||||
|
||||
private static string GetIssueUrl(string website)
|
||||
{
|
||||
if (!website.StartsWith("https://github.com"))
|
||||
{
|
||||
return website;
|
||||
}
|
||||
if(website.Contains("Flow-Launcher/Flow.Launcher"))
|
||||
{
|
||||
return Constant.Issue;
|
||||
}
|
||||
var treeIndex = website.IndexOf("tree", StringComparison.Ordinal);
|
||||
return treeIndex == -1 ? $"{website}/issues/new" : $"{website[..treeIndex]}/issues/new";
|
||||
}
|
||||
|
||||
private void SetException(Exception exception)
|
||||
{
|
||||
string path = Log.CurrentLogDirectory;
|
||||
var directory = new DirectoryInfo(path);
|
||||
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
|
||||
|
||||
var paragraph = Hyperlink("Please open new issue in: ", Constant.Issue);
|
||||
var websiteUrl = exception switch
|
||||
{
|
||||
FlowPluginException pluginException =>GetIssueUrl(pluginException.Metadata.Website),
|
||||
_ => Constant.Issue
|
||||
};
|
||||
|
||||
|
||||
var paragraph = Hyperlink("Please open new issue in: ", websiteUrl);
|
||||
paragraph.Inlines.Add($"1. upload log file: {log.FullName}\n");
|
||||
paragraph.Inlines.Add($"2. copy below exception message");
|
||||
ErrorTextbox.Document.Blocks.Add(paragraph);
|
||||
|
|
@ -49,7 +71,10 @@ namespace Flow.Launcher
|
|||
var paragraph = new Paragraph();
|
||||
paragraph.Margin = new Thickness(0);
|
||||
|
||||
var link = new Hyperlink { IsEnabled = true };
|
||||
var link = new Hyperlink
|
||||
{
|
||||
IsEnabled = true
|
||||
};
|
||||
link.Inlines.Add(url);
|
||||
link.NavigateUri = new Uri(url);
|
||||
link.RequestNavigate += (s, e) => SearchWeb.OpenInBrowserTab(e.Uri.ToString());
|
||||
|
|
@ -62,4 +87,4 @@ namespace Flow.Launcher
|
|||
return paragraph;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue