Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Flow.Launcher.Core/ExternalPlugins/FlowPluginException.cs
Original file line number Diff line number Diff line change
@@ -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()}";
}
}
}
16 changes: 9 additions & 7 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Flow.Launcher.Core.ExternalPlugins;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -182,13 +183,11 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)
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();
Expand All @@ -206,7 +205,10 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
// 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;
}

Expand Down
33 changes: 29 additions & 4 deletions Flow.Launcher/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Flow.Launcher.Core.ExternalPlugins;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand All @@ -22,13 +23,34 @@ public ReportWindow(Exception exception)
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);
Expand All @@ -49,7 +71,10 @@ private Paragraph Hyperlink(string textBeforeUrl, string url)
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());
Expand All @@ -62,4 +87,4 @@ private Paragraph Hyperlink(string textBeforeUrl, string url)
return paragraph;
}
}
}
}