Fix a handful of strict concurrency warnings

This commit is contained in:
Shadowfacts 2024-04-13 23:06:30 -04:00
parent 216e58e5ec
commit e94bee4fc8
9 changed files with 18 additions and 13 deletions

View File

@ -53,7 +53,7 @@ public struct PushSubscription {
self.policy = policy self.policy = policy
} }
public enum Policy: String, CaseIterable, Identifiable { public enum Policy: String, CaseIterable, Identifiable, Sendable {
case all, followed, followers case all, followed, followers
public var id: some Hashable { public var id: some Hashable {
@ -61,7 +61,7 @@ public struct PushSubscription {
} }
} }
public struct Alerts: OptionSet, Hashable { public struct Alerts: OptionSet, Hashable, Sendable {
public static let mention = Alerts(rawValue: 1 << 0) public static let mention = Alerts(rawValue: 1 << 0)
public static let status = Alerts(rawValue: 1 << 1) public static let status = Alerts(rawValue: 1 << 1)
public static let reblog = Alerts(rawValue: 1 << 2) public static let reblog = Alerts(rawValue: 1 << 2)

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public struct Preferences { public struct Preferences {
@MainActor
public static let shared: PreferenceStore = load() public static let shared: PreferenceStore = load()
private static var documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! private static var documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
@ -18,6 +19,7 @@ public struct Preferences {
private init() {} private init() {}
@MainActor
public static func save() { public static func save() {
let encoder = PropertyListEncoder() let encoder = PropertyListEncoder()
let data = try? encoder.encode(PreferenceCoding(wrapped: shared)) let data = try? encoder.encode(PreferenceCoding(wrapped: shared))

View File

@ -12,7 +12,7 @@ public enum PostVisibility: Codable, Hashable, CaseIterable, Sendable {
case serverDefault case serverDefault
case visibility(Visibility) case visibility(Visibility)
public static var allCases: [PostVisibility] = [.serverDefault] + Visibility.allCases.map { .visibility($0) } public private(set) static var allCases: [PostVisibility] = [.serverDefault] + Visibility.allCases.map { .visibility($0) }
public func resolved(withServerDefault serverDefault: Visibility?) -> Visibility { public func resolved(withServerDefault serverDefault: Visibility?) -> Visibility {
switch self { switch self {
@ -57,7 +57,7 @@ public enum ReplyVisibility: Codable, Hashable, CaseIterable {
case sameAsPost case sameAsPost
case visibility(Visibility) case visibility(Visibility)
public static var allCases: [ReplyVisibility] = [.sameAsPost] + Visibility.allCases.map { .visibility($0) } public private(set) static var allCases: [ReplyVisibility] = [.sameAsPost] + Visibility.allCases.map { .visibility($0) }
@MainActor @MainActor
public func resolved(withServerDefault serverDefault: Visibility?) -> Visibility { public func resolved(withServerDefault serverDefault: Visibility?) -> Visibility {

View File

@ -8,7 +8,8 @@
import Foundation import Foundation
import Combine import Combine
public class UserAccountsManager: ObservableObject { // Sendability: UserDefaults is not marked Sendable, but is documented as being thread safe
public final class UserAccountsManager: ObservableObject, @unchecked Sendable {
public static let shared = UserAccountsManager() public static let shared = UserAccountsManager()

View File

@ -23,10 +23,10 @@ class LogoutService {
func run() { func run() {
let accountInfo = self.accountInfo let accountInfo = self.accountInfo
Task.detached { Task.detached { @MainActor in
if await PushManager.shared.pushSubscription(account: accountInfo) != nil { if PushManager.shared.pushSubscription(account: accountInfo) != nil {
_ = try? await self.mastodonController.run(Pachyderm.PushSubscription.delete()) _ = try? await self.mastodonController.run(Pachyderm.PushSubscription.delete())
await PushManager.shared.removeSubscription(account: accountInfo) PushManager.shared.removeSubscription(account: accountInfo)
} }
try? await self.mastodonController.client.revokeAccessToken() try? await self.mastodonController.client.revokeAccessToken()
} }

View File

@ -107,7 +107,7 @@ struct FlipEffect: GeometryEffect {
} }
private struct WidthPrefKey: PreferenceKey { private struct WidthPrefKey: PreferenceKey {
static var defaultValue: CGFloat = 0 static let defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue() value = nextValue()

View File

@ -292,7 +292,7 @@ private extension AttributeScopes {
private enum HeadingLevelAttributes: CodableAttributedStringKey, MarkdownDecodableAttributedStringKey { private enum HeadingLevelAttributes: CodableAttributedStringKey, MarkdownDecodableAttributedStringKey {
public typealias Value = Int public typealias Value = Int
public static var name = "headingLevel" public static let name = "headingLevel"
} }
private extension AttributeDynamicLookup { private extension AttributeDynamicLookup {

View File

@ -59,7 +59,7 @@ struct ConfettiView: View {
} }
private struct SizeKey: PreferenceKey { private struct SizeKey: PreferenceKey {
static var defaultValue: CGSize = .zero static let defaultValue: CGSize = .zero
static func reduce(value: inout CGSize, nextValue: () -> CGSize) { static func reduce(value: inout CGSize, nextValue: () -> CGSize) {
value = nextValue() value = nextValue()
} }

View File

@ -44,7 +44,7 @@ struct TipJarView: View {
Text(error.localizedDescription) Text(error.localizedDescription)
}) })
.task { .task {
updatesObserver = Task.detached { updatesObserver = Task.detached { @MainActor in
await observeTransactionUpdates() await observeTransactionUpdates()
} }
do { do {
@ -95,6 +95,7 @@ struct TipJarView: View {
} }
} }
@MainActor
private func observeTransactionUpdates() async { private func observeTransactionUpdates() async {
for await verificationResult in StoreKit.Transaction.updates { for await verificationResult in StoreKit.Transaction.updates {
guard let index = products.firstIndex(where: { $0.0.id == verificationResult.unsafePayloadValue.productID }) else { guard let index = products.firstIndex(where: { $0.0.id == verificationResult.unsafePayloadValue.productID }) else {
@ -175,6 +176,7 @@ private struct TipRow: View {
} }
} }
@MainActor
private func purchase() async { private func purchase() async {
isPurchasing = true isPurchasing = true
let result: Product.PurchaseResult let result: Product.PurchaseResult
@ -229,7 +231,7 @@ extension HorizontalAlignment {
} }
private struct ButtonWidthKey: PreferenceKey { private struct ButtonWidthKey: PreferenceKey {
static var defaultValue: CGFloat = 0 static let defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = max(value, nextValue()) value = max(value, nextValue())
} }