Skip to content

Commit 249e6ef

Browse files
authored
feat(mac): add bulk Approve All / Reject All to the pairing approval panel (#104011)
* feat(mac): add bulk Approve All / Reject All to the pairing approval panel * fix(mac): resolve bulk pairing decisions against the rendered snapshot
1 parent 31703de commit 249e6ef

4 files changed

Lines changed: 209 additions & 38 deletions

File tree

‎apps/.i18n/native-source.json‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19899,87 +19899,103 @@
1989919899
},
1990019900
{
1990119901
"kind": "ui-call",
19902-
"line": 52,
19902+
"line": 59,
1990319903
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1990419904
"source": "Not Now",
1990519905
"surface": "apple",
1990619906
"id": "native.apple.048e9cc88fb7af55"
1990719907
},
19908+
{
19909+
"kind": "ui-call",
19910+
"line": 76,
19911+
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
19912+
"source": "Reject All",
19913+
"surface": "apple",
19914+
"id": "native.apple.4f271aca6df52a32"
19915+
},
19916+
{
19917+
"kind": "ui-call",
19918+
"line": 83,
19919+
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
19920+
"source": "Approve All",
19921+
"surface": "apple",
19922+
"id": "native.apple.bef7b0a91ca5c184"
19923+
},
1990819924
{
1990919925
"kind": "conditional-branch",
19910-
"line": 67,
19926+
"line": 103,
1991119927
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1991219928
"source": "Pairing Request",
1991319929
"surface": "apple",
1991419930
"id": "native.apple.57e27a9a3ef63ac4"
1991519931
},
1991619932
{
1991719933
"kind": "conditional-branch",
19918-
"line": 67,
19934+
"line": 103,
1991919935
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1992019936
"source": "Pairing Requests",
1992119937
"surface": "apple",
1992219938
"id": "native.apple.61152c2ea359eaa0"
1992319939
},
1992419940
{
1992519941
"kind": "ui-modifier",
19926-
"line": 176,
19942+
"line": 212,
1992719943
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1992819944
"source": "Copy full ID",
1992919945
"surface": "apple",
1993019946
"id": "native.apple.d3b539b5e822f581"
1993119947
},
1993219948
{
1993319949
"kind": "conditional-branch",
19934-
"line": 192,
19950+
"line": 227,
1993519951
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1993619952
"source": "Approve Device",
1993719953
"surface": "apple",
1993819954
"id": "native.apple.01bd6552a4adee7c"
1993919955
},
1994019956
{
1994119957
"kind": "conditional-branch",
19942-
"line": 192,
19958+
"line": 227,
1994319959
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1994419960
"source": "Approve Node",
1994519961
"surface": "apple",
1994619962
"id": "native.apple.b12ad4f00b1cd3d1"
1994719963
},
1994819964
{
1994919965
"kind": "ui-call",
19950-
"line": 214,
19966+
"line": 238,
1995119967
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1995219968
"source": "Reject",
1995319969
"surface": "apple",
1995419970
"id": "native.apple.8878bb60553ad307"
1995519971
},
1995619972
{
1995719973
"kind": "conditional-branch",
19958-
"line": 258,
19974+
"line": 295,
1995919975
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1996019976
"source": "A device wants to connect to OpenClaw.",
1996119977
"surface": "apple",
1996219978
"id": "native.apple.2e9d9d1f5d4346d4"
1996319979
},
1996419980
{
1996519981
"kind": "conditional-branch",
19966-
"line": 258,
19982+
"line": 295,
1996719983
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1996819984
"source": "A node wants to connect to OpenClaw.",
1996919985
"surface": "apple",
1997019986
"id": "native.apple.11b1b5e9dd510766"
1997119987
},
1997219988
{
1997319989
"kind": "conditional-branch",
19974-
"line": 269,
19990+
"line": 306,
1997519991
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1997619992
"source": "New device",
1997719993
"surface": "apple",
1997819994
"id": "native.apple.2412e85f7d11395e"
1997919995
},
1998019996
{
1998119997
"kind": "conditional-branch",
19982-
"line": 269,
19998+
"line": 306,
1998319999
"path": "apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift",
1998420000
"source": "OpenClaw Mac app",
1998520001
"surface": "apple",

‎apps/macos/Sources/OpenClaw/PairingApprovalCenter.swift‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ final class PairingApprovalCenter {
107107
}
108108
}
109109

