Finish independent macOS version
This commit is contained in:
@@ -67,7 +67,7 @@ public class ExtensionProfile: ObservableObject {
|
||||
|
||||
public static func install() async throws {
|
||||
let manager = NETunnelProviderManager()
|
||||
manager.localizedDescription = "utun interface"
|
||||
manager.localizedDescription = Variant.applicationName
|
||||
let tunnelProtocol = NETunnelProviderProtocol()
|
||||
if Variant.useSystemExtension {
|
||||
tunnelProtocol.providerBundleIdentifier = "\(FilePath.packageName).system"
|
||||
|
||||
@@ -3,7 +3,7 @@ import Libbox
|
||||
|
||||
public class HTTPClient {
|
||||
private static var userAgent: String {
|
||||
var userAgent = FilePath.httpClientName
|
||||
var userAgent = Variant.applicationName
|
||||
userAgent += "/"
|
||||
userAgent += Bundle.main.version
|
||||
userAgent += " (Build "
|
||||
|
||||
@@ -4,24 +4,32 @@
|
||||
|
||||
public class SystemExtension: NSObject, OSSystemExtensionRequestDelegate {
|
||||
private let forceUpdate: Bool
|
||||
private let inBackground: Bool
|
||||
private let semaphore = DispatchSemaphore(value: 0)
|
||||
private var result: OSSystemExtensionRequest.Result?
|
||||
private var properties: [OSSystemExtensionProperties]?
|
||||
private var error: Error?
|
||||
|
||||
private init(forceUpdate: Bool = false) {
|
||||
private init(forceUpdate: Bool = false, inBackground: Bool = false) {
|
||||
self.forceUpdate = forceUpdate
|
||||
self.inBackground = inBackground
|
||||
}
|
||||
|
||||
public func request(_: OSSystemExtensionRequest, actionForReplacingExtension existing: OSSystemExtensionProperties, withExtension ext: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction {
|
||||
if forceUpdate {
|
||||
return .replace
|
||||
}
|
||||
if existing.isAwaitingUserApproval, !inBackground {
|
||||
return .replace
|
||||
}
|
||||
if existing.bundleIdentifier == ext.bundleIdentifier,
|
||||
existing.bundleVersion == ext.bundleVersion
|
||||
existing.bundleVersion == ext.bundleVersion,
|
||||
existing.bundleShortVersion == ext.bundleShortVersion
|
||||
{
|
||||
NSLog("Skip update system extension")
|
||||
return .cancel
|
||||
} else {
|
||||
NSLog("Update system extension")
|
||||
return .replace
|
||||
}
|
||||
}
|
||||
@@ -69,24 +77,26 @@
|
||||
|
||||
public static func isInstalled() async -> Bool {
|
||||
await (try? Task.detached {
|
||||
do {
|
||||
let propList = try SystemExtension().getProperties()
|
||||
if propList.isEmpty {
|
||||
return false
|
||||
}
|
||||
for extensionProp in propList {
|
||||
if !extensionProp.isAwaitingUserApproval, !extensionProp.isUninstalling {
|
||||
return true
|
||||
for _ in 0 ..< 3 {
|
||||
do {
|
||||
let propList = try SystemExtension().getProperties()
|
||||
if propList.isEmpty {
|
||||
return false
|
||||
}
|
||||
for extensionProp in propList {
|
||||
if !extensionProp.isAwaitingUserApproval, !extensionProp.isUninstalling {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
try await Task.sleep(nanoseconds: NSEC_PER_SEC)
|
||||
}
|
||||
} catch {
|
||||
NSLog(error.localizedDescription)
|
||||
}
|
||||
return false
|
||||
}.result.get()) == true
|
||||
}
|
||||
|
||||
public static func install(forceUpdate: Bool = false) async throws -> OSSystemExtensionRequest.Result? {
|
||||
public static func install(forceUpdate: Bool = false, inBackground _: Bool = false) async throws -> OSSystemExtensionRequest.Result? {
|
||||
try await Task.detached {
|
||||
try SystemExtension(forceUpdate: forceUpdate).submitAndWait()
|
||||
}.result.get()
|
||||
|
||||
@@ -2,11 +2,6 @@ import Foundation
|
||||
|
||||
public enum FilePath {
|
||||
public static let packageName = "io.nekohasekai.sfa"
|
||||
#if os(iOS)
|
||||
public static let httpClientName = "SFI"
|
||||
#elseif os(macOS)
|
||||
public static let httpClientName = "SFM"
|
||||
#endif
|
||||
}
|
||||
|
||||
public extension FilePath {
|
||||
|
||||
@@ -6,4 +6,10 @@ public enum Variant {
|
||||
#else
|
||||
public static let useSystemExtension = false
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
public static let applicationName = "SFI"
|
||||
#elseif os(macOS)
|
||||
public static let applicationName = "SFM"
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user