Minor fixes
This commit is contained in:
@@ -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
|
||||||
title: String(localized: "Full Disk Access permission is required"),
|
|
||||||
message: String(localized: "Please grant the permission for **SFMExtension**, then we can continue."),
|
|
||||||
primaryButton: .default(String(localized: "Authorize"), action: openFDASettings),
|
|
||||||
secondaryButton: .cancel()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
await MainActor.run {
|
|
||||||
alert = AlertState(title: String(localized: "Service Error"), message: myError.localizedDescription)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 os(macOS)
|
||||||
private func openFDASettings() {
|
if nsError.domain == "Library.FullDiskAccessPermissionRequired" {
|
||||||
|
return AlertState(
|
||||||
|
title: String(localized: "Full Disk Access permission is required"),
|
||||||
|
message: String(localized: "Please grant the permission for **SFMExtension**, then we can continue."),
|
||||||
|
primaryButton: .default(String(localized: "Authorize"), action: Self.openFDASettings),
|
||||||
|
secondaryButton: .cancel()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return AlertState(title: String(localized: "Service Error"), message: nsError.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user