Skip to content

Commit

Permalink
Fix building for Xcode 15 and 16
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Nov 1, 2024
1 parent 74d4fd9 commit 993b284
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 148 deletions.
8 changes: 4 additions & 4 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@
A9D9A4D42C36E1EA004088DD /* mullvad_rust_runtime.h in Headers */ = {isa = PBXBuildFile; fileRef = A9D9A4D32C36E1EA004088DD /* mullvad_rust_runtime.h */; settings = {ATTRIBUTES = (Private, ); }; };
A9DF789B2B7D1DF10094E4AD /* mullvad-api.h in Headers */ = {isa = PBXBuildFile; fileRef = 01EF6F2D2B6A51B100125696 /* mullvad-api.h */; settings = {ATTRIBUTES = (Private, ); }; };
A9DF789D2B7D1E8B0094E4AD /* LoggedInWithTimeUITestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 859089692B61763B003AF5F5 /* LoggedInWithTimeUITestCase.swift */; };
A9E031782ACB09930095D843 /* UIApplication+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E031762ACB08950095D843 /* UIApplication+Extensions.swift */; };
A9E031782ACB09930095D843 /* BackgroundTaskProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E031762ACB08950095D843 /* BackgroundTaskProvider.swift */; };
A9E0317A2ACB0AE70095D843 /* UIApplication+Stubs.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E031792ACB0AE70095D843 /* UIApplication+Stubs.swift */; };
A9E0317F2ACC331C0095D843 /* TunnelStatusBlockObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E0317D2ACC32920095D843 /* TunnelStatusBlockObserver.swift */; };
A9E034642ABB302000E59A5A /* UIEdgeInsets+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E034632ABB302000E59A5A /* UIEdgeInsets+Extensions.swift */; };
Expand Down Expand Up @@ -2070,7 +2070,7 @@
A9D96B192A8247C100A5C673 /* MigrationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationManager.swift; sourceTree = "<group>"; };
A9D9A4C02C36D53C004088DD /* MullvadRustRuntimeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MullvadRustRuntimeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A9D9A4D32C36E1EA004088DD /* mullvad_rust_runtime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mullvad_rust_runtime.h; path = include/mullvad_rust_runtime.h; sourceTree = "<group>"; };
A9E031762ACB08950095D843 /* UIApplication+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Extensions.swift"; sourceTree = "<group>"; };
A9E031762ACB08950095D843 /* BackgroundTaskProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundTaskProvider.swift; sourceTree = "<group>"; };
A9E031792ACB0AE70095D843 /* UIApplication+Stubs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Stubs.swift"; sourceTree = "<group>"; };
A9E0317D2ACC32920095D843 /* TunnelStatusBlockObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelStatusBlockObserver.swift; sourceTree = "<group>"; };
A9E034632ABB302000E59A5A /* UIEdgeInsets+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIEdgeInsets+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2686,7 +2686,7 @@
44BB5F962BE527F4002520EB /* TunnelState+UI.swift */,
A9E0317D2ACC32920095D843 /* TunnelStatusBlockObserver.swift */,
5803B4B12940A48700C23744 /* TunnelStore.swift */,
A9E031762ACB08950095D843 /* UIApplication+Extensions.swift */,
A9E031762ACB08950095D843 /* BackgroundTaskProvider.swift */,
5842102F282D8A3C00F24E46 /* UpdateAccountDataOperation.swift */,
58421031282E42B000F24E46 /* UpdateDeviceDataOperation.swift */,
A9F360332AAB626300F53531 /* VPNConnectionProtocol.swift */,
Expand Down Expand Up @@ -6041,7 +6041,7 @@
58D2240A294C90210029F5F8 /* IPAddress+Codable.swift in Sources */,
58E45A5729F12C5100281ECF /* Result+Extensions.swift in Sources */,
A90C48672C36BC2600DCB94C /* EphemeralPeerReceiver.swift in Sources */,
A9E031782ACB09930095D843 /* UIApplication+Extensions.swift in Sources */,
A9E031782ACB09930095D843 /* BackgroundTaskProvider.swift in Sources */,
58D2240B294C90210029F5F8 /* Cancellable.swift in Sources */,
58D2240C294C90210029F5F8 /* WrappingError.swift in Sources */,
A9A8A8EB2A262AB30086D569 /* FileCache.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadVPN/AddressCacheTracker/AddressCacheTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class AddressCacheTracker {

/// Logger.
private let logger = Logger(label: "AddressCache.Tracker")
private let application: UIApplication
private let backgroundTaskProvider: BackgroundTaskProviding

/// REST API proxy.
private let apiProxy: APIQuerying
Expand All @@ -45,8 +45,8 @@ final class AddressCacheTracker {
private let nslock = NSLock()

/// Designated initializer
init(application: UIApplication, apiProxy: APIQuerying, store: REST.AddressCache) {
self.application = application
init(backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying, store: REST.AddressCache) {
self.backgroundTaskProvider = backgroundTaskProvider
self.apiProxy = apiProxy
self.store = store
}
Expand Down Expand Up @@ -103,7 +103,7 @@ final class AddressCacheTracker {

operation.addObserver(
BackgroundObserver(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
name: "Update endpoints",
cancelUponExpiration: true
)
Expand Down
26 changes: 19 additions & 7 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let tunnelSettingsListener = TunnelSettingsListener()
let tunnelSettingsUpdater = SettingsUpdater(listener: tunnelSettingsListener)

let backgroundTaskProvider = BackgroundTaskProvider(
backgroundTimeRemaining: application.backgroundTimeRemaining,
application: application
)

relayCacheTracker = RelayCacheTracker(
relayCache: ipOverrideWrapper,
application: application,
backgroundTaskProvider: backgroundTaskProvider,
apiProxy: apiProxy
)

addressCacheTracker = AddressCacheTracker(application: application, apiProxy: apiProxy, store: addressCache)
addressCacheTracker = AddressCacheTracker(
backgroundTaskProvider: backgroundTaskProvider,
apiProxy: apiProxy,
store: addressCache
)

tunnelStore = TunnelStore(application: application)
tunnelStore = TunnelStore(application: backgroundTaskProvider)

let relaySelector = RelaySelectorWrapper(
relayCache: ipOverrideWrapper
)
tunnelManager = createTunnelManager(application: application, relaySelector: relaySelector)
tunnelManager = createTunnelManager(
backgroundTaskProvider: backgroundTaskProvider,
relaySelector: relaySelector
)

settingsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in
tunnelSettingsListener.onNewSettings?(settings)
})
tunnelManager.addObserver(settingsObserver)

storePaymentManager = StorePaymentManager(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
queue: .default(),
apiProxy: apiProxy,
accountsProxy: accountsProxy,
Expand Down Expand Up @@ -155,11 +167,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

private func createTunnelManager(
application: UIApplication,
backgroundTaskProvider: BackgroundTaskProviding,
relaySelector: RelaySelectorProtocol
) -> TunnelManager {
return TunnelManager(
application: application,
backgroundTaskProvider: backgroundTaskProvider,
tunnelStore: tunnelStore,
relayCacheTracker: relayCacheTracker,
accountsProxy: accountsProxy,
Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
/// Relay cache.
private let cache: RelayCacheProtocol

private let application: UIApplication
private let backgroundTaskProvider: BackgroundTaskProviding

/// Lock used for synchronization.
private let relayCacheLock = NSLock()
Expand All @@ -57,8 +57,8 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
/// Memory cache.
private var cachedRelays: CachedRelays?

init(relayCache: RelayCacheProtocol, application: UIApplication, apiProxy: APIQuerying) {
self.application = application
init(relayCache: RelayCacheProtocol, backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying) {
self.backgroundTaskProvider = backgroundTaskProvider
self.apiProxy = apiProxy
cache = relayCache

Expand Down Expand Up @@ -181,7 +181,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {

operation.addObserver(
BackgroundObserver(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
name: "Update relays",
cancelUponExpiration: true
)
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPN/StorePaymentManager/StorePaymentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
return queue
}()

private let backgroundTaskProvider: BackgroundTaskProvider
private let backgroundTaskProvider: BackgroundTaskProviding
private let paymentQueue: SKPaymentQueue
private let apiProxy: APIQuerying
private let accountsProxy: RESTAccountHandling
Expand All @@ -57,7 +57,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
/// - accountsProxy: the object implementing `RESTAccountHandling`.
/// - transactionLog: an instance of transaction log. Typically ``StoreTransactionLog/default``.
init(
backgroundTaskProvider: BackgroundTaskProvider,
backgroundTaskProvider: BackgroundTaskProviding,
queue: SKPaymentQueue,
apiProxy: APIQuerying,
accountsProxy: RESTAccountHandling,
Expand Down
64 changes: 64 additions & 0 deletions ios/MullvadVPN/TunnelManager/BackgroundTaskProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// BackgroundTaskProvider.swift
// MullvadVPN
//
// Created by Marco Nikic on 2023-10-02.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

#if canImport(UIKit)

import Foundation
import UIKit

@available(iOSApplicationExtension, unavailable)
public protocol BackgroundTaskProviding {
var backgroundTimeRemaining: TimeInterval { get }
#if compiler(>=6)
nonisolated
func beginBackgroundTask(
withName taskName: String?,
expirationHandler handler: (@MainActor @Sendable () -> Void)?
) -> UIBackgroundTaskIdentifier
#else
func beginBackgroundTask(
withName taskName: String?,
expirationHandler handler: (() -> Void)?
) -> UIBackgroundTaskIdentifier
#endif

func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier)
}

@available(iOSApplicationExtension, unavailable)
public class BackgroundTaskProvider: BackgroundTaskProviding {
public var backgroundTimeRemaining: TimeInterval
weak var application: UIApplication!

public init(backgroundTimeRemaining: TimeInterval, application: UIApplication) {
self.backgroundTimeRemaining = backgroundTimeRemaining
self.application = application
}

#if compiler(>=6)
nonisolated
public func beginBackgroundTask(
withName taskName: String?,
expirationHandler handler: (@MainActor @Sendable () -> Void)?
) -> UIBackgroundTaskIdentifier {
application.beginBackgroundTask(withName: taskName, expirationHandler: handler)
}
#else
public func beginBackgroundTask(
withName taskName: String?,
expirationHandler handler: (() -> Void)?
) -> UIBackgroundTaskIdentifier {
application.beginBackgroundTask(withName: taskName, expirationHandler: handler)
}
#endif

public func endBackgroundTask(_ identifier: UIBackgroundTaskIdentifier) {
application.endBackgroundTask(identifier)
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private let defaultTimeout: Duration = .seconds(5)
final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output> {
typealias DecoderHandler = (Data?) throws -> Output

private let backgroundTaskProvider: BackgroundTaskProvider
private let backgroundTaskProvider: BackgroundTaskProviding
private let tunnel: any TunnelProtocol
private let message: TunnelProviderMessage
private let timeout: Duration
Expand All @@ -38,7 +38,7 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>

init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
backgroundTaskProvider: BackgroundTaskProviding,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
Expand Down Expand Up @@ -215,54 +215,6 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>
}
}

extension SendTunnelProviderMessageOperation where Output: Codable {
convenience init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
completionHandler: @escaping CompletionHandler
) {
self.init(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: tunnel,
message: message,
timeout: timeout,
decoderHandler: { data in
if let data {
return try TunnelProviderReply(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
},
completionHandler: completionHandler
)
}
}

extension SendTunnelProviderMessageOperation where Output == Void {
convenience init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
completionHandler: CompletionHandler?
) {
self.init(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: tunnel,
message: message,
timeout: timeout,
decoderHandler: { _ in () },
completionHandler: completionHandler
)
}
}

enum SendTunnelProviderMessageError: LocalizedError, WrappingError {
/// Tunnel process is either down or about to go down.
case tunnelDown(NEVPNStatus)
Expand Down
22 changes: 21 additions & 1 deletion ios/MullvadVPN/TunnelManager/Tunnel+Messaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .reconnectTunnel(nextRelays),
decoderHandler: { _ in () },
completionHandler: completionHandler
)

Expand All @@ -44,16 +45,24 @@ extension TunnelProtocol {
func getTunnelStatus(
completionHandler: @escaping (Result<ObservedState, Error>) -> Void
) -> Cancellable {
let decoderHandler: (Data?) throws -> ObservedState = { data in
if let data {
return try TunnelProviderReply<ObservedState>(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
}

let operation = SendTunnelProviderMessageOperation(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .getTunnelStatus,
decoderHandler: decoderHandler,
completionHandler: completionHandler
)

operationQueue.addOperation(operation)

return operation
}

Expand All @@ -62,12 +71,21 @@ extension TunnelProtocol {
_ proxyRequest: ProxyURLRequest,
completionHandler: @escaping (Result<ProxyURLResponse, Error>) -> Void
) -> Cancellable {
let decoderHandler: (Data?) throws -> ProxyURLResponse = { data in
if let data {
return try TunnelProviderReply<ProxyURLResponse>(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
}

let operation = SendTunnelProviderMessageOperation(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .sendURLRequest(proxyRequest),
timeout: proxyRequestTimeout,
decoderHandler: decoderHandler,
completionHandler: completionHandler
)

Expand All @@ -79,6 +97,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .cancelURLRequest(proxyRequest.id),
decoderHandler: decoderHandler,
completionHandler: nil
)

Expand All @@ -99,6 +118,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .privateKeyRotation,
decoderHandler: { _ in () },
completionHandler: completionHandler
)

Expand Down
Loading

0 comments on commit 993b284

Please sign in to comment.