diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
index 6c506cfc06c..3af57f00d53 100644
--- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
+++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs
@@ -150,6 +150,16 @@ public static bool FileExists(this string filePath)
return File.Exists(filePath);
}
+ ///
+ /// Checks if a file or directory exists
+ ///
+ ///
+ ///
+ public static bool FileOrLocationExists(this string path)
+ {
+ return LocationExists(path) || FileExists(path);
+ }
+
///
/// Open a directory window (using the OS's default handler, usually explorer)
///
diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml
index 626fe1385a4..561bb277eff 100644
--- a/Flow.Launcher/Languages/en.xaml
+++ b/Flow.Launcher/Languages/en.xaml
@@ -590,6 +590,7 @@
Error
An error occurred while opening the folder. {0}
An error occurred while opening the URL in the browser. Please check your Default Web Browser configuration in the General section of the settings window
+ File or directory not found: {0}
Please wait...
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 6a8ee40f98c..b4c3aa92b82 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Specialized;
@@ -74,7 +74,6 @@ public void ChangeQuery(string query, bool requery = false)
_mainVM.ChangeQueryText(query, requery);
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "")]
public void RestartApp()
{
_mainVM.Hide();
@@ -179,7 +178,7 @@ public async void CopyToClipboard(string stringToCopy, bool directCopy = false,
Clipboard.SetFileDropList(paths);
});
-
+
if (exception == null)
{
if (showDefaultNotification)
@@ -218,7 +217,7 @@ public async void CopyToClipboard(string stringToCopy, bool directCopy = false,
{
LogException(nameof(PublicAPIInstance), "Failed to copy text to clipboard", exception);
ShowMsgError(GetTranslation("failedToCopy"));
- }
+ }
}
}
@@ -327,7 +326,7 @@ public void SavePluginSettings()
((PluginJsonStorage)_pluginJsonStorages[type]).Save();
}
-
+
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
{
try
@@ -412,6 +411,12 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
{
+ if (uri.IsFile && !FilesFolders.FileOrLocationExists(uri.LocalPath))
+ {
+ ShowMsgError(GetTranslation("errorTitle"), string.Format(GetTranslation("fileNotFoundError"), uri.LocalPath));
+ return;
+ }
+
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
{
var browserInfo = _settings.CustomBrowser;
@@ -441,13 +446,19 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
}
else
{
- Process.Start(new ProcessStartInfo()
+ try
{
- FileName = uri.AbsoluteUri,
- UseShellExecute = true
- })?.Dispose();
-
- return;
+ Process.Start(new ProcessStartInfo()
+ {
+ FileName = uri.AbsoluteUri,
+ UseShellExecute = true
+ })?.Dispose();
+ }
+ catch (Exception e)
+ {
+ LogException(ClassName, $"Failed to open: {uri.AbsoluteUri}", e);
+ ShowMsgError(GetTranslation("errorTitle"), e.Message);
+ }
}
}
@@ -481,7 +492,7 @@ public void OpenAppUri(Uri appUri)
OpenUri(appUri);
}
- public void ToggleGameMode()
+ public void ToggleGameMode()
{
_mainVM.ToggleGameMode();
}