forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingControlBarView.swift
More file actions
3214 lines (2994 loc) · 113 KB
/
Copy pathFloatingControlBarView.swift
File metadata and controls
3214 lines (2994 loc) · 113 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import AppKit
import Combine
import OmiSupport
import OmiTheme
import SwiftUI
import UniformTypeIdentifiers
enum ShortcutHintLayout {
static func visibleTokens(for keys: [String]) -> [String] {
keys
}
}
/// A chat surface replaces the compact notch waveform, so recording must keep
/// its own visible projection while the conversation is open. This is derived
/// entirely from reducer-owned presentation state; it does not create another
/// PTT lifecycle owner.
enum FloatingChatPTTOverlayPolicy {
static func shouldShow(
showingAIConversation: Bool,
isVoiceListening: Bool
) -> Bool {
showingAIConversation && isVoiceListening
}
}
/// Routes an idle notch click through the main chat's sole window authority.
/// Voice and an already-presented floating conversation own their respective
/// surfaces and must not be displaced by a late notch click.
enum NotchIdleTapRoute {
static func perform(
isVoicePresentationActive: Bool,
isShowingConversation: Bool,
openMainChat: () -> Void
) {
guard !isVoicePresentationActive, !isShowingConversation else { return }
openMainChat()
}
}
enum NotchChromeLayout {
/// A chat can be restoring or transitioning while the rendered conversation
/// is already visible. Both states must keep the notch controls pinned;
/// otherwise the notch controls jump out to the surface edges for
/// a frame during expansion.
static func isChatPinned(
showingAIConversation: Bool,
hasVisibleConversation: Bool
) -> Bool {
showingAIConversation || hasVisibleConversation
}
/// The hover menu and chat surface can grow much wider than the physical
/// notch. Keep the controls in the notch-width header for the entire
/// lifecycle so expansion never moves either control away from its
/// collapsed position.
static func width(
chromeWidth: CGFloat,
expandedWidth: CGFloat,
switcherProgress: CGFloat,
isChatPresented: Bool
) -> CGFloat {
// The expanded surface owns the extra width. The header must remain a
// stable physical-notch anchor whether the row is opening, closing, or
// transitioning into/restoring chat. Keep the parameters at this seam
// so tests cover every caller state without duplicating layout policy.
_ = expandedWidth
_ = switcherProgress
_ = isChatPresented
return chromeWidth
}
}
/// Main floating control bar SwiftUI view composing all sub-views.
struct FloatingControlBarView: View {
@EnvironmentObject var state: FloatingControlBarState
@ObservedObject private var shortcutSettings = ShortcutSettings.shared
@ObservedObject private var agentPills = AgentPillsManager.shared
weak var window: NSWindow?
var onPlayPause: () -> Void
var onTogglePushToTalk: () -> Void
var onAskAI: () -> Void
var onHide: () -> Void
var onSendQuery: (String) -> Void
var onCloseAI: () -> Void
var onEscape: () -> Void
var onClearVisibleConversation: () -> Void
var onRate: ((String, Int?, ChatFeedbackReason?) -> Void)?
var onShareLink: (() async -> String?)?
@State private var isHovering = false
@State private var onboardingGlowOn = false
@State private var notchLogoHovering = false
@State private var agentSwitcherCollapseWorkItem: DispatchWorkItem?
/// 0 = hover rows hidden, 1 = hover rows revealed below the fixed header.
@State private var notchSwitcherProgress: CGFloat = 0
/// Last reported text-editor height so inputViewHeight can be recomputed
/// when the pill list changes while the input is open. (Cubic P2.)
private let agentChatSwitchTransition = Animation.easeOut(duration: 0.10)
private var isChatChromePinned: Bool {
NotchChromeLayout.isChatPinned(
showingAIConversation: state.showingAIConversation,
hasVisibleConversation: state.hasVisibleConversation
)
}
private var notchHiddenCenterWidth: CGFloat {
// Without a physical notch there is no dead zone to straddle — keep a
// small deliberate gap between the lobes instead of the phantom one.
state.usesNotchIsland
? FloatingControlBarWindow.notchHiddenCenterWidth(for: window?.screen ?? NSScreen.main)
: FloatingControlBarWindow.pillSurfaceCenterGapWidth
}
private var notchSideWidth: CGFloat {
if showingNotchVoiceControl {
return NotchVoiceControlPresentation.activeSideWidth
}
if isChatChromePinned {
return agentPills.pills.isEmpty
? FloatingControlBarWindow.notchCompactSideWidth
: FloatingControlBarWindow.notchActiveSideWidth
}
if showingNotchThinking {
return FloatingControlBarWindow.notchThinkingSideWidth
}
if agentPills.pills.isEmpty && !state.isVoiceListening {
return FloatingControlBarWindow.notchCompactSideWidth
}
return FloatingControlBarWindow.notchActiveSideWidth
}
private var notchChromeWidth: CGFloat {
notchHiddenCenterWidth + notchSideWidth * 2
}
private var notchChromeLayoutWidth: CGFloat {
isChatChromePinned || shouldShowNotchHoverMenu
? max(notchChromeWidth, FloatingControlBarWindow.notchExpandedWidth)
: notchChromeWidth
}
/// The surface can morph below it, but chrome always keeps the compact
/// notch-width header so its controls do not drift.
private var notchChromeMorphWidth: CGFloat {
NotchChromeLayout.width(
chromeWidth: notchChromeWidth,
expandedWidth: FloatingControlBarWindow.notchExpandedWidth,
switcherProgress: notchSwitcherProgress,
isChatPresented: isChatChromePinned
)
}
private var notchSurfaceHorizontalInset: CGFloat {
state.usesNotchIsland ? FloatingControlBarWindow.notchGlowOutsetX : 0
}
private var notchSurfaceBottomInset: CGFloat {
state.usesNotchIsland ? FloatingControlBarWindow.notchGlowOutsetBottom : 0
}
private var notchHoverMenuHeight: CGFloat {
FloatingControlBarWindow.notchHoverMenuHeight(agentCount: agentPills.pills.count)
}
private var notchHoverRowWidth: CGFloat {
max(
0,
min(
notchChromeLayoutWidth - NotchAgentStackMetrics.listHorizontalInset * 2,
FloatingControlBarWindow.notchExpandedWidth - NotchAgentStackMetrics.listHorizontalInset * 2
)
)
}
var body: some View {
Group {
if state.usesNotchIsland || state.showingAIConversation || state.isNotchHoverMenuVisible {
unifiedFloatingSurface
} else {
VStack(spacing: state.isShowingNotification && !state.showingAIConversation ? 8 : 0) {
barChrome
if let notification = state.currentNotification, !state.showingAIConversation {
barNotification(notification)
.floatingBackground(cornerRadius: 18)
.padding(.horizontal, OmiSpacing.sm)
.padding(.bottom, OmiSpacing.sm)
.transition(.move(edge: .top).combined(with: .opacity))
}
}
}
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: state.usesNotchIsland || state.showingAIConversation || state.isNotchHoverMenuVisible
? .top : .center
)
.background(Color.clear)
.omiAnimation(.spring(response: 0.35, dampingFraction: 0.82), value: state.currentNotification?.id)
// Placed on the always-mounted root (not inside unifiedFloatingSurface) so
// the pill→island morph still fires when transitioning out of the idle pill.
.onChange(of: activeLifecycleKey) { _, _ in
(window as? FloatingControlBarWindow)?.syncActiveIsland()
}
}
/// Composite key for the active PTT lifecycle — any change drives the
/// pill ↔ notch-island morph (see FloatingControlBarWindow.syncActiveIsland).
private var activeLifecycleKey: String {
"\(state.isVoiceListening)-\(state.isVoiceLocked)-\(state.isThinking)-\(state.isVoiceResponseGlowActive)"
}
/// Whether the bar chrome should stretch to fill the window width
private var barNeedsFullWidth: Bool {
isHovering || state.isVoiceListening
}
private var shouldShowNotchHoverMenu: Bool {
state.isNotchHoverMenuVisible
&& NotchAgentMenuPresentation.shouldPresent(agentCount: agentPills.pills.count)
}
private var showingNotchWaveform: Bool {
state.voiceProjection.isListening
}
/// The trailing notch lobe becomes the visible stop/send action while a
/// voice turn is capturing. A failure hint keeps its dedicated status
/// treatment instead of suggesting that a finished turn can be sent.
private var showingNotchVoiceControl: Bool {
state.voiceProjection.isListening
}
/// The notch "thinking" state: a PTT query is committed and being processed,
/// with no live listening or open conversation surface. Shows the spinning
/// Omi mark in the left notch lobe (chat already has its own loading UI).
private var showingNotchThinking: Bool {
(state.isThinking || state.isVoiceResponseWaiting)
&& !state.showingAIConversation
&& !state.isVoiceListening
}
private var showingPTTStatusBanner: Bool {
!state.pttHintText.isEmpty
}
/// The notch "speaking" state: response audio is playing (or draining), so
/// the resting ring pulses like a speaker instead of sitting static.
private var showingNotchSpeaking: Bool {
state.isVoiceResponseGlowActive && !state.isVoiceListening
}
private var unifiedFloatingSurface: some View {
VStack(spacing: 0) {
if state.usesNotchIsland || state.showingAIConversation {
notchChrome
} else {
// No camera housing to blend into — the pill surface starts
// with a slim top inset instead of the notch chrome band.
Color.clear
.frame(height: FloatingControlBarWindow.pillSurfaceTopPadding)
}
if showingPTTStatusBanner {
pttStatusBanner
.frame(height: FloatingControlBarWindow.pttHintRowHeight)
.padding(.horizontal, OmiSpacing.md)
.padding(.bottom, OmiSpacing.xs)
.transition(.opacity)
}
if shouldShowNotchHoverMenu {
if state.usesNotchIsland {
Color.clear
.frame(width: notchChromeLayoutWidth, height: notchHoverMenuHeight, alignment: .top)
.onHover { setAgentSwitcherHovering($0) }
.transition(.identity)
} else {
pillAgentListMenu
}
}
if state.showingAIConversation {
conversationView
.padding(.horizontal, OmiSpacing.md)
.padding(.top, 0)
.padding(.bottom, FloatingControlBarWindow.notchConversationBottomPadding)
.transition(.opacity)
}
if let notification = state.currentNotification, !state.showingAIConversation {
barNotification(notification)
.padding(.horizontal, 10)
.padding(.bottom, 10)
.transition(.move(edge: .top).combined(with: .opacity))
}
}
.overlay(alignment: .top) {
if state.usesNotchIsland && shouldShowNotchHoverMenu {
ZStack(alignment: .top) {
NotchAgentMorphField(
manager: agentPills,
activePillID: state.activeAgentChatPillID,
progress: notchSwitcherProgress,
notchHiddenCenterWidth: notchHiddenCenterWidth,
notchSideWidth: notchSideWidth,
notchChromeHeight: notchChromeHeight,
rowTopOffset: 0,
onSelect: openAgentInChat
)
.frame(width: notchChromeLayoutWidth, height: notchChromeHeight + notchHoverMenuHeight)
.allowsHitTesting(notchSwitcherProgress > 0.6)
// Shortcut legend + capture controls, hugging the trailing edge of the
// expanded surface — the notch's right side, revealed on hover.
VStack {
NotchSystemControlsView(progress: notchSwitcherProgress)
.padding(
.top,
notchChromeHeight
+ FloatingControlBarWindow.notchControlPanelTopOffset(agentCount: agentPills.pills.count)
+ OmiSpacing.xs
)
.padding(.trailing, OmiSpacing.md)
Spacer(minLength: 0)
}
.frame(
width: notchChromeLayoutWidth,
height: notchChromeHeight + notchHoverMenuHeight,
alignment: .topTrailing
)
notchAgentLogoHitTarget
.frame(width: notchChromeLayoutWidth, height: notchChromeHeight)
}
.frame(width: notchChromeLayoutWidth, height: notchChromeHeight + notchHoverMenuHeight)
.onHover { setAgentSwitcherHovering($0) }
}
}
.onAppear { notchSwitcherProgress = shouldShowNotchHoverMenu ? 1 : 0 }
.padding(.horizontal, notchSurfaceHorizontalInset)
.padding(.bottom, notchSurfaceBottomInset)
.background(alignment: .top) {
GeometryReader { geometry in
let bottomRadius: CGFloat = state.showingAIConversation || state.currentNotification != nil ? 22 : 18
let surfaceSize = floatingSurfaceSize(geometry: geometry)
let surfaceWidth = surfaceSize.width
let surfaceHeight = surfaceSize.height
ZStack(alignment: .top) {
NotchDockShape(
bottomRadius: bottomRadius,
topRadius: state.usesNotchIsland ? 0 : 14
)
.fill(Color.black)
.frame(width: surfaceWidth, height: surfaceHeight)
if state.isVoiceResponseGlowActive {
NotchResponseGlowView(
bottomRadius: bottomRadius,
topRadius: state.usesNotchIsland ? 0 : 14,
edgeInset: state.usesNotchIsland ? 0 : 3
)
.frame(width: surfaceWidth, height: surfaceHeight)
}
// Onboarding: a plain white glow on the bar edge so first-run
// users notice it — no animated sweep. Reuses the voice glow's
// shape and ramps in 1s after the bar appears. Clears the
// moment they start typing.
if state.onboardingBarGlow && state.aiInputText.isEmpty {
NotchLowerEdgeShape(
bottomRadius: bottomRadius,
topRadius: state.usesNotchIsland ? 0 : 14,
edgeInset: state.usesNotchIsland ? 0 : 3
)
.stroke(
Color.white,
style: StrokeStyle(lineWidth: 3.2, lineCap: .round, lineJoin: .round)
)
.frame(width: surfaceWidth, height: surfaceHeight)
.shadow(color: Color.white.opacity(0.85), radius: 12)
.shadow(color: Color.white.opacity(0.5), radius: 22)
.opacity(onboardingGlowOn ? 1 : 0)
.allowsHitTesting(false)
.task {
// Signal-driven (cancels on disappear) instead of asyncAfter:
// hold the bar un-glowed for a beat, then ease the glow in.
onboardingGlowOn = false
try? await Task.sleep(for: .seconds(1))
guard !Task.isCancelled else { return }
OmiMotion.withGated(.easeIn(duration: 0.7)) {
onboardingGlowOn = true
}
}
.onDisappear { onboardingGlowOn = false }
}
}
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .top)
}
}
.overlay(alignment: .bottomTrailing) {
if state.showingAIConversation {
ZStack {
ResizeHandleView(targetWindow: window)
.frame(width: 20, height: 20)
ResizeGripShape()
.foregroundStyle(.white.opacity(0.3))
.frame(width: 14, height: 14)
.allowsHitTesting(false)
}
.padding(.trailing, notchSurfaceHorizontalInset + 4)
.padding(.bottom, notchSurfaceBottomInset + 4)
}
}
.overlay(alignment: .bottom) {
if FloatingChatPTTOverlayPolicy.shouldShow(
showingAIConversation: state.showingAIConversation,
isVoiceListening: state.isVoiceListening
) {
// `conversationView` replaces the normal notch waveform while
// chat is open. Keep the recording/hint projection visible at
// the bottom of that same surface instead of hiding PTT state.
voiceListeningView
.padding(.horizontal, OmiSpacing.md)
.frame(height: 42)
.background(Capsule().fill(Color.white.opacity(0.12)))
.overlay(Capsule().stroke(Color.white.opacity(0.15), lineWidth: 1))
.padding(.horizontal, notchSurfaceHorizontalInset + OmiSpacing.md)
.padding(.bottom, notchSurfaceBottomInset + 8)
.accessibilityIdentifier("floating_chat_ptt_recording")
.accessibilityLabel(
state.pttHintText.isEmpty ? "Recording voice message" : state.pttHintText
)
.allowsHitTesting(false)
.transition(.move(edge: .bottom).combined(with: .opacity))
}
}
.scaleEffect(
x: max(0.001, state.notchRevealProgress),
y: max(0.001, state.notchRevealProgress),
anchor: .top
)
.opacity(min(1, max(0, state.notchRevealProgress * 1.4)))
.contentShape(Rectangle())
.contextMenu { barContextMenu }
.onHover(perform: handleBarHover)
.onChange(of: shouldShowNotchHoverMenu) { _, visible in
if state.isVoicePresentationActive {
// A PTT transition replaces the idle hover surface with a separately sized panel. Do not
// let an in-flight hover spring keep changing the black surface after voice takes over.
var transaction = Transaction()
transaction.animation = nil
withTransaction(transaction) {
notchSwitcherProgress = 0
}
return
}
// SwiftUI carries the visible morph. The panel expands before the content
// and collapses only when this animation reports that it has settled.
let morphAnim: Animation =
visible
? FloatingControlBarWindow.notchHoverMenuExpandAnimation
: FloatingControlBarWindow.notchHoverMenuCollapseAnimation
withAnimation(OmiMotion.gated(morphAnim), completionCriteria: .logicallyComplete) {
notchSwitcherProgress = visible ? 1 : 0
} completion: {
guard !visible, !state.isNotchHoverMenuVisible else { return }
(window as? FloatingControlBarWindow)?.settleNotchAgentSwitcherCollapse()
}
}
.onChange(of: state.isVoicePresentationActive) { _, active in
guard active else { return }
// These view-local values otherwise remain true until pointer exit and can paint stale
// hover chrome over the voice presentation.
var transaction = Transaction()
transaction.animation = nil
withTransaction(transaction) {
isHovering = false
notchLogoHovering = false
notchSwitcherProgress = 0
}
}
.onChange(of: state.showingAIConversation) { _, isShowing in
guard state.usesNotchIsland, !isShowing, shouldShowNotchHoverMenu else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.08) {
guard shouldShowNotchHoverMenu else { return }
(window as? FloatingControlBarWindow)?.resizeForAgentSwitcher(visible: true)
}
}
.onChange(of: agentPills.pills.isEmpty) { _, isEmpty in
if isEmpty {
state.agentSwitcherPinned = false
state.agentSwitcherHovering = false
state.setNotchHoverMenuOpen(false)
notchLogoHovering = false
(window as? FloatingControlBarWindow)?.setPillAgentListVisible(false)
}
}
.onDisappear { state.setNotchHoverMenuOpen(false) }
}
/// Size of the visible black surface behind the floating content.
/// Notch hover follows the content morph while AppKit snaps at its boundaries.
private func floatingSurfaceSize(geometry: GeometryProxy) -> CGSize {
let notchHoverLifecycle = NotchHoverSurfacePolicy.usesAnimatedHoverSurface(
usesNotchIsland: state.usesNotchIsland,
showingAIConversation: state.showingAIConversation,
isVoicePresentationActive: state.isVoicePresentationActive,
isShowingNotification: state.isShowingNotification)
if notchHoverLifecycle {
let openWidth = max(notchChromeWidth, FloatingControlBarWindow.notchExpandedWidth)
return CGSize(
width: notchChromeWidth + (openWidth - notchChromeWidth) * notchSwitcherProgress,
height: notchChromeHeight + notchHoverMenuHeight * notchSwitcherProgress
)
}
let hasExpandedSurface =
state.showingAIConversation
|| state.currentNotification != nil
|| shouldShowNotchHoverMenu
|| showingPTTStatusBanner
guard hasExpandedSurface else {
return CGSize(width: notchChromeWidth, height: notchChromeHeight)
}
return CGSize(
width: max(notchChromeWidth, geometry.size.width - notchSurfaceHorizontalInset * 2),
height: max(notchChromeHeight, geometry.size.height - notchSurfaceBottomInset)
)
}
private var notchChrome: some View {
ZStack {
HStack(spacing: 0) {
notchAgentLobe
.frame(width: notchSideWidth, height: notchChromeHeight)
Spacer(minLength: notchHiddenCenterWidth)
notchControlLobe
.frame(width: notchSideWidth, height: notchChromeHeight)
}
Color.clear
.frame(width: notchHiddenCenterWidth, height: notchChromeHeight)
.allowsHitTesting(false)
}
.frame(height: notchChromeHeight)
.frame(width: notchChromeMorphWidth)
}
private var notchAgentLobe: some View {
HStack(spacing: 0) {
ZStack(alignment: .trailing) {
// One always-mounted identity mark owns idle, PTT, and thinking
// presentation. The reducer still owns the voice lifecycle; this view
// only morphs its read-only projection at the mark's existing position.
NotchAgentPillsRowView(
manager: agentPills,
barWindow: window,
isVoiceListening: showingNotchWaveform,
isThinking: showingNotchThinking,
isSpeaking: showingNotchSpeaking,
isDictating: state.isVoiceDictating,
isLocked: state.isVoiceLocked
)
.scaleEffect(notchLogoHovering ? 1.06 : 1.0)
}
.frame(width: notchSideWidth, height: notchChromeHeight, alignment: .trailing)
.padding(.trailing, OmiSpacing.hairline)
.contentShape(Rectangle())
.onHover { hovering in
guard !state.isVoicePresentationActive else { return }
setNotchLogoHovering(hovering)
}
.onTapGesture {
guard !state.isVoicePresentationActive else { return }
openAgentChatsFromNotchLogo()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
}
/// Picks the actionable "Couldn't reach Omi" card for reach errors, else the
/// normal notification card.
private enum JITFeedbackPresentation {
case planned(JITTriggerFeedbackContext)
case ambient(JITAmbientFeedbackContext)
}
@ViewBuilder
private func barNotification(_ notification: FloatingBarNotification) -> some View {
if let feedbackContext = notification.jitFeedbackContext {
jitFeedbackCard(notification, presentation: .planned(feedbackContext))
} else if let ambientFeedbackContext = notification.jitAmbientFeedbackContext {
jitFeedbackCard(notification, presentation: .ambient(ambientFeedbackContext))
} else if notification.assistantId == "reach_error" {
reachErrorCard(notification)
} else if notification.assistantId == NotchMoment.receiptAssistantId {
notchReceiptCard(notification)
} else if notification.assistantId == NotchMoment.endAssistantId {
notchEndCard(notification)
} else if notification.assistantId == MeetingActionItemBannerPolicy.assistantID,
case .meetingSummaryShare(let conversationID, let recipients)? = notification.action
{
MeetingSummaryShareCard(
notification: notification, conversationID: conversationID, recipients: recipients)
} else if notification.assistantId == "suggestion" {
suggestionCard(notification)
} else if notification.assistantId == IntegrationNudgeCoordinator.assistantID,
case .connectIntegration(let telemetryID, let triggerID)? = notification.action,
let entry = IntegrationNudgeCatalog.entry(telemetryID: telemetryID)
{
IntegrationNudgeCard(notification: notification, entry: entry, triggerID: triggerID)
} else if notification.assistantId == FirstRealAppCardCoordinator.assistantID,
case .askOmiPrefilled(let prompt)? = notification.action
{
FirstRealAppCard(notification: notification, prompt: prompt)
} else if notification.assistantId == ContextReminderCoordinator.assistantID,
case .contextReminder(let reminderID)? = notification.action
{
ContextReminderCard(notification: notification, reminderID: reminderID)
} else {
notificationView(notification)
}
}
/// Concrete, explicit-only controls for a planned trigger. Each action is
/// submitted through the delivery actor; dismissing or ignoring the card
/// never calls this path.
private func jitFeedbackCard(
_ notification: FloatingBarNotification,
presentation: JITFeedbackPresentation
) -> some View {
VStack(alignment: .leading, spacing: OmiSpacing.sm) {
Button {
FloatingControlBarManager.shared.openNotificationAsChat(notification)
} label: {
HStack(alignment: .top, spacing: OmiSpacing.md) {
Image(systemName: "bell.badge.fill")
.font(.system(size: 18, weight: .semibold))
.foregroundColor(.white)
.frame(width: 44, height: 44)
.background(Color.white.opacity(0.12))
.clipShape(RoundedRectangle(cornerRadius: 13, style: .continuous))
VStack(alignment: .leading, spacing: 3) {
Text(notification.title)
.scaledFont(size: OmiType.subheading, weight: .semibold)
.foregroundColor(.white)
.lineLimit(1)
Text(notification.message)
.scaledFont(size: OmiType.body)
.foregroundColor(.white.opacity(0.78))
.lineLimit(3)
.multilineTextAlignment(.leading)
if InterjectFeature.isEnabled {
Text(InterjectReplyHint.text(tokens: ShortcutSettings.shared.pttShortcut.displayTokens))
.scaledFont(size: OmiType.micro, weight: .medium)
.foregroundColor(.white.opacity(0.45))
.lineLimit(1)
}
}
Spacer(minLength: 0)
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
HStack(spacing: OmiSpacing.xs) {
jitFeedbackButton("Useful", systemImage: "hand.thumbsup.fill") {
submitJITFeedback(.useful, notification: notification, presentation: presentation)
}
jitFeedbackButton("Not relevant", systemImage: "hand.thumbsdown.fill") {
submitJITFeedback(.falsePositive, notification: notification, presentation: presentation)
}
if case .planned = presentation {
jitFeedbackButton("Snooze", systemImage: "zzz") {
submitJITFeedback(
.snooze, notification: notification, presentation: presentation,
snoozedUntil: Date().addingTimeInterval(24 * 60 * 60))
}
jitFeedbackButton("Disable", systemImage: "bell.slash.fill") {
submitJITFeedback(.disable, notification: notification, presentation: presentation)
}
jitFeedbackButton("Missed", systemImage: "clock.badge.exclamationmark") {
submitJITFeedback(.missedOrLate, notification: notification, presentation: presentation)
}
}
}
}
.padding(.horizontal, OmiSpacing.lg)
.padding(.vertical, OmiSpacing.md + 2)
.overlay(alignment: .topTrailing) {
Button {
FloatingControlBarManager.shared.dismissCurrentNotification()
} label: {
Image(systemName: "xmark")
.font(.system(size: 10, weight: .bold))
.foregroundColor(.white.opacity(0.62))
.frame(width: 18, height: 18)
.background(Color.white.opacity(0.08))
.clipShape(Circle())
}
.buttonStyle(.plain)
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.md)
.accessibilityLabel("Dismiss notification")
}
}
private func jitFeedbackButton(
_ title: String,
systemImage: String,
action: @escaping () -> Void
) -> some View {
Button(action: action) {
Label(title, systemImage: systemImage)
.scaledFont(size: OmiType.micro, weight: .semibold)
.foregroundColor(.white.opacity(0.9))
.padding(.horizontal, OmiSpacing.xs)
.padding(.vertical, OmiSpacing.xxs)
.background(Color.white.opacity(0.12))
.clipShape(Capsule())
}
.buttonStyle(.plain)
}
private func submitJITFeedback(
_ action: JITTriggerFeedbackAction,
notification: FloatingBarNotification,
presentation: JITFeedbackPresentation,
snoozedUntil: Date? = nil
) {
let ownerID: String
switch presentation {
case .planned(let context): ownerID = context.ownerID
case .ambient(let context): ownerID = context.ownerID
}
guard
let authorizationSnapshot = RuntimeOwnerIdentity.captureAuthorizationSnapshot(
expectedOwnerID: ownerID
)
else { return }
let accountGeneration = AccountCutoverControlManager.shared.control.accountGeneration
let notificationID = notification.id
Task {
switch presentation {
case .planned(let context):
await FloatingControlBarManager.shared.recordInterjectJITVerdictIfEnabled(
identity: notification.feedbackIdentity,
verb: action.interjectVerb)
await JITTriggerFeedbackActionRouter.record(
action,
context: context,
snoozedUntil: snoozedUntil,
authorizationSnapshot: authorizationSnapshot)
case .ambient(let context):
await JITAmbientFeedbackActionRouter.record(
action,
context: context,
authorizationSnapshot: authorizationSnapshot,
currentAccountGeneration: accountGeneration,
presentationCurrent: {
FloatingControlBarManager.shared.isCurrentNotification(notificationID)
})
}
await MainActor.run {
guard FloatingControlBarManager.shared.isCurrentNotification(notificationID) else { return }
FloatingControlBarManager.shared.dismissCurrentNotification()
}
}
}
/// Live proactive suggestion. Monochrome and quiet by design — this card interrupts
/// unprompted, so it earns attention with the sentence, not with chrome.
private func suggestionCard(_ notification: FloatingBarNotification) -> some View {
Button {
FloatingControlBarManager.shared.openNotificationAsChat(notification)
} label: {
HStack(alignment: .top, spacing: OmiSpacing.md) {
ZStack {
RoundedRectangle(cornerRadius: 13, style: .continuous)
.fill(
LinearGradient(
colors: [Color.white.opacity(0.18), Color.white.opacity(0.08)],
startPoint: .top,
endPoint: .bottom
)
)
.overlay(
RoundedRectangle(cornerRadius: 13, style: .continuous)
.strokeBorder(Color.white.opacity(0.12), lineWidth: 1)
)
.frame(width: 44, height: 44)
Image(systemName: "lightbulb.fill")
.font(.system(size: 17, weight: .semibold))
.foregroundColor(.white)
}
VStack(alignment: .leading, spacing: 3) {
Text("Suggested by Omi")
.scaledFont(size: OmiType.caption, weight: .semibold)
.foregroundColor(.white.opacity(0.5))
.lineLimit(1)
Text(notification.message)
.scaledFont(size: OmiType.subheading, weight: .medium)
.foregroundColor(.white)
.lineLimit(3)
.multilineTextAlignment(.leading)
.lineSpacing(1.5)
.fixedSize(horizontal: false, vertical: true)
if InterjectFeature.isEnabled {
Text(InterjectReplyHint.text(tokens: ShortcutSettings.shared.pttShortcut.displayTokens))
.scaledFont(size: OmiType.micro, weight: .medium)
.foregroundColor(.white.opacity(0.45))
.lineLimit(1)
}
}
Spacer(minLength: OmiSpacing.xs)
// Reserve room so copy never runs under the overlaid dismiss button.
Color.clear
.frame(width: 28, height: 20)
}
.padding(.horizontal, OmiSpacing.lg)
.padding(.vertical, OmiSpacing.md + 2)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.overlay(alignment: .topTrailing) {
Button {
FloatingControlBarManager.shared.dismissCurrentNotification()
} label: {
Image(systemName: "xmark")
.font(.system(size: 10, weight: .bold))
.foregroundColor(.white.opacity(0.62))
.frame(width: 18, height: 18)
.background(Color.white.opacity(0.08))
.clipShape(Circle())
}
.buttonStyle(.plain)
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.md)
.accessibilityLabel("Dismiss suggestion")
}
}
/// Conversation ends — the USP moment. "N follow-ups ready" + Review / Later.
private func notchEndCard(_ notification: FloatingBarNotification) -> some View {
VStack(alignment: .leading, spacing: 2) {
if !notification.message.isEmpty {
Text(notification.message)
.scaledFont(size: 11)
.foregroundColor(.white.opacity(0.55))
.lineLimit(1)
}
Text(notification.title)
.scaledFont(size: 13, weight: .semibold)
.foregroundColor(.white)
.lineLimit(1)
HStack(spacing: 7) {
Button {
NotchMomentsCoordinator.shared.reviewFollowUps()
FloatingControlBarManager.shared.dismissCurrentNotification()
} label: {
Text("Review")
.scaledFont(size: 12, weight: .semibold)
.foregroundColor(.black)
.padding(.horizontal, 11).padding(.vertical, 4)
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 7, style: .continuous))
}
.buttonStyle(.plain)
Button {
FloatingControlBarManager.shared.dismissCurrentNotification()
} label: {
Text("Later").scaledFont(size: 12).foregroundColor(.white.opacity(0.5))
}
.buttonStyle(.plain)
}
.padding(.top, 4)
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.sm)
.frame(maxWidth: .infinity, alignment: .leading)
}
/// Hard reach failure (retries exhausted). Persists until the user picks
/// Retry (re-runs the query, restarting backoff) or Skip (back to idle).
private func reachErrorCard(_ notification: FloatingBarNotification) -> some View {
HStack(alignment: .center, spacing: OmiSpacing.sm) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 14, weight: .semibold))
.foregroundColor(.white.opacity(0.9))
VStack(alignment: .leading, spacing: 1) {
Text(notification.title)
.scaledFont(size: OmiType.body, weight: .semibold)
.foregroundColor(.white)
.lineLimit(1)
if !notification.message.isEmpty {
Text(notification.message)
.scaledFont(size: 11)
.foregroundColor(.white.opacity(0.7))
.lineLimit(1)
}
}
Spacer(minLength: OmiSpacing.sm)
Button {
FloatingControlBarManager.shared.retryReachError()
} label: {
Text("Retry")
.scaledFont(size: 12, weight: .semibold)
.foregroundColor(.white)
.padding(.horizontal, OmiSpacing.sm)
.padding(.vertical, OmiSpacing.xxs)
.background(Color.white.opacity(0.18))
.clipShape(Capsule())
}
.buttonStyle(.plain)
Button {
FloatingControlBarManager.shared.dismissReachError()
} label: {
Text("Skip")
.scaledFont(size: 12, weight: .semibold)
.foregroundColor(.white.opacity(0.6))
.padding(.horizontal, OmiSpacing.xs)
.padding(.vertical, OmiSpacing.xxs)
}
.buttonStyle(.plain)
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.md)
.frame(maxWidth: .infinity, alignment: .leading)
}
private var notchAgentLogoHitTarget: some View {
GeometryReader { geometry in
let logoCenterX = NotchAgentStackMetrics.logoCenterX(
rowWidth: geometry.size.width,
notchHiddenCenterWidth: notchHiddenCenterWidth,
notchSideWidth: notchSideWidth
)
Color.clear
.frame(width: 44, height: 44)
.contentShape(Rectangle())
.position(x: logoCenterX, y: notchChromeHeight / 2)
.onHover { setNotchLogoHovering($0) }
.onTapGesture {
openAgentChatsFromNotchLogo()
}
.accessibilityLabel("Agent chats")
.accessibilityHint("Open agent chats")
}
}
private var notchControlLobe: some View {
// Idle-notch clicking opens the main chat. During capture the same lobe
// becomes the explicit stop/send action, using the existing push-to-talk
// button facade so the reducer remains the sole lifecycle owner.
Button {
if showingNotchVoiceControl {
onTogglePushToTalk()
} else {
openMainChatFromIdleNotch()
}
} label: {
if showingNotchVoiceControl {
HStack(spacing: OmiSpacing.xxs) {
Image(systemName: NotchVoiceControlPresentation.iconName(isLocked: state.isVoiceLocked))
.scaledFont(size: OmiType.micro, weight: .semibold)
Text(NotchVoiceControlPresentation.title(isLocked: state.isVoiceLocked))
.scaledFont(size: OmiType.micro, weight: .bold)
}
.foregroundColor(state.isVoiceLocked ? .orange : NotchGlass.ink(.w85))
.padding(.horizontal, OmiSpacing.xs)
.padding(.vertical, OmiSpacing.xxs)
.background(
Capsule().fill(
state.isVoiceLocked ? Color.orange.opacity(0.18) : NotchGlass.fillHover
)
)
.contentShape(Capsule())
} else {
Color.clear
.contentShape(Rectangle())
}
}
.buttonStyle(.plain)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.padding(.leading, OmiSpacing.xs)
.padding(.trailing, OmiSpacing.md)
.accessibilityLabel(
showingNotchVoiceControl
? NotchVoiceControlPresentation.accessibilityLabel(isLocked: state.isVoiceLocked)
: "Open Omi chat"
)
.accessibilityValue(