mirror of
https://github.com/block/buzz.git
synced 2026-11-13 21:01:53 +00:00
Follow-up to review notes on [#9360 Home Screen shortcuts](https://github.com/block/buzz/pull/9360). These are fixes for rare races, with no visible change. - **The member picker can't wedge.** UIKit ignores a dismiss that arrives mid-transition (the sheet still animating in, or during an interactive swipe-down) and never runs its completion. The picker coordinator queues every later present behind that completion, so New DM and Add members then opened nothing for the rest of the session. Dismiss now waits for the transition to finish, then dismisses whatever is still presented. - **A shortcut tap reaches Dart once.** The native bridge both buffered a tap and sent it, so a tap during cold launch could arrive twice and run again after Home had already handled it. Now a tap is buffered only until Dart first takes the pending one, and after that it is sent directly. - **Signing out drops a waiting tap.** Removing Home clears a tap that is still waiting (for example on a Bestie that is still loading), so it can't run in the next account's Home. Not included: carrying the Bestie's pubkey in the shortcut item, so a stale "Message Alice" falls back to Agents rather than opening the current Bestie. It's optional, and it would change the bridge's payload shared with the lock screen widgets in [#9373 lock screen widgets](https://github.com/block/buzz/pull/9373). ### Validation - The Home shortcut journey gains a step: a tap waiting while the app is inactive is cleared when Home goes away. The step fails with the teardown guard removed. - Automated simulator run (iPhone 17 Pro, iOS 27, signed in to a Builderlab test community), driving the app icon's quick actions on the Home Screen: - New DM from a conversation opens the picker. New DM again, with the picker already open, replaces it. New chat over the picker closes it and opens a draft, and New DM after that opens the picker again (it doesn't get stuck). - Message (Bestie) opens the Bestie conversation. - Cold launch through New chat opens exactly one New chat screen. Back returns to Messages. buzz-review-completed Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.7 KiB
Swift
70 lines
2.7 KiB
Swift
import Flutter
|
|
import UIKit
|
|
|
|
/// Publishes Home Screen quick actions from Flutter and hands taps back to it.
|
|
///
|
|
/// A tap can arrive before Dart is listening (cold launch, or before Home
|
|
/// mounts), so until Dart first takes the buffered tap the latest one waits
|
|
/// there. After that, each tap is sent to Dart once.
|
|
final class HomeScreenShortcuts {
|
|
static let shared = HomeScreenShortcuts()
|
|
|
|
private static let types: Set<String> = ["new-chat", "new-dm", "message-bestie"]
|
|
private static let icons: [String: UIApplicationShortcutIcon] = [
|
|
"new-chat": UIApplicationShortcutIcon(systemImageName: "square.and.pencil"),
|
|
"new-dm": UIApplicationShortcutIcon(systemImageName: "bubble.left"),
|
|
"message-bestie": UIApplicationShortcutIcon(templateImageName: "ShortcutAgent"),
|
|
]
|
|
|
|
private var channel: FlutterMethodChannel?
|
|
private var pending: String?
|
|
/// Whether Dart has taken the buffered tap and now receives taps directly.
|
|
private var listening = false
|
|
|
|
func attach(messenger: FlutterBinaryMessenger) {
|
|
let channel = FlutterMethodChannel(name: "buzz/home_screen_shortcuts", binaryMessenger: messenger)
|
|
self.channel = channel
|
|
channel.setMethodCallHandler { [weak self] call, result in
|
|
switch call.method {
|
|
case "setItems":
|
|
guard let items = call.arguments as? [[String: String]] else {
|
|
result(FlutterError(code: "invalid_input", message: nil, details: nil))
|
|
return
|
|
}
|
|
var shortcuts: [UIApplicationShortcutItem] = []
|
|
for item in items {
|
|
guard let type = item["type"], Self.types.contains(type), let title = item["title"] else {
|
|
result(FlutterError(code: "invalid_input", message: "Unknown shortcut", details: item))
|
|
return
|
|
}
|
|
shortcuts.append(
|
|
UIApplicationShortcutItem(
|
|
type: type, localizedTitle: title, localizedSubtitle: nil, icon: Self.icons[type], userInfo: nil))
|
|
}
|
|
UIApplication.shared.shortcutItems = shortcuts
|
|
result(nil)
|
|
case "takePending":
|
|
result(self?.pending)
|
|
self?.pending = nil
|
|
self?.listening = true
|
|
default:
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Returns false for items this bridge does not own.
|
|
@discardableResult
|
|
func handle(_ item: UIApplicationShortcutItem) -> Bool {
|
|
guard Self.types.contains(item.type) else { return false }
|
|
let type = item.type
|
|
pending = type
|
|
// Sending a tap that is also buffered could reach Dart twice: once from
|
|
// the channel's own buffer and once from takePending.
|
|
guard listening else { return true }
|
|
pending = nil
|
|
channel?.invokeMethod("open", arguments: type)
|
|
return true
|
|
}
|
|
}
|