[PR #407] feat: single-instance application support #405

Open
opened 2026-05-05 22:18:25 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/feschber/lan-mouse/pull/407
Author: @tyvsmith
Created: 3/29/2026
Status: 🔄 Open

Base: mainHead: feat/single-instance


📝 Commits (2)

  • 380eab4 feat: single-instance application support
  • 3698abd fix: use windows().first() instead of active_window() for re-activation check

📊 Changes

4 files changed (+90 additions, -13 deletions)

View changed files

📝 lan-mouse-gtk/src/lib.rs (+25 -3)
📝 lan-mouse-ipc/src/connect.rs (+32 -0)
📝 lan-mouse-ipc/src/lib.rs (+16 -1)
📝 src/main.rs (+17 -9)

📄 Description

Summary

Fixes #406 — makes lan-mouse a single-instance application so that repeated GUI launches reuse the existing daemon and raise the existing window.

  • main.rs: Probe the IPC socket via is_service_running() before spawning a daemon child process. If a daemon is already listening, skip spawning and connect the GTK frontend to it. Daemon lifecycle cleanup (SIGINT + wait + kill) only runs if we spawned the daemon ourselves.
  • lan-mouse-ipc: Add is_service_running() for a one-shot socket probe (Unix socket / TCP on Windows). Add try_connect() that attempts a single connection without the infinite retry loop of connect()/wait_for_service(). Extract shared connection-building into make_connection().
  • lan-mouse-gtk: Check app.active_window() on activate and present the existing window instead of creating a duplicate. Use try_connect() first, falling back to spawning a new daemon + connect() if the connection fails — handles the edge case where a daemon dies between the main.rs probe and the GTK connection attempt.

Behavior changes

  • When connecting to an externally-managed daemon (e.g. lan-mouse daemon), closing the GUI no longer kills it.
  • If the daemon dies between startup detection and GTK connection, the GUI transparently spawns a replacement instead of hanging.

Test plan

Verified locally on Arch Linux + Hyprland (Wayland):

  • Fresh launch (no daemon running): daemon spawns, GUI opens — works as before
  • Second launch while first is running: reuses existing daemon, raises existing window (no duplicate)
  • lan-mouse daemon started separately, then lan-mouse GUI: connects to existing daemon, closing GUI leaves daemon running
  • Daemon killed externally while GUI is starting: GUI detects failed connection, spawns a new daemon, connects successfully
  • cargo fmt passes
  • cargo build succeeds

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/feschber/lan-mouse/pull/407 **Author:** [@tyvsmith](https://github.com/tyvsmith) **Created:** 3/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/single-instance` --- ### 📝 Commits (2) - [`380eab4`](https://github.com/feschber/lan-mouse/commit/380eab4a7a9fbf74f98ba37924d27fd635f6d2c6) feat: single-instance application support - [`3698abd`](https://github.com/feschber/lan-mouse/commit/3698abd7b26d149b0224800760d5a01957abc718) fix: use windows().first() instead of active_window() for re-activation check ### 📊 Changes **4 files changed** (+90 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `lan-mouse-gtk/src/lib.rs` (+25 -3) 📝 `lan-mouse-ipc/src/connect.rs` (+32 -0) 📝 `lan-mouse-ipc/src/lib.rs` (+16 -1) 📝 `src/main.rs` (+17 -9) </details> ### 📄 Description ## Summary Fixes #406 — makes lan-mouse a single-instance application so that repeated GUI launches reuse the existing daemon and raise the existing window. - **main.rs**: Probe the IPC socket via `is_service_running()` before spawning a daemon child process. If a daemon is already listening, skip spawning and connect the GTK frontend to it. Daemon lifecycle cleanup (SIGINT + wait + kill) only runs if we spawned the daemon ourselves. - **lan-mouse-ipc**: Add `is_service_running()` for a one-shot socket probe (Unix socket / TCP on Windows). Add `try_connect()` that attempts a single connection without the infinite retry loop of `connect()`/`wait_for_service()`. Extract shared connection-building into `make_connection()`. - **lan-mouse-gtk**: Check `app.active_window()` on activate and present the existing window instead of creating a duplicate. Use `try_connect()` first, falling back to spawning a new daemon + `connect()` if the connection fails — handles the edge case where a daemon dies between the main.rs probe and the GTK connection attempt. ## Behavior changes - When connecting to an externally-managed daemon (e.g. `lan-mouse daemon`), closing the GUI no longer kills it. - If the daemon dies between startup detection and GTK connection, the GUI transparently spawns a replacement instead of hanging. ## Test plan Verified locally on Arch Linux + Hyprland (Wayland): - [x] Fresh launch (no daemon running): daemon spawns, GUI opens — works as before - [x] Second launch while first is running: reuses existing daemon, raises existing window (no duplicate) - [x] `lan-mouse daemon` started separately, then `lan-mouse` GUI: connects to existing daemon, closing GUI leaves daemon running - [x] Daemon killed externally while GUI is starting: GUI detects failed connection, spawns a new daemon, connects successfully - [x] `cargo fmt` passes - [x] `cargo build` succeeds 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror added the
pull-request
label 2026-05-05 22:18:25 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/lan-mouse#405
No description provided.