Skip to content

Conversation

sanoojes
Copy link
Contributor

@sanoojes sanoojes commented Oct 2, 2025

Use exact match as it now kills apps like spotify_player

Summary by CodeRabbit

  • Bug Fixes
    • Improved restart reliability on macOS and Linux by matching only the exact app process name, preventing accidental termination of similarly named processes.
    • Ensures the correct process is targeted during shutdown and restart flows, reducing unexpected interruptions.
    • No changes to behavior on Windows.

Copy link

coderabbitai bot commented Oct 2, 2025

Walkthrough

Updated process termination logic in src/cmd/restart.go: on Linux and Darwin, pkill now uses exact-match (-x) for the Spotify process name; Windows logic unchanged.

Changes

Cohort / File(s) Summary
Process termination logic
src/cmd/restart.go
Switch pkill invocations on Linux/Darwin to use exact-name matching (-x) for "spotify"/"Spotify"; no change for Windows.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant User
  participant RestartCmd as Restart Command
  participant SpotifyKill as SpotifyKill()
  participant OS as OS Check
  participant Proc as pkill

  User->>RestartCmd: invoke restart
  RestartCmd->>SpotifyKill: terminate Spotify
  SpotifyKill->>OS: detect platform
  alt Linux/Darwin
    OS-->>SpotifyKill: unix-like
    SpotifyKill->>Proc: pkill -x "spotify" / "Spotify"
    note over Proc,SpotifyKill: Exact-name match required
  else Windows
    OS-->>SpotifyKill: windows
    SpotifyKill->>Proc: taskkill /IM Spotify.exe /F (unchanged)
  end
  SpotifyKill-->>RestartCmd: result
  RestartCmd-->>User: continue restart flow
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at tidy kills, hop-hop, precise and neat—
No fuzzy names, just exact bills, processes face defeat.
On penguin paths and apple trails, I tap the -x with cheer,
While Windows hums its steady tales—restart is crystal clear.
(\*/)^(_^) 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely and accurately summarizes the core change by indicating that pkill will now use an exact match when terminating Spotify, directly reflecting the modifications in the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cmd/restart.go (1)

20-25: Use exact match with pgrep for consistency.

Line 21 uses pgrep spotify without the -x flag, which will match process names like spotify_player. For consistency with the exact-match termination on line 24, and to avoid false positives in the detection logic, add the -x flag to pgrep as well.

Apply this diff:

-		isRunning := exec.Command("pgrep", "spotify")
+		isRunning := exec.Command("pgrep", "-x", "spotify")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15d1365 and 8aad069.

📒 Files selected for processing (1)
  • src/cmd/restart.go (1 hunks)

Comment on lines 26 to 31
case "darwin":
isRunning := exec.Command("sh", "-c", "ps aux | grep 'Spotify' | grep -v grep")
_, err := isRunning.CombinedOutput()
if err == nil {
exec.Command("pkill", "Spotify").Run()
exec.Command("pkill", "-x", "Spotify").Run()
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Use pgrep with exact match for consistency.

Line 27 uses ps aux | grep 'Spotify' which will match any process containing "Spotify" in its command line, creating an inconsistency with the exact-match termination on line 30. For consistency with the Linux implementation and to avoid false positives, replace the grep-based detection with pgrep -x Spotify.

Apply this diff:

-		isRunning := exec.Command("sh", "-c", "ps aux | grep 'Spotify' | grep -v grep")
-		_, err := isRunning.CombinedOutput()
+		isRunning := exec.Command("pgrep", "-x", "Spotify")
+		_, err := isRunning.Output()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case "darwin":
isRunning := exec.Command("sh", "-c", "ps aux | grep 'Spotify' | grep -v grep")
_, err := isRunning.CombinedOutput()
if err == nil {
exec.Command("pkill", "Spotify").Run()
exec.Command("pkill", "-x", "Spotify").Run()
}
case "darwin":
- isRunning := exec.Command("sh", "-c", "ps aux | grep 'Spotify' | grep -v grep")
isRunning := exec.Command("pgrep", "-x", "Spotify")
_, err := isRunning.Output()
if err == nil {
exec.Command("pkill", "-x", "Spotify").Run()
}
🤖 Prompt for AI Agents
In src/cmd/restart.go around lines 26 to 31, replace the ps+grep detection with
an exact-match pgrep call: run exec.Command("pgrep", "-x",
"Spotify").CombinedOutput() and use its error/result to decide whether to call
exec.Command("pkill", "-x", "Spotify").Run(); this ensures exact-process
matching consistent with the pkill usage and avoids false positives from
substring matches.

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

Successfully merging this pull request may close these issues.

1 participant