fix(plugins): hide the window before running quit hooks (#94) - #97
Merged
Conversation
Closing kept the window on screen for as long as the slowest plugin onBeforeQuit callback took — gist-sync pushes to GitHub on exit, so the app looked frozen for ~2s. Hide the window first so the wait is invisible, and only when a hook is actually registered. Arm the Rust-side exit up front with a fallback timer and quit from a finally block, so a throwing hook or a failed invoke can never leave a hidden window over a live process.
Works well on Windows, thanks and waiting for the release !! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #94. Based on @Flash303's diagnosis and patch in #95 — the approach here is theirs, with two extra safety fixes.
Cause
ensureQuitHandler()(src/plugins/runtime.ts) interceptsonCloseRequested, callspreventDefault(), and then awaits every pluginonBeforeQuitcallback (capped at 5s) before triggering the Rust-side exit. The window stays on screen for that entire wait. The gist-sync plugin pushes to GitHub in its quit hook, so closing the app looked frozen for ~2s. With no plugin registering a quit hook the handler is never installed at all, which is why this only reproduces with a plugin like gist-sync enabled.Change
core:window:allow-hidecapability (not part ofcore:default).finallyblock. Without this, a throwing hook or aninvokethat never lands would leave a hidden window over a live process — worse than a slow close.Tests
New
src/plugins/runtime.quitHandler.test.tscovers: hide precedes the hook, no hide when there are zero hooks, exit still happens when a hook throws, and exit on the 5s cap with the fallback timer disarmed (force_quitinvoked exactly once).pnpm tsc --noEmitclean;pnpm vitest run src/pluginsgreen (73 files, 593 tests).Live verification
Debug build driven under Xvfb/WebKitGTK through tauri-driver, with a test plugin whose quit hook runs for ~2.4s:
plugin:window|is_visiblesampled from inside the hook:falseat every sample from 303ms onward through 2429ms — the window is gone while the sync is still running.Not verified on Windows — no Windows machine here. The mechanism is platform-independent, but @Flash303 confirmed the original symptom and fix on Windows 11.