Fix Swift 6 isolation: hop to @MainActor inside Timer callback for EOSE tracker mutations

This commit is contained in:
jack
2025-09-13 11:53:19 +02:00
parent fecebb05d5
commit 5bf28e5ba4
2 changed files with 11 additions and 6 deletions
+2
View File
@@ -264,6 +264,7 @@ final class NostrRelayManager: ObservableObject {
var tracker = EOSETracker(pendingRelays: Set(urls), callback: onEOSE, timer: nil) var tracker = EOSETracker(pendingRelays: Set(urls), callback: onEOSE, timer: nil)
// Fallback timeout to avoid hanging if a relay never sends EOSE // Fallback timeout to avoid hanging if a relay never sends EOSE
tracker.timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { [weak self] _ in tracker.timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { [weak self] _ in
Task { @MainActor in
guard let self = self else { return } guard let self = self else { return }
if let t = self.eoseTrackers[id] { if let t = self.eoseTrackers[id] {
t.timer?.invalidate() t.timer?.invalidate()
@@ -271,6 +272,7 @@ final class NostrRelayManager: ObservableObject {
onEOSE() onEOSE()
} }
} }
}
eoseTrackers[id] = tracker eoseTrackers[id] = tracker
} }
SecureLogger.debug("📋 Queued subscription id=\(id) for \(urls.count) relay(s)", category: .session) SecureLogger.debug("📋 Queued subscription id=\(id) for \(urls.count) relay(s)", category: .session)
+4 -1
View File
@@ -1183,7 +1183,7 @@ struct ContentView: View {
notesGeohash = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash notesGeohash = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .block })?.geohash
showLocationNotes = true showLocationNotes = true
}) { }) {
HStack(spacing: 4) { HStack(alignment: .center, spacing: 4) {
Image(systemName: "long.text.page.and.pencil") Image(systemName: "long.text.page.and.pencil")
.font(.system(size: 12)) .font(.system(size: 12))
.foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82)) .foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82))
@@ -1191,8 +1191,11 @@ struct ContentView: View {
Text("\(c)") Text("\(c)")
.font(.system(size: 11, design: .monospaced)) .font(.system(size: 11, design: .monospaced))
.foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82)) .foregroundColor(Color(hue: 0.60, saturation: 0.85, brightness: 0.82))
.lineLimit(1)
.fixedSize(horizontal: true, vertical: false)
} }
} }
.fixedSize(horizontal: true, vertical: false)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.accessibilityLabel("Location notes for this place") .accessibilityLabel("Location notes for this place")