Skip to content

Commit 763fee0

Browse files
committed
Add new helper method & Improve code quality
1 parent 71b8144 commit 763fee0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public static bool FileExists(this string filePath)
150150
return File.Exists(filePath);
151151
}
152152

153+
/// <summary>
154+
/// Checks if a file or directory exists
155+
/// </summary>
156+
/// <param name="path"></param>
157+
/// <returns></returns>
158+
public static bool FileOrLocationExists(this string path)
159+
{
160+
return LocationExists(path) || FileExists(path);
161+
}
162+
153163
/// <summary>
154164
/// Open a directory window (using the OS's default handler, usually explorer)
155165
/// </summary>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public void ChangeQuery(string query, bool requery = false)
7474
_mainVM.ChangeQueryText(query, requery);
7575
}
7676

77-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]
7877
public void RestartApp()
7978
{
8079
_mainVM.Hide();
@@ -179,7 +178,7 @@ public async void CopyToClipboard(string stringToCopy, bool directCopy = false,
179178

180179
Clipboard.SetFileDropList(paths);
181180
});
182-
181+
183182
if (exception == null)
184183
{
185184
if (showDefaultNotification)
@@ -218,7 +217,7 @@ public async void CopyToClipboard(string stringToCopy, bool directCopy = false,
218217
{
219218
LogException(nameof(PublicAPIInstance), "Failed to copy text to clipboard", exception);
220219
ShowMsgError(GetTranslation("failedToCopy"));
221-
}
220+
}
222221
}
223222
}
224223

@@ -327,7 +326,7 @@ public void SavePluginSettings()
327326

328327
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
329328
}
330-
329+
331330
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
332331
{
333332
try
@@ -412,7 +411,7 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
412411

413412
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
414413
{
415-
if (uri.IsFile && !File.Exists(uri.LocalPath) && !Directory.Exists(uri.LocalPath))
414+
if (uri.IsFile && !FilesFolders.FileOrLocationExists(uri.LocalPath))
416415
{
417416
ShowMsgError(GetTranslation("errorTitle"), string.Format(GetTranslation("fileNotFoundError"), uri.LocalPath));
418417
return;
@@ -493,7 +492,7 @@ public void OpenAppUri(Uri appUri)
493492
OpenUri(appUri);
494493
}
495494

496-
public void ToggleGameMode()
495+
public void ToggleGameMode()
497496
{
498497
_mainVM.ToggleGameMode();
499498
}

0 commit comments

Comments
 (0)