From c8e47c092be6eaa67244fa92ce64c2067f639e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 6 Jan 2026 14:06:22 +0800 Subject: [PATCH] Add Open Settings button for camera permission denied on macOS --- .../Views/Scanner/QRScannerView.swift | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ApplicationLibrary/Views/Scanner/QRScannerView.swift b/ApplicationLibrary/Views/Scanner/QRScannerView.swift index 36c5fc8..9d89564 100644 --- a/ApplicationLibrary/Views/Scanner/QRScannerView.swift +++ b/ApplicationLibrary/Views/Scanner/QRScannerView.swift @@ -4,6 +4,10 @@ import Library import SwiftUI + #if os(macOS) + import AppKit + #endif + @MainActor public struct QRScannerView: View { @Environment(\.dismiss) private var dismiss @@ -140,15 +144,34 @@ case let .failure(error): switch error { case .permissionDenied: - alert = AlertState( - title: String(localized: "Camera Access Denied"), - message: String(localized: "Please enable camera access in Settings to scan QR codes.") - ) + #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( + title: String(localized: "Camera Access Denied"), + message: String(localized: "Please enable camera access in Settings to scan QR codes.") + ) + #endif default: 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 {