forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRewindOnlyView.swift
More file actions
357 lines (306 loc) · 10.9 KB
/
Copy pathRewindOnlyView.swift
File metadata and controls
357 lines (306 loc) · 10.9 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
import OmiSupport
import OmiTheme
import SwiftUI
/// Rewind-only view for when the app is launched with --mode=rewind
/// Shows just the Rewind page without the sidebar, with a settings button overlay
struct RewindOnlyView: View {
@StateObject private var appState = AppState()
@ObservedObject private var authState = AuthState.shared
var body: some View {
Group {
if authState.isRestoringAuth {
VStack(spacing: OmiSpacing.lg) {
if let iconURL = Bundle.resourceBundle.url(forResource: "herologo", withExtension: "png"),
let nsImage = NSImage(contentsOf: iconURL)
{
Image(nsImage: nsImage)
.resizable()
.scaledToFit()
.frame(width: 64, height: 64)
}
ProgressView()
.scaleEffect(0.8)
.tint(Ink.secondary)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else if authState.sessionPhase == .recoveryRequired {
SessionRecoveryView()
.onAppear {
log("RewindOnlyView: Showing recoverable auth state")
}
} else if !authState.isSignedIn {
// Not signed in - show sign in view
SignInView(authState: authState)
.onAppear {
log("RewindOnlyView: Showing SignInView (not signed in)")
}
} else {
// Signed in - show Rewind page with settings overlay
rewindContent
.onAppear {
log("RewindOnlyView: Showing Rewind content (signed in)")
// Start screen monitoring automatically in rewind mode
startMonitoringIfNeeded()
}
}
}
// No ground of its own: the glass window owns it. See `glassContent()` — it also pins the
// panel's light appearance, without which `Ink`'s ladder resolves *up* on a Dark Mac and the
// whole page renders white on white.
.glassContent()
.frame(minWidth: 800, minHeight: 500)
.tint(Ink.accent)
.onAppear {
log("RewindOnlyView: View appeared - isSignedIn=\(authState.isSignedIn)")
// The window has to be transparent and light-pinned or there is no glass — a window still
// painting its own `backgroundColor` slips an opaque sheet between the desktop and the blur.
DispatchQueue.main.async {
for window in NSApp.windows
where window.title.contains("Rewind") || window.title.lowercased().hasPrefix("omi") {
WindowGlass.wear(window, as: .titled)
}
}
}
}
// MARK: - Rewind Content
private var rewindContent: some View {
ZStack(alignment: .topTrailing) {
// Main Rewind page (full width, no sidebar)
RewindPage()
// Settings button overlay in top-right corner
settingsButton
.padding(OmiSpacing.lg)
}
}
// MARK: - Settings Button
private var settingsButton: some View {
Menu {
Button {
openRewindSettings()
} label: {
Label("Rewind Settings", systemImage: "slider.horizontal.3")
}
Divider()
Button {
openFullApp()
} label: {
Label("Open Full omi App", systemImage: "square.grid.2x2")
}
Divider()
Button {
NSApplication.shared.terminate(nil)
} label: {
Label("Quit", systemImage: "xmark.circle")
}
} label: {
Image(systemName: "gearshape.fill")
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.primary)
.padding(OmiSpacing.sm)
// It floats over the timeline, so it is real glass rather than a wash: a wash over moving
// screenshots is not a control, it is a smudge.
.glassFloatingBar(cornerRadius: 999)
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.fixedSize()
.help("Settings")
}
// MARK: - Actions
private func startMonitoringIfNeeded() {
let settings = AssistantSettings.shared
if settings.screenAnalysisEnabled {
ProactiveAssistantsPlugin.shared.startMonitoring { success, error in
if success {
log("RewindOnlyView: Screen analysis started automatically")
} else {
log("RewindOnlyView: Screen analysis failed to start: \(error ?? "unknown")")
}
}
}
}
private func openRewindSettings() {
// Open settings window focused on Rewind section
RewindSettingsWindow.show()
}
private func openFullApp() {
// Launch the full app (without --mode=rewind)
let appPath = Bundle.main.bundlePath
let task = Process()
task.launchPath = "/usr/bin/open"
task.arguments = ["-n", appPath] // -n opens a new instance
try? task.run()
}
}
// MARK: - Rewind Settings Window
/// Standalone settings window for Rewind-only mode
@MainActor class RewindSettingsWindow {
static var window: NSWindow?
static func show() {
// If window exists, just bring it to front
if let existingWindow = window, existingWindow.isVisible {
existingWindow.makeKeyAndOrderFront(nil)
NSApp.activate()
return
}
// Create settings content - using SettingsContentView with Rewind section
let settingsView = RewindSettingsView()
.withFontScaling()
.frame(minWidth: 500, minHeight: 400)
.glassContent()
let hostingController = NSHostingController(rootView: settingsView)
let newWindow = NSWindow(contentViewController: hostingController)
newWindow.title = "Rewind Settings"
newWindow.setContentSize(NSSize(width: 600, height: 500))
newWindow.styleMask = [.titled, .closable, .resizable, .miniaturizable]
newWindow.minSize = NSSize(width: 500, height: 400)
newWindow.center()
// Transparent + light-pinned, or there is no glass.
WindowGlass.wear(newWindow, as: .titled)
newWindow.isReleasedWhenClosed = false
newWindow.makeKeyAndOrderFront(nil)
NSApp.activate()
self.window = newWindow
}
}
// MARK: - Rewind Settings View
/// Settings view specifically for Rewind configuration
struct RewindSettingsView: View {
@AppStorage("screenAnalysisEnabled") private var screenAnalysisEnabled = true
@AppStorage("rewindRetentionDays") private var retentionDays = 7
@AppStorage("rewindCaptureInterval") private var captureInterval = 1.0
@State private var excludedApps: [String] = []
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: OmiSpacing.xxl) {
// Header
VStack(alignment: .leading, spacing: OmiSpacing.xxs) {
Text("Rewind Settings")
.scaledFont(size: 24, weight: .bold)
.foregroundColor(Ink.primary)
Text("Configure screen capture and storage")
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.secondary)
}
GlassSeparator()
// Screen Capture Toggle
settingsRow(
title: "Screen Capture",
subtitle: "Capture screenshots for Rewind timeline"
) {
Toggle("", isOn: $screenAnalysisEnabled)
.toggleStyle(OmiToggleStyle())
}
// Retention Period
settingsRow(
title: "Keep Screenshots For",
subtitle: RewindSettings.isUnlimited(retentionDays: retentionDays)
? "Every screenshot is kept, so Rewind reaches back to your first capture"
: "Older screenshots will be automatically deleted"
) {
SettingsMenuPicker(selection: $retentionDays) {
Text("1 day").tag(1)
Text("3 days").tag(3)
Text("7 days").tag(7)
Text("14 days").tag(14)
Text("30 days").tag(30)
Text("Keep everything").tag(RewindSettings.unlimitedRetentionDays)
}
}
// Storage Info
storageInfoSection
GlassSeparator()
// Permissions Section
permissionsSection
Spacer()
}
.padding(OmiSpacing.xxl)
}
.glassContent()
}
private func settingsRow<Content: View>(
title: String,
subtitle: String,
@ViewBuilder content: () -> Content
) -> some View {
HStack(alignment: .center, spacing: OmiSpacing.lg) {
VStack(alignment: .leading, spacing: OmiSpacing.xxs) {
Text(title)
.scaledFont(size: OmiType.body, weight: .medium)
.foregroundColor(Ink.primary)
Text(subtitle)
.scaledFont(size: OmiType.caption)
// The bottom rung on glass is `secondary`; a fainter grey measures under WCAG AA there.
.foregroundColor(Ink.secondary)
}
Spacer()
content()
}
.padding(.vertical, OmiSpacing.sm)
}
private var storageInfoSection: some View {
VStack(alignment: .leading, spacing: OmiSpacing.md) {
Text("Storage")
.scaledFont(size: OmiType.body, weight: .semibold)
.foregroundColor(Ink.primary)
HStack {
VStack(alignment: .leading, spacing: OmiSpacing.xxs) {
Text("Screenshots stored locally")
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.primary)
Text("~/Library/Application Support/Omi/users/\(UserDefaults.standard.string(forKey: "auth_userId") ?? "")/")
.scaledFont(size: OmiType.caption, design: .monospaced)
.foregroundColor(Ink.secondary)
}
Spacer()
Button("Show in Finder") {
let url = DesktopLocalProfile.applicationSupportURL()
NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: url.path)
}
.buttonStyle(.plain)
// The one accent, spent on the one thing here that is actionable and is not a button.
.foregroundColor(Ink.accent)
.scaledFont(size: OmiType.caption, weight: .medium)
}
}
.padding(OmiSpacing.lg)
.glassCard(cornerRadius: PageGlass.rowRadius)
}
private var permissionsSection: some View {
VStack(alignment: .leading, spacing: OmiSpacing.md) {
Text("Permissions")
.scaledFont(size: OmiType.body, weight: .semibold)
.foregroundColor(Ink.primary)
Button {
ScreenCaptureService.requestScreenRecordingAccessAndOpenSettings()
} label: {
HStack {
Image(systemName: "rectangle.on.rectangle")
.scaledFont(size: OmiType.subheading)
.foregroundColor(Ink.primary)
VStack(alignment: .leading, spacing: OmiSpacing.hairline) {
Text("Screen Recording")
.scaledFont(size: OmiType.body, weight: .medium)
.foregroundColor(Ink.primary)
Text("Required for Rewind to capture your screen")
.scaledFont(size: OmiType.caption)
.foregroundColor(Ink.secondary)
}
Spacer()
Text("Open Settings")
.scaledFont(size: OmiType.caption, weight: .medium)
.foregroundColor(Ink.accent)
}
.padding(OmiSpacing.md)
.glassCard(cornerRadius: PageGlass.rowRadius)
}
.buttonStyle(.plain)
}
}
}
#if canImport(PreviewsMacros)
#Preview {
RewindOnlyView()
.frame(width: 1000, height: 700)
}
#endif