Repository navigation
fix(v3): add SingleInstance.OnSecondInstanceExit for pre-exit cleanup - #6078
4RH1T3CT0R7 wants to merge 2 commits into
Conversation
The second instance terminated via os.Exit inside application.New, and again inside the darwin and linux notify implementations, so nothing the caller deferred before New ever ran. Run an optional OnSecondInstanceExit hook after notifying the first instance, and keep a single exit site. Fixes wailsapp#6052
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe single-instance exit path now uses a manager method that notifies the first instance, runs an optional callback, and exits with the configured code. Platform notification methods no longer exit directly. Tests and documentation cover the new behavior. ChangesSingle-instance exit handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SecondInstance
participant singleInstanceManager
participant FirstInstance
SecondInstance->>singleInstanceManager: application.New detects existing instance
singleInstanceManager->>FirstInstance: notifyFirstInstance()
singleInstanceManager->>SecondInstance: OnSecondInstanceExit()
SecondInstance->>SecondInstance: os.Exit(ExitCode)
Suggested reviewers: Merge Risk: 🟡 Moderate · up to The exit-hook behavior is implemented and documented, but the new test code contains a duplicate type declaration that prevents the package tests from compiling. Remove the duplicate before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. (1 skipped: 1 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
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. A rabbit checked the second door, Comment |
|
Ported this PR's ExitCode/OnSecondInstanceExit documentation to M-Press in 397faec and updated the corresponding existing page in all nine languages (de, fr, id, ja, ko, pt, ru, zh-cn, zh-tw). Dependency: merged #6137 at 7b0f6dc and changed this PR's base to Validation: M-Press 1.0.17 strict build, link/asset check, and rendered-site check passed (2,010 content pages; 2,011 HTML pages; zero site errors). Linux Known gate: the global translation audit remains failing with 7,678 findings, matching the pinned migration baseline count; findings outside this page are unchanged. The inherited migration audit blocker is separate work and the gate remains enabled. |
|
Thanks for carrying this over to M-Press and sorting out the notify conflict. |
When SingleInstance finds the lock already held, the second process ends with os.Exit inside application.New, so anything the caller deferred before New (flushing a file, releasing a lock, closing a log) never runs. The darwin and linux notify implementations also had their own os.Exit, giving three exit sites for the same path.
This adds SingleInstanceOptions.OnSecondInstanceExit, called in the second instance after the first has been notified and right before os.Exit(ExitCode), and collapses the three exit sites into one manager method. Apps that don't set the hook behave exactly as before. A subprocess test checks the hook runs after notification and the process exits with ExitCode; it skips on macOS, where notifyFirstInstance runs an AppKit loop to capture the launch URL. The Linux notify overlaps with the open #5973, so whichever lands second needs a small rebase.
Fixes #6052
Summary by CodeRabbit
New Features
OnSecondInstanceExitcallback for cleanup or resource handling before a second application instance exits.Documentation