110+
/// Resolve a batch of cards with one decision. Takes the caller's
111+
/// rendered snapshot instead of reading the live queue: a request that
112+
/// arrives between render and click must never be resolved unseen.
113+
/// `decide`'s in-flight guard keeps repeated clicks idempotent.
114+
func decideAll(_ cards: [Card], _ decision: Decision) {
115+
for card in cards {
116+
self.decide(card, decision)
117+
}
118+
}
119+
110120
/// "Not Now": hide the panel without resolving anything. Requests stay
111121
/// pending on the gateway (TTL applies) and in the menu-bar count.
112122
func snooze() {
@@ -161,6 +171,12 @@ final class PairingApprovalCenter {
161171
}
162172

163173
#if DEBUG
174+
/// Test seam: seed the live queue without presenting the panel (tests
175+
/// run without an NSApplication, so `updatePanel` must not fire).
176+
func _testSetCards(_ cards: [Card]) {
177+
self.cards = cards
178+
}
179+
164180
/// Demo/screenshot hook: decisions on injected cards resolve locally
165181
/// instead of routing to a prompter.
166182
private var demoRequestIds: Set<String> = []

‎apps/macos/Sources/OpenClaw/PairingApprovalPanelView.swift‎

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,51 @@ struct PairingApprovalPanelView: View {
4747
}
4848
}
4949
.scrollBounceBehavior(.basedOnSize)
50+
self.footer(cards: cards)
51+
}
52+
.padding(18)
53+
}
54+
55+
/// Single request keeps the minimal "Not Now" footer; multiple requests
56+
/// add one-click bulk actions so a queue never needs card-by-card clicks.
57+
@ViewBuilder
58+
private func footer(cards: [PairingApprovalCenter.Card]) -> some View {
59+
let notNow = Button("Not Now") { self.center.snooze() }
60+
.keyboardShortcut(.cancelAction)
61+
.buttonStyle(.plain)
62+
.foregroundStyle(.secondary)
63+
if cards.count > 1 {
64+
let allBusy = cards.allSatisfy { self.center.decisionsInFlight.contains($0.id) }
65+
HStack(spacing: 8) {
66+
notNow
67+
Spacer()
68+
// No keyboard shortcuts here: bulk approval is a security
69+
// decision and must never be a stray Return press. Both
70+
// actions resolve the rendered `cards` snapshot, never the
71+
// live queue, so a request that arrives mid-click cannot be
72+
// approved before it was ever displayed.
73+
Button(role: .destructive) {
74+
self.center.decideAll(cards, .reject)
75+
} label: {
76+
Text("Reject All")
77+
.padding(.horizontal, 6)
78+
}
79+
.pairingActionStyle(prominent: false)
80+
Button {
81+
self.center.decideAll(cards, .approve)
82+
} label: {
83+
Text("Approve All")
84+
.padding(.horizontal, 6)
85+
}
86+
.pairingActionStyle(prominent: true)
87+
}
88+
.disabled(allBusy)
89+
} else {
5090
HStack {
5191
Spacer()
52-
Button("Not Now") { self.center.snooze() }
53-
.keyboardShortcut(.cancelAction)
54-
.buttonStyle(.plain)
55-
.foregroundStyle(.secondary)
92+
notNow
5693
}
5794
}
58-
.padding(18)
5995
}
6096

6197
private func header(cards: [PairingApprovalCenter.Card]) -> some View {
@@ -184,44 +220,45 @@ struct PairingRequestCardView: View {
184220
.onHover { self.isHoveringDetail = $0 }
185221
}
186222

187-
@ViewBuilder
188223
private var approveButton: some View {
189-
let button = Button {
224+
Button {
190225
self.onDecision(.approve)
191226
} label: {
192227
Text(self.card.kind == .node ? "Approve Node" : "Approve Device")
193228
.padding(.horizontal, 6)
194229
}
195-
let shortcut: KeyboardShortcut? = self.isOnlyRequest ? .defaultAction : nil
196-
if #available(macOS 26.0, *) {
197-
button
198-
.buttonStyle(.glassProminent)
199-
.buttonBorderShape(.capsule)
200-
.keyboardShortcut(shortcut)
201-
} else {
202-
button
203-
.buttonStyle(.borderedProminent)
204-
.buttonBorderShape(.capsule)
205-
.keyboardShortcut(shortcut)
206-
}
230+
.pairingActionStyle(prominent: true)
231+
.keyboardShortcut(self.isOnlyRequest ? .defaultAction : nil)
207232
}
208233

209-
@ViewBuilder
210234
private var rejectButton: some View {
211-
let button = Button(role: .destructive) {
235+
Button(role: .destructive) {
212236
self.onDecision(.reject)
213237
} label: {
214238
Text("Reject")
215239
.padding(.horizontal, 6)
216240
}
241+
.pairingActionStyle(prominent: false)
242+
}
243+
}
244+
245+
extension View {
246+
/// Shared capsule styling for pairing decision buttons: Liquid Glass on
247+
/// macOS 26+, bordered fallback on macOS 15.
248+
@ViewBuilder
249+
func pairingActionStyle(prominent: Bool) -> some View {
217250
if #available(macOS 26.0, *) {
218-
button
219-
.buttonStyle(.glass)
220-
.buttonBorderShape(.capsule)
251+
if prominent {
252+
self.buttonStyle(.glassProminent).buttonBorderShape(.capsule)
253+
} else {
254+
self.buttonStyle(.glass).buttonBorderShape(.capsule)
255+
}
221256
} else {
222-
button
223-
.buttonStyle(.bordered)
224-
.buttonBorderShape(.capsule)
257+
if prominent {
258+
self.buttonStyle(.borderedProminent).buttonBorderShape(.capsule)
259+
} else {
260+
self.buttonStyle(.bordered).buttonBorderShape(.capsule)
261+
}
225262
}
226263
}
227264
}

