Skip to content

Commit f6c75c2

Browse files
committed
Handle exception from OpenInBrowserTab & OpenInBrowserWindow
1 parent 4bc34f6 commit f6c75c2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@
473473
</system:String>
474474
<system:String x:Key="errorTitle">Error</system:String>
475475
<system:String x:Key="folderOpenError">An error occurred while opening the folder. {0}</system:String>
476+
<system:String x:Key="browserOpenError">An error occurred while opening the url in browser. Please check your setting in Default Web Browser of general page.</system:String>
476477

477478
<!-- General Notice -->
478479
<system:String x:Key="pleaseWait">Please wait...</system:String>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,27 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
399399

400400
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
401401

402-
if (browserInfo.OpenInTab)
402+
try
403403
{
404-
uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
404+
if (browserInfo.OpenInTab)
405+
{
406+
uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
407+
}
408+
else
409+
{
410+
uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
411+
}
405412
}
406-
else
413+
catch (Exception e)
407414
{
408-
uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
415+
var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window";
416+
LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e);
417+
ShowMsgBox(
418+
GetTranslation("browserOpenError"),
419+
GetTranslation("errorTitle"),
420+
MessageBoxButton.OK,
421+
MessageBoxImage.Error
422+
);
409423
}
410424
}
411425
else

0 commit comments

Comments
 (0)