From 050c2cb64781a4eba0cb84474dfde815d65c5d30 Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 17 May 2025 15:08:20 +0900 Subject: [PATCH 1/5] Refactor OpenDirectory method to improve path handling and streamline process start logic --- Flow.Launcher/PublicAPIInstance.cs | 46 +++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 5b8e8c9af89..28b4b042943 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -314,24 +314,48 @@ public void SavePluginSettings() ((PluginJsonStorage)_pluginJsonStorages[type]).Save(); } - public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null) + public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null) { - using var explorer = new Process(); + string targetPath; + + if (fileNameOrFilePath is null) + { + targetPath = directoryPath; + } + else + { + targetPath = Path.IsPathRooted(fileNameOrFilePath) + ? fileNameOrFilePath + : Path.Combine(directoryPath, fileNameOrFilePath); + } + var explorerInfo = _settings.CustomExplorer; + var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); + + // If explorer.exe, ignore and pass only the path to Shell + if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") + { + Process.Start(new ProcessStartInfo + { + FileName = targetPath, // Not explorer, Only path. + UseShellExecute = true // Must be true to open folder + }); + return; + } - explorer.StartInfo = new ProcessStartInfo + // Custom File Manager + var psi = new ProcessStartInfo { - FileName = explorerInfo.Path.Replace("%d", DirectoryPath), + FileName = explorerInfo.Path.Replace("%d", directoryPath), UseShellExecute = true, - Arguments = FileNameOrFilePath is null - ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) + Arguments = fileNameOrFilePath is null + ? explorerInfo.DirectoryArgument.Replace("%d", directoryPath) : explorerInfo.FileArgument - .Replace("%d", DirectoryPath) - .Replace("%f", - Path.IsPathRooted(FileNameOrFilePath) ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath) - ) + .Replace("%d", directoryPath) + .Replace("%f", targetPath) }; - explorer.Start(); + + Process.Start(psi); } private void OpenUri(Uri uri, bool? inPrivate = null) From b5bbd9f123ede83f9fe53732a28bb17952c60b21 Mon Sep 17 00:00:00 2001 From: DB p Date: Sat, 17 May 2025 15:16:34 +0900 Subject: [PATCH 2/5] Refactor OpenDirectory method to standardize parameter naming and improve path handling --- Flow.Launcher/PublicAPIInstance.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 28b4b042943..ad48081b467 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -314,19 +314,19 @@ public void SavePluginSettings() ((PluginJsonStorage)_pluginJsonStorages[type]).Save(); } - public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null) + public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null) { string targetPath; - if (fileNameOrFilePath is null) + if (FileNameOrFilePath is null) { - targetPath = directoryPath; + targetPath = DirectoryPath; } else { - targetPath = Path.IsPathRooted(fileNameOrFilePath) - ? fileNameOrFilePath - : Path.Combine(directoryPath, fileNameOrFilePath); + targetPath = Path.IsPathRooted(FileNameOrFilePath) + ? FileNameOrFilePath + : Path.Combine(DirectoryPath, FileNameOrFilePath); } var explorerInfo = _settings.CustomExplorer; @@ -346,12 +346,12 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null // Custom File Manager var psi = new ProcessStartInfo { - FileName = explorerInfo.Path.Replace("%d", directoryPath), + FileName = explorerInfo.Path.Replace("%d", DirectoryPath), UseShellExecute = true, - Arguments = fileNameOrFilePath is null - ? explorerInfo.DirectoryArgument.Replace("%d", directoryPath) + Arguments = FileNameOrFilePath is null + ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) : explorerInfo.FileArgument - .Replace("%d", directoryPath) + .Replace("%d", DirectoryPath) .Replace("%f", targetPath) }; From b5a17b4a24829c657cd2178e9178320f9bfbc3b7 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 17 May 2025 21:35:52 +0800 Subject: [PATCH 3/5] Improve logic --- Flow.Launcher/PublicAPIInstance.cs | 56 ++++++++++++++---------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index ad48081b467..0e32ffae562 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -316,46 +316,42 @@ public void SavePluginSettings() public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null) { - string targetPath; - - if (FileNameOrFilePath is null) - { - targetPath = DirectoryPath; - } - else - { - targetPath = Path.IsPathRooted(FileNameOrFilePath) + var explorerInfo = _settings.CustomExplorer; + var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); + var targetPath = FileNameOrFilePath is null + ? DirectoryPath + : Path.IsPathRooted(FileNameOrFilePath) ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath); - } - var explorerInfo = _settings.CustomExplorer; - var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); - - // If explorer.exe, ignore and pass only the path to Shell + using var explorer = new Process(); if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") { - Process.Start(new ProcessStartInfo + // Windows File Manager + // We should ignore and pass only the path to Shell to prevent zombie explorer.exe processes + explorer.StartInfo = new ProcessStartInfo { FileName = targetPath, // Not explorer, Only path. UseShellExecute = true // Must be true to open folder - }); - return; + }; } - - // Custom File Manager - var psi = new ProcessStartInfo + else { - FileName = explorerInfo.Path.Replace("%d", DirectoryPath), - UseShellExecute = true, - Arguments = FileNameOrFilePath is null - ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) - : explorerInfo.FileArgument - .Replace("%d", DirectoryPath) - .Replace("%f", targetPath) - }; - - Process.Start(psi); + // Custom File Manager + explorer.StartInfo = new ProcessStartInfo + { + FileName = explorerInfo.Path.Replace("%d", DirectoryPath), + UseShellExecute = true, + Arguments = FileNameOrFilePath is null + ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) + : explorerInfo.FileArgument + .Replace("%d", DirectoryPath) + .Replace("%f", targetPath) + }; + } + + // Start the process + explorer.Start(); } private void OpenUri(Uri uri, bool? inPrivate = null) From 95eaa79c703200cdae6cca6111f66a94ef01db77 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 17 May 2025 21:36:33 +0800 Subject: [PATCH 4/5] Improve code logic --- Flow.Launcher/PublicAPIInstance.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 0e32ffae562..828779f0a64 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -316,6 +316,7 @@ public void SavePluginSettings() public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null) { + using var explorer = new Process(); var explorerInfo = _settings.CustomExplorer; var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); var targetPath = FileNameOrFilePath is null @@ -324,7 +325,6 @@ public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath); - using var explorer = new Process(); if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") { // Windows File Manager From 87d11c0a74e4d641157f6baa2d7b197517974225 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 17 May 2025 21:37:27 +0800 Subject: [PATCH 5/5] Remove code comments --- Flow.Launcher/PublicAPIInstance.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 828779f0a64..796f65ae60a 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -349,8 +349,6 @@ public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null .Replace("%f", targetPath) }; } - - // Start the process explorer.Start(); }