Skip to content

Commit 662c113

Browse files
fix(macos): keep the talk overlay visible when a present interrupts its dismissal
dismiss started a 160ms fade and left isVisible true until the completion. a present arriving inside that window therefore saw the panel as already visible, took the branch that only moves and orders it front, and did not bring the alpha back. the old completion then ran and hid the panel anyway so talk could stay enabled with nothing on screen, which is the sequence in the report, present dismiss present then the old completion visibility is now given up when dismiss starts, so a present during the fade takes the first present path and animates the panel back in itself. each dismissal carries a transition id and its completion only hides the panel if it still owns it. the already visible path restores alpha as well this follows quick chat, which rotates a transitionID and checks it in its dismissal completion, and the decision is a pure function so it can be tested the way VoiceWakeOverlayController.evaluateToken is
1 parent 651c1ec commit 662c113

2 files changed

Lines changed: 86 additions & 2 deletions

File tree

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,25 @@ final class TalkOverlayController {
2424
private var window: NSPanel?
2525
private var hostingView: NSHostingView<TalkOverlayView>?
2626
private let screenInset: CGFloat = 0
27+
/// Identifies the desired visibility currently being animated towards. Rotating it on every
28+
/// present and dismiss lets a completion tell whether it still owns the panel.
29+
@ObservationIgnored private var transitionID = UUID()
30+
31+
/// What a finished dismissal animation should do, given the transition it started for.
32+
enum DismissalOutcome: Equatable {
33+
/// Still the newest intent, so the panel goes away.
34+
case hide
35+
/// A newer present replaced it mid-fade and now owns the panel.
36+
case superseded
37+
}
38+
39+
static func evaluateDismissal(current: UUID, dismissal: UUID) -> DismissalOutcome {
40+
current == dismissal ? .hide : .superseded
41+
}
2742

2843
func present() {
2944
self.ensureWindow()
45+
self.transitionID = UUID()
3046
self.hostingView?.rootView = TalkOverlayView(controller: self)
3147
let target = self.targetFrame()
3248
let isFirst = !self.model.isVisible
@@ -36,6 +52,9 @@ final class TalkOverlayController {
3652
isFirstPresent: isFirst,
3753
target: target)
3854
{ window in
55+
// A dismissal that this present superseded may have faded the panel partway out,
56+
// and this path does not animate it back in the way a first present does.
57+
window.alphaValue = 1
3958
window.setFrame(target, display: true)
4059
window.orderFrontRegardless()
4160
}
@@ -47,10 +66,24 @@ final class TalkOverlayController {
4766
return
4867
}
4968

50-
OverlayPanelFactory.animateDismiss(window: window) {
69+
// Give up visibility now rather than when the fade ends, so a present arriving during
70+
// the animation takes the first-present path and animates the panel back in itself.
71+
self.model.isVisible = false
72+
let dismissalID = UUID()
73+
self.transitionID = dismissalID
74+
75+
OverlayPanelFactory.animateDismiss(window: window) { [weak self] in
5176
Task { @MainActor in
77+
guard let self else { return }
78+
guard Self.evaluateDismissal(
79+
current: self.transitionID,
80+
dismissal: dismissalID) == .hide
81+
else {
82+
// A newer present owns the panel. Hiding it here is what left Talk enabled
83+
// with nothing on screen.
84+
return
85+
}
5286
window.orderOut(nil)
53-
self.model.isVisible = false
5487
}
5588
}
5689
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Foundation
2+
import Testing
3+
@testable import OpenClaw
4+
5+
@Suite(.serialized)
6+
@MainActor
7+
struct TalkOverlayDismissalTests {
8+
@Test func `a dismissal completion hides only for the transition it started for`() {
9+
let dismissal = UUID()
10+
11+
// Nothing interrupted the fade, so the panel goes away as asked.
12+
#expect(
13+
TalkOverlayController.evaluateDismissal(current: dismissal, dismissal: dismissal)
14+
== .hide)
15+
16+
// present() rotates the id. The completion from the fade it interrupted must not hide
17+
// the panel that present now owns, which is what left Talk enabled with nothing shown.
18+
#expect(
19+
TalkOverlayController.evaluateDismissal(current: UUID(), dismissal: dismissal)
20+
== .superseded)
21+
}
22+
23+
@Test func `each dismissal is judged against its own transition`() {
24+
// present -> dismiss -> present -> dismiss, and the first completion arrives last.
25+
let first = UUID()
26+
let second = UUID()
27+
28+
#expect(TalkOverlayController.evaluateDismissal(current: second, dismissal: first)
29+
== .superseded)
30+
#expect(TalkOverlayController.evaluateDismissal(current: second, dismissal: second)
31+
== .hide)
32+
}
33+
34+
@Test func `a present during the dismissal fade survives the old completion`() async {
35+
// The reported sequence: present -> dismiss -> present -> old dismissal completion.
36+
// The last present must still own the panel once the interrupted fade finishes.
37+
let controller = TalkOverlayController()
38+
39+
controller.present()
40+
#expect(controller.model.isVisible == true)
41+
42+
controller.dismiss()
43+
controller.present()
44+
#expect(controller.model.isVisible == true)
45+
46+
// Outlast the 160 ms dismissal animation so its completion has run.
47+
try? await Task.sleep(nanoseconds: 400_000_000)
48+
49+
#expect(controller.model.isVisible == true)
50+
}
51+
}

0 commit comments

Comments
 (0)