Fix main-thread blocking I/O
This commit is contained in:
@@ -193,7 +193,7 @@ public class ExtensionProfile: ObservableObject {
|
||||
])
|
||||
}
|
||||
|
||||
let configContent = try profile.read()
|
||||
let configContent = try await profile.readAsync()
|
||||
options["configContent"] = NSString(string: configContent)
|
||||
|
||||
options["ignoreMemoryLimit"] = await NSNumber(value: SharedPreferences.ignoreMemoryLimit.get())
|
||||
@@ -215,10 +215,9 @@ public class ExtensionProfile: ObservableObject {
|
||||
}
|
||||
|
||||
public func fetchProfile() async throws {
|
||||
if let profile = try await ProfileManager.get(Int64(SharedPreferences.selectedProfileID.get())) {
|
||||
if profile.type == .icloud {
|
||||
_ = try profile.read()
|
||||
}
|
||||
let profileID = await SharedPreferences.selectedProfileID.get()
|
||||
if let profile = try await ProfileManager.get(profileID), profile.type == .icloud {
|
||||
_ = try await profile.readAsync()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ public class HTTPClient {
|
||||
}
|
||||
|
||||
public func getString(_ url: String?) throws -> String {
|
||||
#if DEBUG
|
||||
precondition(!Thread.isMainThread, "HTTPClient.getString(...) must not be called on the main thread")
|
||||
#endif
|
||||
let request = client.newRequest()!
|
||||
request.setUserAgent(HTTPClient.userAgent)
|
||||
try request.setURL(url)
|
||||
@@ -32,6 +35,16 @@ public class HTTPClient {
|
||||
return content.value
|
||||
}
|
||||
|
||||
public func getStringAsync(_ url: String?) async throws -> String {
|
||||
try await Self.getStringAsync(url)
|
||||
}
|
||||
|
||||
public static func getStringAsync(_ url: String?) async throws -> String {
|
||||
try await BlockingIO.run {
|
||||
try HTTPClient().getString(url)
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
client.close()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
public class RootHelperClient {
|
||||
public class RootHelperClient: @unchecked Sendable {
|
||||
public static let shared = RootHelperClient()
|
||||
|
||||
private var connection: NSXPCConnection?
|
||||
|
||||
Reference in New Issue
Block a user