Minor fixes

This commit is contained in:
世界
2026-01-03 04:11:08 +08:00
parent 81d6827334
commit ef1c924c64
3 changed files with 31 additions and 21 deletions
@@ -154,10 +154,8 @@ public struct StartStopButton: View {
@available(iOS 16.0, macOS 13.0, tvOS 17.0, *) @available(iOS 16.0, macOS 13.0, tvOS 17.0, *)
private func checkStartupError() async { private func checkStartupError() async {
do { if let alertState = await profile.checkLastDisconnectError() {
try await profile.fetchLastDisconnectError() alert = alertState
} catch {
alert = AlertState(title: String(localized: "Service Error"), message: error.localizedDescription)
} }
} }
@@ -4,6 +4,10 @@ import Library
import NetworkExtension import NetworkExtension
import SwiftUI import SwiftUI
#if os(macOS)
import AppKit
#endif
@MainActor @MainActor
public final class DashboardViewModel: BaseViewModel { public final class DashboardViewModel: BaseViewModel {
@Published public var profileList: [ProfilePreview] = [] @Published public var profileList: [ProfilePreview] = []
@@ -154,32 +158,38 @@ public final class DashboardViewModel: BaseViewModel {
@available(iOS 16.0, macOS 13.0, tvOS 17.0, *) @available(iOS 16.0, macOS 13.0, tvOS 17.0, *)
nonisolated func checkLastDisconnectError(profile: ExtensionProfile) async { nonisolated func checkLastDisconnectError(profile: ExtensionProfile) async {
do { if let alertState = await profile.checkLastDisconnectError() {
try await profile.fetchLastDisconnectError()
return
} catch {
let myError = error as NSError
#if os(macOS)
if myError.domain == "Library.FullDiskAccessPermissionRequired" {
await MainActor.run { await MainActor.run {
alert = AlertState( alert = alertState
}
}
}
}
@available(iOS 16.0, macOS 13.0, tvOS 17.0, *)
extension ExtensionProfile {
public nonisolated func checkLastDisconnectError() async -> AlertState? {
do {
try await fetchLastDisconnectError()
return nil
} catch {
let nsError = error as NSError
#if os(macOS)
if nsError.domain == "Library.FullDiskAccessPermissionRequired" {
return AlertState(
title: String(localized: "Full Disk Access permission is required"), title: String(localized: "Full Disk Access permission is required"),
message: String(localized: "Please grant the permission for **SFMExtension**, then we can continue."), message: String(localized: "Please grant the permission for **SFMExtension**, then we can continue."),
primaryButton: .default(String(localized: "Authorize"), action: openFDASettings), primaryButton: .default(String(localized: "Authorize"), action: Self.openFDASettings),
secondaryButton: .cancel() secondaryButton: .cancel()
) )
} }
return
}
#endif #endif
await MainActor.run { return AlertState(title: String(localized: "Service Error"), message: nsError.localizedDescription)
alert = AlertState(title: String(localized: "Service Error"), message: myError.localizedDescription)
}
} }
} }
#if os(macOS) #if os(macOS)
private func openFDASettings() { private static func openFDASettings() {
if NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles")!) { if NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles")!) {
return return
} }
+2
View File
@@ -111,5 +111,7 @@
<string>en</string> <string>en</string>
<key>NSLocalNetworkUsageDescription</key> <key>NSLocalNetworkUsageDescription</key>
<string>As a universal proxy platform, sing-box configures routing according to your configuration.</string> <string>As a universal proxy platform, sing-box configures routing according to your configuration.</string>
<key>NSCameraUsageDescription</key>
<string>Camera access is required to scan QR codes for importing profiles.</string>
</dict> </dict>
</plist> </plist>