@@ -12,7 +12,7 @@ import Defaults
1212struct CameraPreviewView : View {
1313 @EnvironmentObject var vm : BoringViewModel
1414 @ObservedObject var webcamManager : WebcamManager
15-
15+
1616 var body : some View {
1717 GeometryReader { geometry in
1818 ZStack {
@@ -31,21 +31,42 @@ struct CameraPreviewView: View {
3131 . strokeBorder ( . white. opacity ( 0.04 ) , lineWidth: 1 )
3232 . frame ( width: geometry. size. width, height: geometry. size. width)
3333 VStack ( spacing: 8 ) {
34- Image ( systemName: " web.camera " )
34+ Image ( systemName: webcamManager . authorizationStatus == . denied ? " exclamationmark.triangle " : " web.camera " )
3535 . foregroundStyle ( . gray)
3636 . font ( . system( size: geometry. size. width/ 3.5 ) )
37- Text ( " Mirror " )
37+ Text ( webcamManager . authorizationStatus == . denied ? " Access Denied " : " Mirror " )
3838 . font ( . caption2)
3939 . foregroundColor ( . gray)
4040 }
4141 }
4242 }
4343 }
4444 . onTapGesture {
45- if webcamManager. isSessionRunning {
46- webcamManager. stopSession ( )
47- } else {
48- webcamManager. startSession ( )
45+ switch webcamManager. authorizationStatus {
46+ case . authorized:
47+ if webcamManager. isSessionRunning {
48+ webcamManager. stopSession ( )
49+ } else {
50+ webcamManager. startSession ( )
51+ }
52+ case . denied, . restricted:
53+ print ( " 🚫 Camera access denied/restricted from \( #file) : \( #line) " )
54+ let alert = NSAlert ( )
55+ alert. messageText = " Camera Access Required "
56+ alert. informativeText = " Please allow camera access in System Settings to use the mirror feature. "
57+ alert. addButton ( withTitle: " Open Settings " )
58+ alert. addButton ( withTitle: " Cancel " )
59+
60+ if alert. runModal ( ) == . alertFirstButtonReturn {
61+ if let settingsURL = URL ( string: " x-apple.systempreferences:com.apple.preference.security?Privacy_Camera " ) {
62+ NSWorkspace . shared. open ( settingsURL)
63+ }
64+ }
65+ case . notDetermined:
66+ print ( " 🎥 Checking camera authorization from \( #file) : \( #line) " )
67+ webcamManager. checkAndRequestVideoAuthorization ( )
68+ @unknown default :
69+ break
4970 }
5071 }
5172 . onDisappear {
0 commit comments