Skip to content

fix(macos): exit process cleanly after cleanup on quit (#644) - #650

Merged
khaira777 merged 1 commit into
mainfrom
fix/macos-dock-quit-lifecycle-644
Sep 6, 2026
Merged

khaira777 merged 1 commit into
mainfrom
fix/macos-dock-quit-lifecycle-644

Conversation

@khaira777

@khaira777 khaira777 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #644

Problem

On macOS, closing the application window hides it to the Dock. However, when right-clicking the app in the Dock and selecting Quit (or pressing Cmd+Q), the app only partially quits:

  • will-quit prevents default to run asynchronous cleanup.
  • Once cleanup finishes, app.quit() was called.
  • Because Cocoa termination was already aborted and all windows are closed/destroyed, calling app.quit() from an asynchronous Promise callback does not re-terminate the headless Cocoa run loop, leaving the process in the Dock as an unresponsive zombie requiring a second quit.

Solution

  • In main/shutdown.ts, after runCleanup() completes and verifies !isInstallingUpdate(), call app.exit(exitCode) directly (matching the non-zero and signal exit paths), ensuring the process cleanly terminates on the first quit attempt.
  • Updated tests/shutdown-lifecycle.test.ts to assert that app.exitCodes receives [0] on completed cleanup.

Summary by CodeRabbit

  • Bug Fixes

    • Improved application shutdown behavior to consistently return the intended exit status after cleanup, including during updater handoffs.
  • Tests

    • Updated shutdown lifecycle coverage to verify clean exit statuses during normal application closure.

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 88cc804e-6701-4bfd-9f76-01e7aeecae6f

📥 Commits

Reviewing files that changed from the base of the PR and between 04181fc and 9c0563b.

📒 Files selected for processing (2)
  • main/shutdown.ts
  • tests/shutdown-lifecycle.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The shutdown cleanup path now calls app.exit(exitCode) for all non-update cases. Lifecycle tests verify clean exit code handling and no exit during an active updater installation.

Changes

Shutdown exit handling

Layer / File(s) Summary
Direct exit after cleanup
main/shutdown.ts, tests/shutdown-lifecycle.test.ts
quitAfterCleanup uses app.exit(exitCode) for clean exits. Tests verify exit code 0 after normal cleanup and no exit while updater installation is active.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 9c056

After cleanup, normal quit paths now terminate the application with the computed exit code, fixing the macOS first-quit hang while preserving updater handoff behavior. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, root cause, solution, and linked issue, but it omits most required template sections, including Scope, Verification commands and results, Compatibility & data saf… Add the missing template sections. Document the exact tests or commands run and their results. State the scope, compatibility and data impact, applicable screenshots, and checklist status.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the macOS shutdown fix and matches the primary change.
Linked Issues check ✅ Passed The changes satisfy issue #644 by replacing the clean-exit app.quit() path with app.exit(exitCode) after cleanup, while preserving the updater guard and updating tests to verify exit code [0].
Out of Scope Changes check ✅ Passed The changes are limited to the shutdown implementation and its lifecycle tests. Both files directly support issue #644 and the stated objectives.
Full details: Description check

Explanation

The description explains the problem, root cause, solution, and linked issue, but it omits most required template sections, including Scope, Verification commands and results, Compatibility & data safety, Screenshots, and the contributor checklist.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/macos-dock-quit-lifecycle-644

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

@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes successful shutdown completion to call app.exit(exitCode) after cleanup, preventing macOS from retaining a headless process after Quit.

  • Preserves cleanup, window destruction, exit-code propagation, and update-installation ownership.
  • Updates lifecycle tests to require exit code 0 for normal shutdown and no direct exit during update installation.

Confidence Score: 5/5

The PR appears safe to merge because required cleanup still completes before direct termination and update installation retains control of its own shutdown path.

The changed branch preserves the existing exit code, destroys the window after cleanup, and skips app.exit() while an update installation is active; no current lifecycle listener depends on the removed second app.quit() pass.

Important Files Changed

Filename Overview
main/shutdown.ts Replaces the post-cleanup zero-code app.quit() retry with direct process termination while retaining cleanup and update-install guards.
tests/shutdown-lifecycle.test.ts Updates normal-quit expectations to assert app.exit(0) and verifies update installation still suppresses direct exit.

Sequence Diagram

sequenceDiagram
    participant User
    participant Electron
    participant Shutdown
    participant Cleanup
    User->>Electron: Quit / Cmd+Q
    Electron->>Shutdown: will-quit
    Shutdown-->>Electron: preventDefault()
    Shutdown->>Cleanup: runCleanup()
    Cleanup-->>Shutdown: completed
    Shutdown->>Shutdown: destroyWindow()
    alt Installing update
        Shutdown-->>Electron: Let quitAndInstall own termination
    else Normal quit
        Shutdown->>Electron: app.exit(exitCode)
    end
Loading

Reviews (1): Last reviewed commit: "fix(macos): exit process cleanly after c..." | Re-trigger Greptile

@khaira777
khaira777 merged commit 3dfb3f5 into main Sep 6, 2026
16 checks passed
@khaira777
khaira777 deleted the fix/macos-dock-quit-lifecycle-644 branch September 6, 2026 00:58
@itsbkm itsbkm mentioned this pull request Sep 6, 2026
3 of 4 tasks
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.

[Bug]: macOS app remains in Dock after quitting and requires quitting a second time

1 participant