feat: add destroy menubar capability#5
Merged
Conversation
Adds a `destroy()` method which removes all event listeners and prevents the window from opening after that, until a new instance is created. Also adds an `isDestroyed()` accessor. Adapted from upstream PR max-mapper#323. Co-authored-by: Jimmy <3059814+typologist@users.noreply.github.com>
When `app.isReady()` is true at construction time, `onAppReady` is scheduled via `process.nextTick`, which `destroy()` cannot cancel by removing a listener. Short-circuit `onAppReady` when `_isDestroyed` is already set so a sync construct-then-destroy pattern doesn't recreate the tray and window on the next tick. Also tightens the mocks into spies and adds spec assertions that `destroy()` actually removes the tray and app listeners, and that a second `destroy()` is a true no-op.
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.
Summary
destroy()method that removes all tray and app listeners, destroys the underlyingBrowserWindow, and prevents the window from opening again until a newMenubarinstance is created.isDestroyed()accessor reporting the destroyed state.clicked,onAppReady, andonAppActivateinto arrow-function class fields so they have stable references and can be removed from event emitters by reference.destroy()/isDestroyed()and extends the electron mock withdestroy/removeListener.Adapted from the upstream PR max-mapper/menubar#323 by @typologist, which fixes maxogden/menubar#281.
Test plan
bun run test— all tests passbun run typecheck— no errorsbun run lint:check— no new warnings (one pre-existing warning unrelated to this PR)bun run build— produces ESM/CJS bundles