Finish independent macOS version

This commit is contained in:
世界
2023-07-25 14:04:13 +08:00
parent 12bf02070e
commit 486a685bb5
12 changed files with 147 additions and 98 deletions
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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 "
+23 -13
View File
@@ -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()