fix: post CLI control notifications with deliverImmediately - #1163
Merged
Conversation
Squirrel runs as a background app, and AppKit suspends distributed-notification delivery to apps while they are inactive. The notifications posted by `--reload`, `--sync`, `--ascii`, `--nascii` and `--getascii` were therefore queued or dropped instead of being delivered, so these CLI options appeared to silently do nothing; the corresponding menu items kept working because they invoke the same handlers in-process. Posting with `deliverImmediately: true` bypasses the receiver's suspension so the notifications arrive while Squirrel stays in the background.
There was a problem hiding this comment.
Pull request overview
This PR fixes flaky/ineffective CLI control commands (--reload, --sync, --ascii, --nascii, --getascii) by ensuring their distributed notifications are delivered to the running Squirrel app even while it remains inactive in the background.
Changes:
- Post all five CLI control distributed notifications with
deliverImmediately: trueto bypass AppKit’s suspended-delivery behavior for inactive apps. - Add an explanatory comment documenting why
deliverImmediatelyis necessary for the background-app use case.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
The log file isn't a reliable way to verify if the input method app has done something. Logs can be buffered and sometimes the log file can be missing. Not to comment on the solution though. |
Contributor
Author
|
這個改動的主要依據是我的個人觀察及驗證:
改為 |
Member
|
謝謝。已合併。 |
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.
Problem
squirrel --reload,--sync,--ascii,--nasciiand--getasciifrequently do nothing, while the corresponding menu items always work.Root cause
These CLI options communicate with the running Squirrel instance via distributed notifications. AppKit suspends distributed-notification delivery to applications while they are inactive, and Squirrel — a background input-method app — is virtually always inactive. Since
postNotificationName(_:object:)defaults todeliverImmediately: false, the posted notification respects the receiver's suspension and gets queued or dropped instead of delivered; occasionally it arrives late when Squirrel briefly becomes active, which makes the commands appear flaky rather than broken. The menu items are unaffected because they invoke the same handlers in-process.Verified on macOS 26.5:
squirrel --syncleaves no trace inrime.squirrel.INFO, while posting the same notification withdeliverImmediately: truetriggers the sync within a second.Fix
Post all five CLI control notifications with
deliverImmediately: true, which is documented to bypass the receiver's suspension behavior.