Skip to content

fix: post CLI control notifications with deliverImmediately - #1163

Merged
lotem merged 1 commit into
rime:masterfrom
Wujidadi:fix-cli-notification-delivery
Jul 28, 2026
Merged

fix: post CLI control notifications with deliverImmediately#1163
lotem merged 1 commit into
rime:masterfrom
Wujidadi:fix-cli-notification-delivery

Conversation

@Wujidadi

Copy link
Copy Markdown
Contributor

Problem

squirrel --reload, --sync, --ascii, --nascii and --getascii frequently 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 to deliverImmediately: 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 --sync leaves no trace in rime.squirrel.INFO, while posting the same notification with deliverImmediately: true triggers 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.

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.
Copilot AI review requested due to automatic review settings July 27, 2026 00:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: true to bypass AppKit’s suspended-delivery behavior for inactive apps.
  • Add an explanatory comment documenting why deliverImmediately is necessary for the background-app use case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lotem

lotem commented Jul 27, 2026

Copy link
Copy Markdown
Member

squirrel --sync leaves no trace in rime.squirrel.INFO

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.

@Wujidadi

Wujidadi commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

這個改動的主要依據是我的個人觀察及驗證:

  • 預設發送方式下 squirrel --sync 有時不會出現同步的通知氣泡,~/Library/Rime/sync/ 下的快照檔 mtime 也沒變。
  • 而選單的「同步用戶資料」每次兩者俱現。

改為 deliverImmediately: true(通知名稱、接收端相同)後,下指令一秒內氣泡均可出現,快照能正常更新。日誌僅為佐證。

@lotem
lotem merged commit 7b4a314 into rime:master Jul 28, 2026
1 check passed
@lotem

lotem commented Jul 28, 2026

Copy link
Copy Markdown
Member

謝謝。已合併。

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.

3 participants