Skip to content

Commit b5a17b4

Browse files
committed
Improve logic
1 parent b5bbd9f commit b5a17b4

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -316,46 +316,42 @@ public void SavePluginSettings()
316316

317317
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
318318
{
319-
string targetPath;
320-
321-
if (FileNameOrFilePath is null)
322-
{
323-
targetPath = DirectoryPath;
324-
}
325-
else
326-
{
327-
targetPath = Path.IsPathRooted(FileNameOrFilePath)
319+
var explorerInfo = _settings.CustomExplorer;
320+
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
321+
var targetPath = FileNameOrFilePath is null
322+
? DirectoryPath
323+
: Path.IsPathRooted(FileNameOrFilePath)
328324
? FileNameOrFilePath
329325
: Path.Combine(DirectoryPath, FileNameOrFilePath);
330-
}
331326

332-
var explorerInfo = _settings.CustomExplorer;
333-
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
334-
335-
// If explorer.exe, ignore and pass only the path to Shell
327+
using var explorer = new Process();
336328
if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
337329
{
338-
Process.Start(new ProcessStartInfo
330+
// Windows File Manager
331+
// We should ignore and pass only the path to Shell to prevent zombie explorer.exe processes
332+
explorer.StartInfo = new ProcessStartInfo
339333
{
340334
FileName = targetPath, // Not explorer, Only path.
341335
UseShellExecute = true // Must be true to open folder
342-
});
343-
return;
336+
};
344337
}
345-
346-
// Custom File Manager
347-
var psi = new ProcessStartInfo
338+
else
348339
{
349-
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
350-
UseShellExecute = true,
351-
Arguments = FileNameOrFilePath is null
352-
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
353-
: explorerInfo.FileArgument
354-
.Replace("%d", DirectoryPath)
355-
.Replace("%f", targetPath)
356-
};
357-
358-
Process.Start(psi);
340+
// Custom File Manager
341+
explorer.StartInfo = new ProcessStartInfo
342+
{
343+
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
344+
UseShellExecute = true,
345+
Arguments = FileNameOrFilePath is null
346+
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
347+
: explorerInfo.FileArgument
348+
.Replace("%d", DirectoryPath)
349+
.Replace("%f", targetPath)
350+
};
351+
}
352+
353+
// Start the process
354+
explorer.Start();
359355
}
360356

361357
private void OpenUri(Uri uri, bool? inPrivate = null)

0 commit comments

Comments
 (0)