Skip to content

Conversation

onesounds
Copy link
Contributor

Summary

Problem

Previously, we used ProcessStartInfo with FileName = "explorer.exe" and Arguments = "folder path" to open directories. However, when launched this way from a WPF application, explorer.exe remains as a child process and does not exit even after its window is closed.

Solution

Instead of launching explorer.exe directly, this PR updates the logic to:

  • Use Process.Start("folder path") with UseShellExecute = true when the custom explorer is set to explorer.exe.
  • This leverages the Windows Shell to open the folder using the default handler (usually File Explorer), avoiding the need to explicitly invoke explorer.exe.

This method ensures that:

  • No zombie explorer.exe processes are left behind.
  • The folder is still opened as expected in the File Explorer.

Additional Notes

  • Custom explorers still work as before using the original logic.
  • This change only affects when the custom explorer is explicitly set to "explorer.exe".

@prlabeler prlabeler bot added the bug Something isn't working label May 17, 2025
@onesounds onesounds self-assigned this May 17, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented May 17, 2025

🥷 Code experts: Jack251970

Jack251970 has most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970
MAY 70 additions & 18 deletions
APR 165 additions & 61 deletions
MAR 21 additions & 19 deletions
FEB 28 additions & 11 deletions
JAN 45 additions & 47 deletions
DEC 25 additions & 32 deletions

Knowledge based on git-blame:
Jack251970: 49%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented May 17, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented May 17, 2025

📝 Walkthrough

