Level up to strict Concurrency (#361)

Trigger and resolve some additional Concurrency issues.
This commit is contained in:
Davide De Rosa 2023-09-10 20:36:52 +02:00 committed by GitHub
parent c5cf0ca1d2
commit 7de000148f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 30 additions and 12 deletions

View File

@ -1898,6 +1898,7 @@
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "match Development com.algoritmico.ios.Passepartout catalyst"; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "match Development com.algoritmico.ios.Passepartout catalyst";
SUPPORTS_MACCATALYST = YES; SUPPORTS_MACCATALYST = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = targeted;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
name = Debug; name = Debug;
@ -1924,6 +1925,7 @@
PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout"; PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "match Development com.algoritmico.ios.Passepartout catalyst"; "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "match Development com.algoritmico.ios.Passepartout catalyst";
SUPPORTS_MACCATALYST = YES; SUPPORTS_MACCATALYST = YES;
SWIFT_STRICT_CONCURRENCY = targeted;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
name = Release; name = Release;

View File

@ -53,8 +53,6 @@ extension ProfileManager {
} }
extension ProviderManager { extension ProviderManager {
@MainActor
static let shared = AppContext.shared.providerManager static let shared = AppContext.shared.providerManager
} }

View File

@ -27,6 +27,7 @@ import Foundation
import Intents import Intents
import PassepartoutLibrary import PassepartoutLibrary
@MainActor
final class IntentDispatcher { final class IntentDispatcher {
private struct Groups { private struct Groups {
static let vpn = "VPN" static let vpn = "VPN"

View File

@ -26,6 +26,7 @@
import Foundation import Foundation
import PassepartoutLibrary import PassepartoutLibrary
@MainActor
protocol ProviderProfileAvailability { protocol ProviderProfileAvailability {
var profile: Profile { get } var profile: Profile { get }

View File

@ -43,6 +43,7 @@ final class MacBundleDelegate: MacMenuDelegate {
DefaultLightVPNManager() DefaultLightVPNManager()
} }
@MainActor
var utils: LightUtils { var utils: LightUtils {
DefaultLightUtils() DefaultLightUtils()
} }

View File

@ -25,7 +25,7 @@
import Combine import Combine
import Foundation import Foundation
import Intents @preconcurrency import Intents
import IntentsUI import IntentsUI
import PassepartoutLibrary import PassepartoutLibrary

View File

@ -29,6 +29,7 @@ import CoreData
import Foundation import Foundation
import PassepartoutLibrary import PassepartoutLibrary
@MainActor
final class PersistenceManager: ObservableObject { final class PersistenceManager: ObservableObject {
let store: KeyValueStore let store: KeyValueStore
@ -80,17 +81,13 @@ final class PersistenceManager: ObservableObject {
extension PersistenceManager { extension PersistenceManager {
func eraseCloudKitStore() async { func eraseCloudKitStore() async {
await MainActor.run {
isErasingCloudKitStore = true isErasingCloudKitStore = true
}
await Self.eraseCloudKitStore( await Self.eraseCloudKitStore(
fromContainerWithId: ckContainerId, fromContainerWithId: ckContainerId,
zoneId: .init(zoneName: ckCoreDataZone) zoneId: .init(zoneName: ckCoreDataZone)
) )
await MainActor.run {
isErasingCloudKitStore = false isErasingCloudKitStore = false
} }
}
// WARNING: this is not running on main actor // WARNING: this is not running on main actor
private static func eraseCloudKitStore(fromContainerWithId containerId: String, zoneId: CKRecordZone.ID) async { private static func eraseCloudKitStore(fromContainerWithId containerId: String, zoneId: CKRecordZone.ID) async {

View File

@ -27,6 +27,8 @@ import Foundation
import PassepartoutLibrary import PassepartoutLibrary
extension AddProviderView { extension AddProviderView {
@MainActor
final class ViewModel: ObservableObject { final class ViewModel: ObservableObject {
enum PendingOperation { enum PendingOperation {
case index case index

View File

@ -329,6 +329,8 @@ private struct EndpointsByAddress: Identifiable {
// MARK: - Bindings // MARK: - Bindings
private extension ObservableProfile { private extension ObservableProfile {
@MainActor
func builderBinding(providerManager: ProviderManager) -> Binding<OpenVPN.ConfigurationBuilder> { func builderBinding(providerManager: ProviderManager) -> Binding<OpenVPN.ConfigurationBuilder> {
.init { .init {
if self.value.isProvider { if self.value.isProvider {

View File

@ -120,6 +120,8 @@ private extension EndpointView.WireGuardView {
// MARK: - Bindings // MARK: - Bindings
private extension ObservableProfile { private extension ObservableProfile {
@MainActor
func builderBinding(providerManager: ProviderManager) -> Binding<WireGuard.ConfigurationBuilder> { func builderBinding(providerManager: ProviderManager) -> Binding<WireGuard.ConfigurationBuilder> {
.init { .init {
if self.value.isProvider { if self.value.isProvider {

View File

@ -103,7 +103,9 @@ private extension ProfileView.ProviderSection {
Label(L10n.Provider.Preset.title, systemImage: themeProviderPresetImage) Label(L10n.Provider.Preset.title, systemImage: themeProviderPresetImage)
.withTrailingText(currentProviderPreset) .withTrailingText(currentProviderPreset)
} }
Button(action: refreshInfrastructure) { Button {
refreshInfrastructure()
} label: {
Text(L10n.Profile.Items.Provider.Refresh.caption) Text(L10n.Profile.Items.Provider.Refresh.caption)
}.withTrailingProgress(when: isRefreshingInfrastructure) }.withTrailingProgress(when: isRefreshingInfrastructure)
} footer: { } footer: {

View File

@ -309,6 +309,8 @@ private extension ProviderLocationView.ServerListView {
// MARK: - Bindings // MARK: - Bindings
private extension ObservableProfile { private extension ObservableProfile {
@MainActor
func selectedServerBinding(providerManager: ProviderManager, isPresented: Binding<Bool>) -> Binding<ProviderServer?> { func selectedServerBinding(providerManager: ProviderManager, isPresented: Binding<Bool>) -> Binding<ProviderServer?> {
.init { .init {
guard let serverId = self.value.providerServerId else { guard let serverId = self.value.providerServerId else {

View File

@ -95,6 +95,8 @@ private extension ProviderPresetView {
// MARK: - Bindings // MARK: - Bindings
private extension ObservableProfile { private extension ObservableProfile {
@MainActor
func selectedPresetBinding(providerManager: ProviderManager) -> Binding<ProviderServer.Preset?> { func selectedPresetBinding(providerManager: ProviderManager) -> Binding<ProviderServer.Preset?> {
.init { .init {
guard let serverId = self.value.providerServerId else { guard let serverId = self.value.providerServerId else {

View File

@ -25,6 +25,7 @@
import Foundation import Foundation
@MainActor
public protocol RateLimited: AnyObject { public protocol RateLimited: AnyObject {
associatedtype ActionID: Hashable associatedtype ActionID: Hashable

View File

@ -27,6 +27,7 @@ import Combine
import Foundation import Foundation
import PassepartoutCore import PassepartoutCore
@MainActor
public final class ProviderManager: ObservableObject, RateLimited { public final class ProviderManager: ObservableObject, RateLimited {
private let localProvidersRepository: LocalProvidersRepository private let localProvidersRepository: LocalProvidersRepository

View File

@ -28,6 +28,7 @@ import PassepartoutCore
import PassepartoutProviders import PassepartoutProviders
import PassepartoutVPN import PassepartoutVPN
@MainActor
extension Profile { extension Profile {
public func providerServer(_ providerManager: ProviderManager) -> ProviderServer? { public func providerServer(_ providerManager: ProviderManager) -> ProviderServer? {
guard let serverId = providerServerId else { guard let serverId = providerServerId else {

View File

@ -133,7 +133,7 @@ extension TunnelKitVPNManagerStrategy {
} }
public func reinstate(_ parameters: VPNConfigurationParameters) async throws { public func reinstate(_ parameters: VPNConfigurationParameters) async throws {
let configuration = try vpnConfiguration(withParameters: parameters) let configuration = try await vpnConfiguration(withParameters: parameters)
guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else { guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else {
fatalError("Configuration must implement VPNProtocolProviding") fatalError("Configuration must implement VPNProtocolProviding")
} }
@ -154,7 +154,7 @@ extension TunnelKitVPNManagerStrategy {
} }
public func connect(_ parameters: VPNConfigurationParameters) async throws { public func connect(_ parameters: VPNConfigurationParameters) async throws {
let configuration = try vpnConfiguration(withParameters: parameters) let configuration = try await vpnConfiguration(withParameters: parameters)
guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else { guard let vpnType = configuration.neConfiguration as? VPNProtocolProviding else {
fatalError("Configuration must implement VPNProtocolProviding") fatalError("Configuration must implement VPNProtocolProviding")
} }
@ -301,6 +301,8 @@ private extension TunnelKitVPNManagerStrategy {
// MARK: Configuration // MARK: Configuration
private extension TunnelKitVPNManagerStrategy { private extension TunnelKitVPNManagerStrategy {
@MainActor
func vpnConfiguration(withParameters parameters: VPNConfigurationParameters) throws -> TunnelKitVPNConfiguration { func vpnConfiguration(withParameters parameters: VPNConfigurationParameters) throws -> TunnelKitVPNConfiguration {
let profile = parameters.profile let profile = parameters.profile
do { do {

View File

@ -30,6 +30,7 @@ import PassepartoutProviders
@testable import PassepartoutProvidersImpl @testable import PassepartoutProvidersImpl
import XCTest import XCTest
@MainActor
final class ProvidersTests: XCTestCase { final class ProvidersTests: XCTestCase {
private var persistence: ProvidersPersistence! private var persistence: ProvidersPersistence!