Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order search result by window title #3150

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

PaulPSta
Copy link

@PaulPSta PaulPSta commented Dec 27, 2024

When using the killer process feature, I often find it difficult to recall the exact name of the process I want to terminate. However, in most cases, I am trying to close a process associated with a visible window on my screen, rather than a background service or job.

To improve usability and speed, I propose sorting the search results to prioritize processes that have a non-empty MainWindowTitle, so that processes with visible windows appear first.

image

Copy link

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
❌ forbidden-pattern 22
❌ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

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.

@prlabeler prlabeler bot added the enhancement New feature or request label Dec 27, 2024
Copy link

gitstream-cm bot commented Dec 27, 2024

🥷 Code experts: no user matched threshold 10

See details

Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs

Knowledge based on git-blame:

Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs

Knowledge based on git-blame:

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

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the Process Killer plugin in Flow Launcher, focusing on improving process information handling. A new RunningProcessInfo record is added to encapsulate process details, and a method for retrieving processes with non-empty window titles is implemented. The changes aim to provide more context when displaying and managing running processes, with improvements in data structure and information retrieval mechanisms.

Changes

File Change Summary
Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs - Added RunningProcessInfo private record
- Updated CreateResultsFromQuery method
- Renamed processlist to processList
- Introduced processWithNonEmptyMainWindowTitleList
- Modified result sorting and context handling
Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs - Added P/Invoke method signatures for Windows API functions
- Defined EnumWindowsProc delegate
- Implemented GetProcessesWithNonEmptyWindowTitle() method

Sequence Diagram

sequenceDiagram
    participant PH as ProcessHelper
    participant Main as Main Plugin
    participant User as User

    User->>Main: Trigger Process Search
    Main->>PH: GetProcessesWithNonEmptyWindowTitle()
    PH-->>Main: Return Processes with Titles
    Main->>Main: Create Results
    Main-->>User: Display Processes
Loading

Poem

🐰 Processes dance, windows unfurl,
A killer's plugin with a new twirl
Titles revealed, context so bright
Hunting down tasks with rabbit-like might
Flow Launcher leaps, code clean and clear! 🔪


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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: 0

🧹 Nitpick comments (3)
Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs (2)

68-70: Consolidate dictionary usage
You're retrieving a dictionary of processes with non-empty window titles while also retrieving a broader processList. Consider whether this dictionary or an alternative data structure can more seamlessly integrate with the main list. This might streamline lookups and reduce repeated iteration.


78-90: Avoid potential performance overhead in large loops
The approach of building a new Result for each process is fine for modest lists, but in systems with many processes, enumerating them all might cause performance concerns. Periodically review if you need a paging mechanism or a more optimized approach for large process sets.

Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs (1)

80-104: Handle potential exceptions from Process.GetProcessById
If the process exits between the time of enumeration and retrieval, it may throw an exception. Consider wrapping it in a try-catch block to avoid runtime issues.

Potential approach:

+try
+{
+    var process = Process.GetProcessById((int)processId);
+    if (!processDict.ContainsKey((int)processId))
+    {
+        processDict.Add((int)processId, windowTitle.ToString());
+    }
+}
+catch (ArgumentException)
+{
+    // Process no longer exists, skip
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e7e825e and b2532fc.

📒 Files selected for processing (2)
  • Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs (3 hunks)
🔇 Additional comments (11)
Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs (4)

63-64: Use a dedicated model for clarity
Defining a record for process data is a neat way to group and transport relevant info (ProcessName, MainWindowTitle). This improves maintainability and readability. Great approach!


71-71: Consider user feedback for empty query
When processList.Any() is false, you return null. If someone types an invalid or empty query, returning null means no results. Make sure this behavior aligns with desired user experience (e.g., we might want to show a “No matching processes” item).


101-104: Sorting logic fits the use case
You’re correctly using OrderBy to push processes with non-empty window titles to the top. The subsequent .ThenBy(x => x.Title) helps group them by logical title ordering. This is straightforward and readable.


109-120: Re-check concurrency or potential race conditions
Inserting a “Kill All” option is a solid UX improvement. However, calls to TryKill for multiple processes could face concurrency or ephemeral process states. If a process closes just as the user selects “Kill All,” handle or log that possibility gracefully.

Would you like me to create a verification script to check for concurrency handling across all kill calls?

Plugins/Flow.Launcher.Plugin.ProcessKiller/ProcessHelper.cs (7)

1-1: File header looks good
No issues found regarding the top-level using directives.


14-16: Verify multi-platform considerations for EnumWindows
EnumWindows is a Windows API function. Ensure that the plugin gracefully handles or skips this functionality on non-Windows platforms.


17-17: Delegate for EnumWindowsProc
This delegate looks correctly declared for the callback.


22-23: Checks for window visibility
Using IsWindowVisible is a valid approach for filtering out hidden windows.


25-26: GetWindowThreadProcessId usage
Acquiring the process ID via GetWindowThreadProcessId is standard practice and looks good here.


77-79: Docstring clarity
The XML comment accurately describes the method’s purpose and return value.


19-20: ⚠️ Potential issue

Use a larger StringBuilder capacity
Calling new StringBuilder() defaults to 16 as capacity. This may truncate window titles longer than 16 characters.

Consider specifying a larger capacity, for example:

-StringBuilder windowTitle = new StringBuilder();
+StringBuilder windowTitle = new StringBuilder(256);

Likely invalid or redundant comment.

@taooceros
Copy link
Member

make sense! Thanks. How do you think if we rank them by the z-index on the screen (I don't know whether it is possible though)?

@@ -95,22 +98,25 @@ private List<Result> CreateResultsFromQuery(Query query)
});
}

var sortedResults = results.OrderBy(x => x.Title).ToList();
Copy link
Member

Choose a reason for hiding this comment

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

I would like to ask you to do a score bump instead of simply orderby.

Copy link

gitstream-cm bot commented Jan 9, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants