mirror of
https://github.com/pawelorzech/MacTorn.git
synced 2026-01-30 04:04:27 +00:00
fix: Resolve Swift concurrency errors by extracting MainActor functions
Extract watchlist mutations into dedicated @MainActor functions to avoid actor-isolated property access issues in async context. This fixes CI build failures caused by strict concurrency checking.
This commit is contained in:
parent
9724bcbacb
commit
e10add9474
1 changed files with 20 additions and 18 deletions
|
|
@ -300,23 +300,11 @@ class AppState: ObservableObject {
|
||||||
let sortedListings = allListings.sorted { $0.price < $1.price }
|
let sortedListings = allListings.sorted { $0.price < $1.price }
|
||||||
logger.debug("Item \(itemId): found \(sortedListings.count) listings, lowest: \(sortedListings.first?.price ?? 0)")
|
logger.debug("Item \(itemId): found \(sortedListings.count) listings, lowest: \(sortedListings.first?.price ?? 0)")
|
||||||
|
|
||||||
await MainActor.run {
|
if let best = sortedListings.first {
|
||||||
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {
|
let secondPrice = sortedListings.count > 1 ? sortedListings[1].price : 0
|
||||||
if let best = sortedListings.first {
|
await updateItemPrice(itemId: itemId, lowestPrice: best.price, lowestPriceQuantity: best.amount, secondLowestPrice: secondPrice)
|
||||||
var item = watchlistItems[index]
|
} else {
|
||||||
item.lowestPrice = best.price
|
await updateItemError(itemId: itemId, error: "No listings")
|
||||||
item.lowestPriceQuantity = best.amount
|
|
||||||
item.secondLowestPrice = sortedListings.count > 1 ? sortedListings[1].price : 0
|
|
||||||
item.lastUpdated = Date()
|
|
||||||
item.error = nil
|
|
||||||
watchlistItems[index] = item
|
|
||||||
} else {
|
|
||||||
var item = watchlistItems[index]
|
|
||||||
item.error = "No listings"
|
|
||||||
watchlistItems[index] = item
|
|
||||||
}
|
|
||||||
saveWatchlist()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -325,6 +313,20 @@ class AppState: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
private func updateItemPrice(itemId: Int, lowestPrice: Int, lowestPriceQuantity: Int, secondLowestPrice: Int) {
|
||||||
|
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {
|
||||||
|
var item = watchlistItems[index]
|
||||||
|
item.lowestPrice = lowestPrice
|
||||||
|
item.lowestPriceQuantity = lowestPriceQuantity
|
||||||
|
item.secondLowestPrice = secondLowestPrice
|
||||||
|
item.lastUpdated = Date()
|
||||||
|
item.error = nil
|
||||||
|
watchlistItems[index] = item
|
||||||
|
saveWatchlist()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func updateItemError(itemId: Int, error: String) {
|
private func updateItemError(itemId: Int, error: String) {
|
||||||
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {
|
if let index = watchlistItems.firstIndex(where: { $0.id == itemId }) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue