Skip to content

Conversation

@bhdai
Copy link

@bhdai bhdai commented Jan 14, 2026

problem

When launching the app while an instance is already running, a new instance starts instead of bringing the existing window to focus. This results in duplicate system tray icons.

The socket cleanup was running BEFORE the connection check,causing every new launch to delete the socket before attempting to detect an existing instance.

solution

Reorder the logic in main():

  1. First - Attempt to connect to existing server
  2. If connected - Send "reopen" message and exit (another instance is running)
  3. If connection fails - Clean up any stale socket files, then start the server

Summary by CodeRabbit

  • Bug Fixes
    • Improved startup cleanup so temporary IPC artifacts are only removed when the app proceeds as the active instance; this prevents accidental removal when another instance is running and preserves cleanup after quit. No changes to public APIs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

Relocated IPC server cleanup from before the duplicate-instance check to after it so cleanup runs only when a new instance proceeds (no existing instance detected), preserving post-exit cleanup of stale IPC artifacts.

Changes

Cohort / File(s) Summary
IPC Cleanup Control Flow
linux/main.cpp
Removed pre-check removal of IPC artifacts (app_server, /tmp/app_server) and moved cleanup to run after the duplicate-instance check succeeds (after the socket_check wait-for-connect block and following server lifecycle events). Cleanup after application quit remains.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix(linux): correct single-instance detection order' directly and specifically summarizes the main change in the pull request—reordering the single-instance detection logic to check for existing instances before cleaning up socket files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
linux/main.cpp (1)

1058-1065: Consider removing redundant removeServer call.

The QLocalServer::removeServer("app_server") at line 1059 is redundant since line 1025 already handles cleanup after the connection check fails. No code between these lines could create a new socket file.

♻️ Suggested simplification
     QLocalServer server;
-    QLocalServer::removeServer("app_server");

     if (!server.listen("app_server"))

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97cb02c and b2043c9.

📒 Files selected for processing (1)
  • linux/main.cpp
🔇 Additional comments (1)
linux/main.cpp (1)

1013-1026: LGTM! Correct fix for single-instance detection.

The reordering correctly ensures that:

  1. Connection attempt happens first to detect an existing instance
  2. Socket cleanup only occurs after confirming no other instance is running

This prevents the race condition where cleanup would remove the socket before the existing instance could be detected.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

🤖 Fix all issues with AI agents
In `@linux/main.cpp`:
- Around line 1026-1028: Remove the hardcoded QFile-based removals of
"/tmp/app_server" and rely solely on QLocalServer::removeServer("app_server");
specifically delete the QFile stale("/tmp/app_server"); if (stale.exists())
stale.remove(); blocks (the occurrences around the QLocalServer::removeServer
calls) so the code no longer attempts to manually remove /tmp/app_server and
lets QLocalServer handle socket cleanup in the correct runtime directory.
🧹 Nitpick comments (1)
linux/main.cpp (1)

1061-1064: Redundant removeServer call.

Line 1062 is now redundant since cleanup already occurs at line 1025 after the connection check fails.

🔧 Suggested fix
     QLocalServer server;
-    QLocalServer::removeServer("app_server");

     if (!server.listen("app_server"))
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 339c478 and 97cb02c.

📒 Files selected for processing (1)
  • linux/main.cpp
🔇 Additional comments (1)
linux/main.cpp (1)

1013-1028: LGTM! Correct fix for single-instance detection.

The reordering properly ensures the cleanup only runs after confirming no existing instance is running. This prevents the race condition where a new launch would delete the socket before detecting the already-running instance.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

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.

2 participants