Skip to content

feat(application): add cross-platform single-instance lock and IPC - #111

Merged
lijy91 merged 1 commit into
mainfrom
feat/single-instance-issue-72
Dec 1, 2026
Merged

lijy91 merged 1 commit into
mainfrom
feat/single-instance-issue-72

Conversation

@lijy91

@lijy91 lijy91 commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Implements cross-platform single-instance locking and second-instance argument forwarding on Application (libnativeapi/nativeapi#72):

  • Adds Application::RequestSingleInstanceLock(const std::string& identifier, const std::vector<std::string>& arguments = {}), HasSingleInstanceLock() const, ReleaseSingleInstanceLock(), and ApplicationSecondInstanceEvent (GetArguments(), GetWorkingDirectory()).
  • Windows: Per-session named mutex (Local\NativeAPISingleInstance_<key>) + overlapped named pipe IPC (\\.\pipe\NativeAPISingleInstance_<key>). Secondary instances call AllowSetForegroundWindow(ASFW_ANY) before forwarding arguments and current working directory so the primary instance can bring its window to the foreground.
  • macOS & Linux: Exclusive flock lock file + Unix domain socket IPC (automatically cleaned up by the OS kernel on crash), with self-pipe wake-up for clean shutdown.
  • Android / iOS / OpenHarmony / WASM: Stubs returning false / no-op (matching platform availability notes).
  • Updates Application::IsSingleInstance() on desktop platforms to reflect HasSingleInstanceLock().
  • Adds multi-process integration test tests/application_single_instance_test.cpp verifying lock acquisition, idempotency, conflict rejection, real child-process argument/cwd forwarding via ApplicationSecondInstanceEvent, and lock handoff after ReleaseSingleInstanceLock().

@lijy91
lijy91 merged commit 3925fa3 into main Dec 1, 2026
11 checks passed
@lijy91
lijy91 deleted the feat/single-instance-issue-72 branch December 1, 2026 12:30
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