Skip to content

Commit b6e2740

Browse files
authored
Merge pull request #3851 from Flow-Launcher/url_exception
Fix uri exception in Report window
2 parents 2b40107 + b7096dd commit b6e2740

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Flow.Launcher/ReportWindow.xaml.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using Flow.Launcher.Core.ExternalPlugins;
2-
using System;
1+
using System;
32
using System.Globalization;
43
using System.IO;
5-
using System.Text;
64
using System.Linq;
5+
using System.Text;
76
using System.Windows;
87
using System.Windows.Documents;
8+
using Flow.Launcher.Core.ExternalPlugins;
99
using Flow.Launcher.Helper;
1010
using Flow.Launcher.Infrastructure;
11-
using Flow.Launcher.Plugin.SharedCommands;
1211
using Flow.Launcher.Infrastructure.UserSettings;
12+
using Flow.Launcher.Plugin.SharedCommands;
1313

1414
namespace Flow.Launcher
1515
{
@@ -44,7 +44,7 @@ private void SetException(Exception exception)
4444

4545
var websiteUrl = exception switch
4646
{
47-
FlowPluginException pluginException =>GetIssuesUrl(pluginException.Metadata.Website),
47+
FlowPluginException pluginException => GetIssuesUrl(pluginException.Metadata.Website),
4848
_ => Constant.IssuesUrl
4949
};
5050

@@ -73,17 +73,36 @@ private static Paragraph Hyperlink(string textBeforeUrl, string url)
7373
Margin = new Thickness(0)
7474
};
7575

76-
var link = new Hyperlink
76+
Hyperlink link = null;
77+
try
7778
{
78-
IsEnabled = true
79-
};
80-
link.Inlines.Add(url);
81-
link.NavigateUri = new Uri(url);
82-
link.Click += (s, e) => SearchWeb.OpenInBrowserTab(url);
79+
var uri = new Uri(url);
80+
81+
link = new Hyperlink
82+
{
83+
IsEnabled = true
84+
};
85+
link.Inlines.Add(url);
86+
link.NavigateUri = uri;
87+
link.Click += (s, e) => SearchWeb.OpenInBrowserTab(url);
88+
}
89+
catch (Exception)
90+
{
91+
// Leave link as null if the URL is invalid
92+
}
8393

8494
paragraph.Inlines.Add(textBeforeUrl);
8595
paragraph.Inlines.Add(" ");
86-
paragraph.Inlines.Add(link);
96+
if (link is null)
97+
{
98+
// Add the URL as plain text if it is invalid
99+
paragraph.Inlines.Add(url);
100+
}
101+
else
102+
{
103+
// Add the hyperlink if it is valid
104+
paragraph.Inlines.Add(link);
105+
}
87106
paragraph.Inlines.Add("\n");
88107

89108
return paragraph;

0 commit comments

Comments
 (0)