Minor fixes

This commit is contained in:
世界
2024-09-12 11:55:21 +08:00
parent 31d63f40b0
commit 20f70a5a6c
@@ -75,11 +75,26 @@
private func reset() { private func reset() {
selected = false selected = false
profiles = nil profiles = nil
if let connection = connection {
connection.cancel()
self.connection = nil
}
} }
private func handleEndpoint(_ endpoint: NWEndpoint) async { private func handleEndpoint(_ endpoint: NWEndpoint) async {
let connection = NWConnection(to: endpoint, using: NWParameters.applicationService) let connection = NWConnection(to: endpoint, using: NWParameters.applicationService)
self.connection = NWSocket(connection) self.connection = NWSocket(connection)
connection.stateUpdateHandler = { state in
switch state {
case .failed(let error):
DispatchQueue.main.async { [self] in
reset()
alert = Alert(error)
}
default: break
}
}
connection.start(queue: .global()) connection.start(queue: .global())
do { do {
try await loopMessages() try await loopMessages()
@@ -176,6 +191,7 @@
lastUpdated = Date(timeIntervalSince1970: Double(content.lastUpdated)) lastUpdated = Date(timeIntervalSince1970: Double(content.lastUpdated))
} }
try await ProfileManager.create(Profile(name: content.name, type: type, path: profileConfig.relativePath, remoteURL: content.remotePath, autoUpdate: content.autoUpdate, lastUpdated: lastUpdated)) try await ProfileManager.create(Profile(name: content.name, type: type, path: profileConfig.relativePath, remoteURL: content.remotePath, autoUpdate: content.autoUpdate, lastUpdated: lastUpdated))
await reset()
await callback() await callback()
await MainActor.run { await MainActor.run {
dismiss() dismiss()