Add Open Settings button for camera permission denied on macOS
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
import Library
|
import Library
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public struct QRScannerView: View {
|
public struct QRScannerView: View {
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@@ -140,15 +144,34 @@
|
|||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
switch error {
|
switch error {
|
||||||
case .permissionDenied:
|
case .permissionDenied:
|
||||||
|
#if os(macOS)
|
||||||
|
alert = AlertState(
|
||||||
|
title: String(localized: "Camera Access Denied"),
|
||||||
|
message: String(localized: "Please enable camera access in Settings to scan QR codes."),
|
||||||
|
primaryButton: .default(String(localized: "Open Settings")) {
|
||||||
|
openCameraPrivacySettings()
|
||||||
|
},
|
||||||
|
secondaryButton: .cancel()
|
||||||
|
)
|
||||||
|
#else
|
||||||
alert = AlertState(
|
alert = AlertState(
|
||||||
title: String(localized: "Camera Access Denied"),
|
title: String(localized: "Camera Access Denied"),
|
||||||
message: String(localized: "Please enable camera access in Settings to scan QR codes.")
|
message: String(localized: "Please enable camera access in Settings to scan QR codes.")
|
||||||
)
|
)
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
alert = AlertState(error: error)
|
alert = AlertState(error: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
private func openCameraPrivacySettings() {
|
||||||
|
if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Camera") {
|
||||||
|
NSWorkspace.shared.open(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct CircularProgressView: View {
|
private struct CircularProgressView: View {
|
||||||
|
|||||||
Reference in New Issue
Block a user