-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathOnboardingView.swift
More file actions
613 lines (555 loc) · 24.8 KB
/
OnboardingView.swift
File metadata and controls
613 lines (555 loc) · 24.8 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
import SwiftUI
import AppKit
import AVKit
import SceneKit
struct OnboardingView: View {
@ObservedObject var appState: AppState
@ObservedObject var chatProvider: ChatProvider
var onComplete: (() -> Void)? = nil
@AppStorage("onboardingStep") private var currentStep = 0
@AppStorage("onboardingVideoStepMigrationDone") private var hasMigratedOnboardingSteps = false
@StateObject private var graphViewModel = MemoryGraphViewModel()
@State private var graphHasData = false
@State private var showTrustPreview = true
@State private var showGraphHints = false
@State private var hintsHovered = false
let steps = ["Chat", "Notifications", "FloatingBar", "VoiceInput", "Tasks"]
var body: some View {
ZStack {
// Full dark background
OmiColors.backgroundPrimary
.ignoresSafeArea()
Group {
if appState.hasCompletedOnboarding {
Color.clear
.onAppear {
log("OnboardingView: hasCompletedOnboarding=true, starting monitoring")
if !ProactiveAssistantsPlugin.shared.isMonitoring {
ProactiveAssistantsPlugin.shared.startMonitoring { _, _ in }
}
if let onComplete = onComplete {
log("OnboardingView: Calling onComplete handler")
onComplete()
} else {
log("OnboardingView: No onComplete handler, view will transition via DesktopHomeView")
}
}
} else {
onboardingContent
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
// One-time migration after removing the dedicated video step:
// old indices (0-5) become new indices (0-4), shifting all non-zero steps down by 1.
if !hasMigratedOnboardingSteps {
if currentStep > 0 {
currentStep -= 1
}
hasMigratedOnboardingSteps = true
}
// If currentStep is beyond the 5-step flow (0-4), clamp to last step.
if currentStep > 4 {
currentStep = 4
}
}
.task {
// Pre-warm the ACP bridge before the chat step starts.
await chatProvider.warmupBridge()
}
.onReceive(NotificationCenter.default.publisher(for: .resetOnboardingRequested)) { _ in
log("OnboardingView: resetOnboardingRequested — returning to chat step for current app")
currentStep = 0
}
}
private var onboardingContent: some View {
Group {
if currentStep == 0 {
// Step 0: Interactive AI Chat + Live Knowledge Graph
HStack(spacing: 0) {
OnboardingChatView(
appState: appState,
chatProvider: chatProvider,
graphViewModel: graphViewModel,
onComplete: {
AnalyticsManager.shared.onboardingStepCompleted(step: 0, stepName: "Chat")
currentStep = 1
},
onSkip: {
currentStep = 1
}
)
.frame(maxWidth: .infinity, maxHeight: .infinity)
// Right pane: Knowledge graph (dark background, graph appears when data arrives)
ZStack {
OmiColors.backgroundSecondary.ignoresSafeArea()
if graphHasData && !showTrustPreview {
MemoryGraphSceneView(viewModel: graphViewModel)
.ignoresSafeArea()
.transition(.opacity)
}
if showTrustPreview {
OnboardingTrustPreviewCard()
.padding(.horizontal, 48)
.transition(.opacity.combined(with: .scale(scale: 0.97)))
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(alignment: .top) {
if graphHasData && !showTrustPreview {
Text("This is your second brain.")
.font(.system(size: 14, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color.black.opacity(0.35))
.cornerRadius(8)
.padding(.top, 18)
.transition(.opacity)
}
}
// Use .overlay so hints composite above the NSViewRepresentable SCNView
.overlay(alignment: .bottom) {
HStack(spacing: 20) {
graphHintItem(icon: "arrow.triangle.2.circlepath", label: "Drag to rotate")
graphHintItem(icon: "magnifyingglass", label: "Scroll to zoom")
graphHintItem(icon: "hand.draw", label: "Two-finger to pan")
}
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(
LinearGradient(
colors: [Color.black.opacity(0), Color.black.opacity(0.5)],
startPoint: .top,
endPoint: .bottom
)
)
.onHover { hovering in
hintsHovered = hovering
}
.opacity(graphHasData && (showGraphHints || hintsHovered) ? 1 : 0)
.animation(.easeInOut(duration: 0.3), value: showGraphHints)
.animation(.easeInOut(duration: 0.3), value: hintsHovered)
.animation(.easeInOut(duration: 0.3), value: graphHasData)
}
.onAppear {
showTrustPreview = true
// Handle case where graph already has data on appear
if !graphViewModel.isEmpty && !graphHasData {
handleGraphDataArrival()
}
}
.onChange(of: graphViewModel.isEmpty) { _, isEmpty in
if !isEmpty && !graphHasData {
handleGraphDataArrival()
}
}
}
} else if currentStep == 1 {
// Step 1: Smart Notifications Demo
OnboardingNotificationStepView(
appState: appState,
chatProvider: chatProvider,
onContinue: {
AnalyticsManager.shared.onboardingStepCompleted(step: 1, stepName: "Notifications")
currentStep = 2
},
onSkip: {
AnalyticsManager.shared.onboardingStepCompleted(step: 1, stepName: "Notifications_Skipped")
currentStep = 2
}
)
} else if currentStep == 2 {
// Step 2: Floating Bar Demo
OnboardingFloatingBarDemoView(
appState: appState,
chatProvider: chatProvider,
onComplete: {
AnalyticsManager.shared.onboardingStepCompleted(step: 2, stepName: "FloatingBar")
currentStep = 3
},
onSkip: {
AnalyticsManager.shared.onboardingStepCompleted(step: 2, stepName: "FloatingBar_Skipped")
currentStep = 3
}
)
} else if currentStep == 3 {
// Step 3: Voice Input Demo
OnboardingVoiceInputDemoView(
appState: appState,
chatProvider: chatProvider,
onComplete: {
AnalyticsManager.shared.onboardingStepCompleted(step: 3, stepName: "VoiceInput")
currentStep = 4
},
onSkip: {
AnalyticsManager.shared.onboardingStepCompleted(step: 3, stepName: "VoiceInput_Skipped")
currentStep = 4
}
)
} else {
// Step 4: Tasks
OnboardingTasksStepView(
onComplete: {
AnalyticsManager.shared.onboardingStepCompleted(step: 4, stepName: "Tasks")
handleOnboardingComplete()
}
)
}
}
}
private func graphHintItem(icon: String, label: String) -> some View {
HStack(spacing: 4) {
Image(systemName: icon)
.font(.system(size: 11))
Text(label)
.font(.system(size: 11))
}
.foregroundColor(.white.opacity(0.5))
}
private func flashGraphHints() {
showGraphHints = true
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
showGraphHints = false
}
}
private func handleGraphDataArrival() {
withAnimation(.easeIn(duration: 0.35)) {
graphHasData = true
}
// Keep the trust panel visible briefly, then transition to the graph.
DispatchQueue.main.asyncAfter(deadline: .now() + 1.4) {
withAnimation(.easeInOut(duration: 0.45)) {
showTrustPreview = false
}
flashGraphHints()
}
}
/// Complete onboarding — start all services and transition to the app
private func handleOnboardingComplete() {
log("OnboardingView: Onboarding complete")
AnalyticsManager.shared.onboardingCompleted()
// Stop the AI if it's still running
chatProvider.stopAgent()
// Navigate to Tasks page after transition
UserDefaults.standard.set(true, forKey: "onboardingJustCompleted")
UserDefaults.standard.set(true, forKey: "hasCompletedFileIndexing")
// Start essential services
Task {
await AgentVMService.shared.startPipeline()
await GoalGenerationService.shared.generateNow()
}
if LaunchAtLoginManager.shared.setEnabled(true) {
AnalyticsManager.shared.launchAtLoginChanged(enabled: true, source: "onboarding_complete")
}
ProactiveAssistantsPlugin.shared.startMonitoring { _, _ in }
appState.startTranscription()
// Create welcome task
Task {
let welcomeDescription = "Run omi for two days to start receiving helpful advice"
let alreadyExists = await ActionItemStorage.shared.actionItemExists(description: welcomeDescription)
if !alreadyExists {
await TasksStore.shared.createTask(
description: welcomeDescription,
dueAt: Date(),
priority: "low"
)
}
}
// Clean up onboarding state and persisted chat data
chatProvider.isOnboarding = false
OnboardingChatPersistence.clear()
if let onComplete = onComplete {
onComplete()
}
// Defer the view hierarchy change so SwiftUI finishes rendering the
// current button before the OnboardingView is removed from the tree.
// Setting this synchronously crashes in Button.body.getter.
DispatchQueue.main.async {
appState.hasCompletedOnboarding = true
}
}
}
private struct OnboardingTrustPreviewCard: View {
var body: some View {
VStack(spacing: 24) {
OnboardingVideoView(cornerRadius: 14)
.aspectRatio(16.0 / 9.0, contentMode: .fit)
.frame(maxWidth: .infinity)
.clipShape(RoundedRectangle(cornerRadius: 16))
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(OmiColors.backgroundQuaternary.opacity(0.35), lineWidth: 1)
)
Rectangle()
.fill(
LinearGradient(
colors: [
OmiColors.backgroundQuaternary.opacity(0),
OmiColors.backgroundQuaternary.opacity(0.4),
OmiColors.backgroundQuaternary.opacity(0)
],
startPoint: .leading,
endPoint: .trailing
)
)
.frame(height: 1)
.padding(.horizontal, 20)
HStack(spacing: 8) {
Image(systemName: "shield.lefthalf.filled")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(OmiColors.purplePrimary.opacity(0.9))
Text("Trust & Privacy")
.font(.system(size: 17, weight: .medium))
.foregroundColor(OmiColors.textSecondary)
.lineLimit(1)
Text("omi protects your data")
.font(.system(size: 15, weight: .regular))
.foregroundColor(OmiColors.textTertiary)
.lineLimit(1)
.minimumScaleFactor(0.85)
}
.padding(.top, 2)
.padding(.bottom, 6)
.frame(maxWidth: .infinity, alignment: .center)
VStack(spacing: 10) {
trustRow(icon: "chevron.left.forwardslash.chevron.right", title: "Open Source", detail: "Code is ")
trustRow(icon: "lock.shield", title: "Encrypted", detail: "Cloud sync data is encrypted in transit and at rest.")
trustRow(icon: "externaldrive.badge.person.crop", title: "User-Owned", detail: "Primary data stays local and belongs to you.")
}
.padding(16)
.background(
RoundedRectangle(cornerRadius: 16)
.fill(OmiColors.backgroundTertiary.opacity(0.75))
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(OmiColors.purplePrimary.opacity(0.25), lineWidth: 1)
)
)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 24)
}
@ViewBuilder
private func trustRow(icon: String, title: String, detail: String) -> some View {
HStack(alignment: .top, spacing: 10) {
Image(systemName: icon)
.font(.system(size: 14, weight: .semibold))
.foregroundColor(OmiColors.purplePrimary)
.frame(width: 20, height: 20)
VStack(alignment: .leading, spacing: 2) {
Text(title)
.font(.system(size: 13, weight: .semibold))
.foregroundColor(OmiColors.textPrimary)
if title == "Open Source" {
HStack(spacing: 0) {
Text(detail)
.foregroundColor(OmiColors.textSecondary)
if let url = URL(string: "https://github.com/basedhardware/omi/") {
Link("public", destination: url)
.foregroundColor(OmiColors.purpleSecondary)
.underline()
}
Text(" and auditable.")
.foregroundColor(OmiColors.textSecondary)
}
.font(.system(size: 12))
} else {
Text(detail)
.font(.system(size: 12))
.foregroundColor(OmiColors.textSecondary)
}
}
Spacer()
}
}
}
// MARK: - Onboarding Video View
struct OnboardingVideoView: NSViewRepresentable {
var cornerRadius: CGFloat = 12
func makeCoordinator() -> Coordinator {
Coordinator()
}
func makeNSView(context: Context) -> AVPlayerView {
let playerView = AVPlayerView()
playerView.wantsLayer = true
playerView.layer?.cornerRadius = cornerRadius
playerView.layer?.cornerCurve = .continuous
playerView.layer?.masksToBounds = true
playerView.videoGravity = .resizeAspect
if let url = Bundle.resourceBundle.url(forResource: "omi-demo", withExtension: "mp4") {
let player = AVPlayer(url: url)
playerView.player = player
playerView.controlsStyle = .none
playerView.showsFullScreenToggleButton = false
playerView.showsSharingServiceButton = false
player.play()
NotificationCenter.default.addObserver(
context.coordinator,
selector: #selector(Coordinator.playerDidFinishPlaying(_:)),
name: .AVPlayerItemDidPlayToEndTime,
object: player.currentItem
)
context.coordinator.player = player
}
return playerView
}
func updateNSView(_ nsView: AVPlayerView, context: Context) {
nsView.layer?.cornerRadius = cornerRadius
}
class Coordinator: NSObject {
var player: AVPlayer?
@objc func playerDidFinishPlaying(_ notification: Notification) {
player?.seek(to: .zero)
player?.play()
}
}
}
// MARK: - Animated GIF View
struct AnimatedGIFView: NSViewRepresentable {
let gifName: String
func makeNSView(context: Context) -> NSImageView {
let imageView = NSImageView()
imageView.imageScaling = .scaleProportionallyDown
imageView.animates = true
imageView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
imageView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
if let url = Bundle.resourceBundle.url(forResource: gifName, withExtension: "gif"),
let image = NSImage(contentsOf: url) {
imageView.image = image
}
return imageView
}
func updateNSView(_ nsView: NSImageView, context: Context) {
nsView.animates = true
}
}
// MARK: - Onboarding Privacy Sheet
struct OnboardingPrivacySheet: View {
@Binding var isPresented: Bool
var body: some View {
VStack(spacing: 0) {
// Header
HStack {
Image(systemName: "shield.lefthalf.filled")
.scaledFont(size: 16)
.foregroundColor(OmiColors.purplePrimary)
Text("Data & Privacy")
.scaledFont(size: 16, weight: .semibold)
.foregroundColor(OmiColors.textPrimary)
Spacer()
Button(action: { isPresented = false }) {
Image(systemName: "xmark.circle.fill")
.scaledFont(size: 18)
.foregroundColor(OmiColors.textTertiary)
}
.buttonStyle(.plain)
}
.padding(20)
Divider()
ScrollView {
VStack(alignment: .leading, spacing: 16) {
// Encryption
privacyCard {
VStack(alignment: .leading, spacing: 10) {
Label("Encryption", systemImage: "lock.shield")
.scaledFont(size: 13, weight: .semibold)
.foregroundColor(OmiColors.textPrimary)
HStack(spacing: 8) {
Image(systemName: "checkmark.circle.fill")
.scaledFont(size: 11)
.foregroundColor(.green)
Text("Server-side encryption")
.scaledFont(size: 12)
.foregroundColor(OmiColors.textSecondary)
Text("Active")
.scaledFont(size: 10, weight: .semibold)
.foregroundColor(.green)
.padding(.horizontal, 5)
.padding(.vertical, 1)
.background(Color.green.opacity(0.15))
.cornerRadius(3)
}
Text("Your data is encrypted and stored securely with Google Cloud infrastructure.")
.scaledFont(size: 11)
.foregroundColor(OmiColors.textTertiary)
.padding(.top, 2)
}
}
// What We Track
privacyCard {
VStack(alignment: .leading, spacing: 8) {
Label("What We Track", systemImage: "list.bullet")
.scaledFont(size: 13, weight: .semibold)
.foregroundColor(OmiColors.textPrimary)
VStack(alignment: .leading, spacing: 4) {
sheetTrackingItem("Onboarding steps completed")
sheetTrackingItem("Settings changes")
sheetTrackingItem("App installations and usage")
sheetTrackingItem("Device connection status")
sheetTrackingItem("Transcript processing events")
sheetTrackingItem("Conversation creation and updates")
sheetTrackingItem("Memory extraction events")
sheetTrackingItem("Chat interactions")
sheetTrackingItem("Speech profile creation")
sheetTrackingItem("Focus session events")
sheetTrackingItem("App open/close events")
}
}
}
// Privacy Guarantees
privacyCard {
VStack(alignment: .leading, spacing: 8) {
Label("Privacy Guarantees", systemImage: "hand.raised.fill")
.scaledFont(size: 13, weight: .semibold)
.foregroundColor(OmiColors.textPrimary)
VStack(alignment: .leading, spacing: 5) {
sheetBullet("Anonymous tracking with randomly generated IDs")
sheetBullet("No personal info stored in analytics")
sheetBullet("Data is never sold or shared with third parties")
sheetBullet("Opt out of tracking at any time")
}
}
}
}
.padding(20)
}
}
.frame(width: 400, height: 480)
.background(OmiColors.backgroundSecondary)
}
private func privacyCard<Content: View>(@ViewBuilder content: () -> Content) -> some View {
content()
.padding(14)
.frame(maxWidth: .infinity, alignment: .leading)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(OmiColors.backgroundTertiary.opacity(0.5))
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(OmiColors.backgroundQuaternary.opacity(0.3), lineWidth: 1)
)
)
}
private func sheetTrackingItem(_ text: String) -> some View {
HStack(spacing: 6) {
Circle()
.fill(OmiColors.textTertiary.opacity(0.5))
.frame(width: 3, height: 3)
Text(text)
.scaledFont(size: 11)
.foregroundColor(OmiColors.textTertiary)
}
}
private func sheetBullet(_ text: String) -> some View {
HStack(spacing: 6) {
Image(systemName: "checkmark")
.scaledFont(size: 8, weight: .bold)
.foregroundColor(.green)
Text(text)
.scaledFont(size: 11)
.foregroundColor(OmiColors.textSecondary)
}
}
}