‎apps/macos/Tests/OpenClawIPCTests/NodePairingApprovalPrompterTests.swift‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,105 @@ struct PairingCardPresentationTests {
238238
#expect(PairingApprovalCenter.shouldAutoPresent(cardIds: ["a", "b"], snoozedIds: ["a"]))
239239
}
240240
}
241+
242+
@MainActor
243+
struct PairingApprovalCenterBulkDecisionTests {
244+
@MainActor
245+
private final class DecisionRecorder {
246+
var decided: [String] = []
247+
248+
func record(_ kind: String, _ card: PairingApprovalCenter.Card, _ decision: PairingApprovalCenter.Decision) {
249+
self.decided.append("\(kind):\(card.requestId):\(decision == .approve ? "approve" : "reject")")
250+
}
251+
}
252+
253+
private func card(
254+
kind: PairingApprovalCenter.Kind,
255+
requestId: String) -> PairingApprovalCenter.Card
256+
{
257+
PairingApprovalCenter.Card(
258+
kind: kind,
259+
requestId: requestId,
260+
subjectId: "subject-\(requestId)",
261+
displayName: nil,
262+
platform: nil,
263+
deviceFamily: nil,
264+
modelIdentifier: nil,
265+
version: nil,
266+
coreVersion: nil,
267+
remoteIp: nil,
268+
role: nil,
269+
scopes: [],
270+
caps: [],
271+
commands: [],
272+
isRepair: false,
273+
previouslyPaired: false,
274+
requestedAt: Date(timeIntervalSince1970: 1_700_000_000))
275+
}
276+
277+
@Test func `decide all routes every card to its kind handler exactly once`() async {
278+
let center = PairingApprovalCenter()
279+
let recorder = DecisionRecorder()
280+
center.register(kind: .node) { recorder.record("node", $0, $1) }
281+
center.register(kind: .device) { recorder.record("device", $0, $1) }
282+
let rendered = [
283+
self.card(kind: .node, requestId: "req-1"),
284+
self.card(kind: .device, requestId: "req-2"),
285+
]
286+
287+
center.decideAll(rendered, .approve)
288+
#expect(center.decisionsInFlight == ["req-1", "req-2"])
289+
// A second bulk click while decisions are in flight must not re-fire.
290+
center.decideAll(rendered, .approve)
291+
292+
var attempts = 0
293+
while recorder.decided.count < 2 || !center.decisionsInFlight.isEmpty, attempts < 10_000 {
294+
attempts += 1
295+
await Task.yield()
296+
}
297+
#expect(recorder.decided.sorted() == ["device:req-2:approve", "node:req-1:approve"])
298+
#expect(center.decisionsInFlight.isEmpty)
299+
}
300+
301+
@Test func `reject all delivers reject to every handler`() async {
302+
let center = PairingApprovalCenter()
303+
let recorder = DecisionRecorder()
304+
center.register(kind: .device) { recorder.record("device", $0, $1) }
305+
let rendered = [
306+
self.card(kind: .device, requestId: "req-1"),
307+
self.card(kind: .device, requestId: "req-2"),
308+
]
309+
310+
center.decideAll(rendered, .reject)
311+
312+
var attempts = 0
313+
while recorder.decided.count < 2, attempts < 10_000 {
314+
attempts += 1
315+
await Task.yield()
316+
}
317+
#expect(recorder.decided.sorted() == ["device:req-1:reject", "device:req-2:reject"])
318+
}
319+
320+
@Test func `bulk decisions resolve only the rendered snapshot`() async {
321+
// Security invariant: a request that arrives after the footer was
322+
// rendered but before the click lands must never be resolved by the
323+
// stale bulk button — only what the user actually saw gets decided.
324+
let center = PairingApprovalCenter()
325+
let recorder = DecisionRecorder()
326+
center.register(kind: .node) { recorder.record("node", $0, $1) }
327+
center.register(kind: .device) { recorder.record("device", $0, $1) }
328+
let rendered = [self.card(kind: .node, requestId: "req-seen")]
329+
// "req-unseen" lands in the live queue after render, before the click.
330+
center._testSetCards(rendered + [self.card(kind: .device, requestId: "req-unseen")])
331+
332+
center.decideAll(rendered, .approve)
333+
334+
var attempts = 0
335+
while recorder.decided.isEmpty, attempts < 10_000 {
336+
attempts += 1
337+
await Task.yield()
338+
}
339+
#expect(recorder.decided == ["node:req-seen:approve"])
340+
#expect(!center.decisionsInFlight.contains("req-unseen"))
341+
}
342+
}

0 commit comments

Comments
 (0)