Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions Dayflow/Dayflow/Views/Onboarding/OnboardingFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,16 @@ struct OnboardingFlow: View {
step.next()
savedStepRawValue = step.rawValue

// Only try to start recording if we already have permission
if CGPreflightScreenCaptureAccess() {
Task {
do {
// Verify we have permission
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
// Start recording
await MainActor.run {
AppState.shared.isRecording = true
}
} catch {
// Permission not granted yet, that's ok
// It will start after restart
print("Will start recording after restart")
// Try to start recording if we have permission
Task {
do {
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
await MainActor.run {
AppState.shared.isRecording = true
}
} catch {
// Permission not granted yet, will start after restart
print("Will start recording after restart")
}
}
case .completion:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import SwiftUI
import AppKit
import ScreenCaptureKit
import CoreGraphics

struct ScreenRecordingPermissionView: View {
var onBack: () -> Void
var onNext: () -> Void
Expand Down Expand Up @@ -180,20 +178,38 @@ struct ScreenRecordingPermissionView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onAppear {
// If already granted, mark as granted; otherwise start in notRequested
if CGPreflightScreenCaptureAccess() {
permissionState = .granted
Task { @MainActor in AppDelegate.allowTermination = false }
} else {
permissionState = .notRequested
Task { @MainActor in AppDelegate.allowTermination = true }
Task {
let granted: Bool
do {
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
granted = true
} catch {
granted = false
}
await MainActor.run {
if granted {
permissionState = .granted
AppDelegate.allowTermination = false
} else {
permissionState = .notRequested
AppDelegate.allowTermination = true
}
}
}
}
// Re-check when app becomes active again (e.g., returning from System Settings)
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
// Only transition to granted here; avoid flipping notChecked to denied automatically
if CGPreflightScreenCaptureAccess() {
permissionState = .granted
Task { @MainActor in AppDelegate.allowTermination = false }
Task {
do {
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
await MainActor.run {
permissionState = .granted
AppDelegate.allowTermination = false
}
} catch {
// Not granted yet, keep current state
}
}
}
.onDisappear {
Expand All @@ -208,16 +224,27 @@ struct ScreenRecordingPermissionView: View {

// This will prompt and register the app with TCC; may return false
_ = CGRequestScreenCaptureAccess()
if CGPreflightScreenCaptureAccess() {
permissionState = .granted
AnalyticsService.shared.capture("screen_permission_granted")
Task { @MainActor in AppDelegate.allowTermination = false }
} else {
permissionState = .needsAction
AnalyticsService.shared.capture("screen_permission_denied")
Task { @MainActor in AppDelegate.allowTermination = true }
Task {
let granted: Bool
do {
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
granted = true
} catch {
granted = false
}
await MainActor.run {
if granted {
permissionState = .granted
AnalyticsService.shared.capture("screen_permission_granted")
AppDelegate.allowTermination = false
} else {
permissionState = .needsAction
AnalyticsService.shared.capture("screen_permission_denied")
AppDelegate.allowTermination = true
}
isCheckingPermission = false
}
}
isCheckingPermission = false
}

private func openSystemSettings() {
Expand Down
10 changes: 8 additions & 2 deletions Dayflow/Dayflow/Views/UI/Settings/StorageSettingsViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AppKit
import Combine
import CoreGraphics
import Foundation
import ScreenCaptureKit

@MainActor
final class StorageSettingsViewModel: ObservableObject {
Expand Down Expand Up @@ -67,7 +67,13 @@ final class StorageSettingsViewModel: ObservableObject {
}

Task.detached(priority: .utility) { [weak self] in
let permission = CGPreflightScreenCaptureAccess()
let permission: Bool
do {
_ = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: true)
permission = true
} catch {
permission = false
}
let recordingsURL = StorageManager.shared.recordingsRoot

let recordingsSize = StorageSettingsViewModel.directorySize(at: recordingsURL)
Expand Down