From 63cf13d0cd1f0c2bdfae81ddd8eff74be5c6f35f Mon Sep 17 00:00:00 2001 From: Wujidadi Date: Mon, 27 Jul 2026 07:56:36 +0800 Subject: [PATCH] fix: deliver CLI control notifications immediately 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. --- sources/Main.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sources/Main.swift b/sources/Main.swift index f998248d9..dcc993ffb 100644 --- a/sources/Main.swift +++ b/sources/Main.swift @@ -35,7 +35,9 @@ struct SquirrelApp { runningSquirrels.forEach { $0.terminate() } return true case "--reload": - DistributedNotificationCenter.default().postNotificationName(.init("SquirrelReloadNotification"), object: nil) + // Squirrel is a background app, and AppKit suspends distributed-notification delivery to inactive apps; + // deliverImmediately is required for these notifications to reach Squirrel while it stays in the background + DistributedNotificationCenter.default().postNotificationName(.init("SquirrelReloadNotification"), object: nil, userInfo: nil, deliverImmediately: true) return true case "--register-input-source", "--install": installer.register() @@ -76,13 +78,13 @@ struct SquirrelApp { _ = rimeAPI.deploy() return true case "--sync": - DistributedNotificationCenter.default().postNotificationName(.init("SquirrelSyncNotification"), object: nil) + DistributedNotificationCenter.default().postNotificationName(.init("SquirrelSyncNotification"), object: nil, userInfo: nil, deliverImmediately: true) return true case "--ascii": - DistributedNotificationCenter.default().postNotificationName(.init("SquirrelToggleASCIIModeNotification"), object: "ascii") + DistributedNotificationCenter.default().postNotificationName(.init("SquirrelToggleASCIIModeNotification"), object: "ascii", userInfo: nil, deliverImmediately: true) return true case "--nascii": - DistributedNotificationCenter.default().postNotificationName(.init("SquirrelToggleASCIIModeNotification"), object: "nascii") + DistributedNotificationCenter.default().postNotificationName(.init("SquirrelToggleASCIIModeNotification"), object: "nascii", userInfo: nil, deliverImmediately: true) return true case "--getascii": var responseReceived = false @@ -97,7 +99,7 @@ struct SquirrelApp { responseReceived = true } } - DistributedNotificationCenter.default().postNotificationName(.init("SquirrelGetASCIIModeNotification"), object: nil) + DistributedNotificationCenter.default().postNotificationName(.init("SquirrelGetASCIIModeNotification"), object: nil, userInfo: nil, deliverImmediately: true) let timeout = Date().addingTimeInterval(2.0) while !responseReceived && Date() < timeout { RunLoop.current.run(until: Date().addingTimeInterval(0.01))