"""

Walkthrough

The OpenDirectory method in PublicAPIInstance was refactored to better resolve file and directory paths and to distinguish between launching the default Windows Explorer and custom file managers. The new logic avoids spawning persistent unwanted explorer processes by opening directories via the shell when using the default explorer.

Changes

File(s) Change Summary
Flow.Launcher/PublicAPIInstance.cs Refactored OpenDirectory method: improved path resolution, distinguished handling for Windows Explorer vs. custom file managers, updated method signature parameter casing.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant PublicAPIInstance
    participant Shell/Process
    participant CustomFileManager

    Caller->>PublicAPIInstance: OpenDirectory(directoryPath, fileNameOrFilePath)
    PublicAPIInstance->>PublicAPIInstance: Resolve targetPath
    PublicAPIInstance->>PublicAPIInstance: Get custom file explorer path
    alt Using default Windows Explorer
        PublicAPIInstance->>Shell/Process: Start(targetPath, UseShellExecute=true)
    else Using custom file manager
        PublicAPIInstance->>CustomFileManager: Start(customExplorerPath, args)
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent persistent unwanted Windows Explorer processes when opening directories (#3550)

Poem

A folder opens, neat and bright,
No ghostly explorers haunt the night.
With careful code, the bug is gone—
Just one true window lingers on.
A hop, a fix, a tidy view,
This bunny brings the change to you! 🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5bbd9f and 87d11c0.

📒 Files selected for processing (1)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/PublicAPIInstance.cs
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Flow.Launcher/PublicAPIInstance.cs (2)

346-359: Consider adding error handling for Process.Start

The code starts processes without any try-catch blocks, which could lead to unhandled exceptions if the paths are invalid or there are permission issues.

Consider adding error handling:

-            Process.Start(psi);
+            try
+            {
+                Process.Start(psi);
+            }
+            catch (Exception e)
+            {
+                LogException(nameof(PublicAPIInstance), $"Failed to open directory: {directoryPath}", e);
+                ShowMsgError(GetTranslation("failedToOpenDirectory"));
+            }

Also apply similar error handling to the explorer.exe case above.


335-336: Consider more robust explorer.exe detection

The current implementation checks if the lowercase filename is "explorer", which works for typical cases but might be improved.

Consider using a case-insensitive string comparison instead of normalizing to lowercase:

-var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
-            
-// If explorer.exe, ignore and pass only the path to Shell
-if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
+var explorerPath = explorerInfo.Path.Trim();
+            
+// If explorer.exe, ignore and pass only the path to Shell
+if (string.Equals(Path.GetFileNameWithoutExtension(explorerPath), "explorer", StringComparison.OrdinalIgnoreCase))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb25c53 and 050c2cb.

📒 Files selected for processing (1)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Flow.Launcher/PublicAPIInstance.cs (2)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
  • OpenDirectory (301-301)
Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs (1)
  • OpenDirectory (163-166)
🪛 GitHub Actions: Check Spelling
Flow.Launcher/PublicAPIInstance.cs

[warning] 49-52: Spell check warning: Ioc is not a recognized word. (unrecognized-spelling)


[warning] 145-174: Spell check warning: VSTHRD is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (3)
Flow.Launcher/PublicAPIInstance.cs (3)

319-330: LGTM: Improved path resolution logic

The new path resolution logic correctly handles both null paths and absolute/relative file paths, ensuring proper path combining behavior.


334-344: Excellent fix for the zombie explorer.exe processes

This solution elegantly addresses the issue by bypassing direct explorer.exe process creation when the default file explorer is used. By starting the process with the path directly and setting UseShellExecute = true, Windows will use the registered handler (typically explorer.exe) but in a way that prevents zombie processes.


338-343:

✅ Verification successful

Verify this approach works for all folder paths

The new method of opening folders by passing the path directly to Process.Start with UseShellExecute = true might behave differently for certain path formats, network paths, or special Windows folders.


🏁 Script executed:

#!/bin/bash
# Script to check if there are any tests or usage patterns that might be affected by the changes

# Look for tests related to the OpenDirectory method
rg -n "OpenDirectory" --type cs

# Check if there are any special path handling cases in the codebase
rg -n "UNC|\\\\\\\\|\\\\\\\\" --type cs

# Check for special folder references that might be affected
rg -n "Environment.SpecialFolder|GetFolderPath" --type cs

# Look for any explorer.exe process handling
rg -n "explorer\\.exe|Process\\.Start.*explorer" --type cs

Length of output: 24095


Process.Start with UseShellExecute=true correctly opens all physical folders (local and UNC)

The change hands off folder opening to ShellExecute, which transparently supports drive-letter paths, network (UNC) shares, long paths, spaces, etc. Special shell namespaces (Recycle Bin, Control Panel, etc.) remain handled by the existing explicit Process.Start("explorer", …) calls in:

  • Plugins/Flow.Launcher.Plugin.Sys/Main.cs:354
  • Flow.Launcher.Infrastructure/FileExplorerHelper.cs:57

No additional verification or code changes are needed here.

This comment has been minimized.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
Flow.Launcher/PublicAPIInstance.cs (1)

317-317: Parameter naming inconsistency with interface.

The parameter names have been changed from PascalCase to camelCase, but the interface IPublicAPI.OpenDirectory still uses PascalCase parameters: DirectoryPath and FileNameOrFilePath. This creates an inconsistency between the interface and implementation.

Either:

  1. Update the interface to match this implementation, or
  2. Revert to using PascalCase parameters to maintain consistency with the interface
🧹 Nitpick comments (1)
Flow.Launcher/PublicAPIInstance.cs (1)

346-359: Consider adding exception handling.

While the custom file manager logic looks good, there's no exception handling around the Process.Start calls. If the explorer application doesn't exist or can't be started, this could throw an unhandled exception.

-            Process.Start(psi);
+            try
+            {
+                Process.Start(psi);
+            }
+            catch (Exception ex)
+            {
+                LogException(nameof(PublicAPIInstance), $"Failed to open directory with custom explorer: {explorerInfo.Path}", ex);
+                // Fallback to default explorer as a recovery mechanism
+                Process.Start(new ProcessStartInfo
+                {
+                    FileName = targetPath,
+                    UseShellExecute = true
+                });
+            }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 050c2cb and b5bbd9f.

📒 Files selected for processing (1)
  • Flow.Launcher/PublicAPIInstance.cs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Flow.Launcher/PublicAPIInstance.cs

[warning] 49-52: Ioc is not a recognized word. (unrecognized-spelling)


[warning] 145-174: VSTHRD is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher/PublicAPIInstance.cs (2)

317-331: Improved path resolution logic.

The new implementation properly handles different path scenarios, making the code more robust.


332-344: Good fix for zombie explorer.exe processes.

This specialized handling for Windows Explorer addresses the core issue described in the PR. By using Process.Start with UseShellExecute = true and passing only the target path (without explicitly starting explorer.exe), the code now leverages the Windows Shell to open folders, preventing zombie processes.

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested

@Jack251970 Jack251970 added this to the 1.20.0 milestone May 17, 2025
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@jjw24 jjw24 merged commit ac8a979 into Flow-Launcher:dev May 18, 2025
8 checks passed
@Jack251970 Jack251970 mentioned this pull request Jun 6, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Explorer plugin duplicates explorer program BUG: Opening directory produced an error BUG: Cannot open theme folder

3 participants