Skip to content

Commit 222b371

Browse files
committed
Fix building for Xcode 15 and 16
1 parent 97072e2 commit 222b371

18 files changed

+128
-114
lines changed

ios/MullvadVPN/AddressCacheTracker/AddressCacheTracker.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class AddressCacheTracker {
2121

2222
/// Logger.
2323
private let logger = Logger(label: "AddressCache.Tracker")
24-
private let application: UIApplication
24+
private let backgroundTaskProvider: BackgroundTaskProviding
2525

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

4747
/// Designated initializer
48-
init(application: UIApplication, apiProxy: APIQuerying, store: REST.AddressCache) {
49-
self.application = application
48+
init(backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying, store: REST.AddressCache) {
49+
self.backgroundTaskProvider = backgroundTaskProvider
5050
self.apiProxy = apiProxy
5151
self.store = store
5252
}
@@ -103,7 +103,7 @@ final class AddressCacheTracker {
103103

104104
operation.addObserver(
105105
BackgroundObserver(
106-
backgroundTaskProvider: application,
106+
backgroundTaskProvider: backgroundTaskProvider,
107107
name: "Update endpoints",
108108
cancelUponExpiration: true
109109
)

ios/MullvadVPN/AppDelegate.swift

+19-7
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
8383
let tunnelSettingsListener = TunnelSettingsListener()
8484
let tunnelSettingsUpdater = SettingsUpdater(listener: tunnelSettingsListener)
8585

86+
let backgroundTaskProvider = BackgroundTaskProvider(
87+
backgroundTimeRemaining: application.backgroundTimeRemaining,
88+
application: application
89+
)
90+
8691
relayCacheTracker = RelayCacheTracker(
8792
relayCache: ipOverrideWrapper,
88-
application: application,
93+
backgroundTaskProvider: backgroundTaskProvider,
8994
apiProxy: apiProxy
9095
)
9196

92-
addressCacheTracker = AddressCacheTracker(application: application, apiProxy: apiProxy, store: addressCache)
97+
addressCacheTracker = AddressCacheTracker(
98+
backgroundTaskProvider: backgroundTaskProvider,
99+
apiProxy: apiProxy,
100+
store: addressCache
101+
)
93102

94-
tunnelStore = TunnelStore(application: application)
103+
tunnelStore = TunnelStore(application: backgroundTaskProvider)
95104

96105
let relaySelector = RelaySelectorWrapper(
97106
relayCache: ipOverrideWrapper
98107
)
99-
tunnelManager = createTunnelManager(application: application, relaySelector: relaySelector)
108+
tunnelManager = createTunnelManager(
109+
backgroundTaskProvider: backgroundTaskProvider,
110+
relaySelector: relaySelector
111+
)
100112

101113
settingsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in
102114
tunnelSettingsListener.onNewSettings?(settings)
103115
})
104116
tunnelManager.addObserver(settingsObserver)
105117

106118
storePaymentManager = StorePaymentManager(
107-
backgroundTaskProvider: application,
119+
backgroundTaskProvider: backgroundTaskProvider,
108120
queue: .default(),
109121
apiProxy: apiProxy,
110122
accountsProxy: accountsProxy,
@@ -155,11 +167,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
155167
}
156168

157169
private func createTunnelManager(
158-
application: UIApplication,
170+
backgroundTaskProvider: BackgroundTaskProviding,
159171
relaySelector: RelaySelectorProtocol
160172
) -> TunnelManager {
161173
return TunnelManager(
162-
application: application,
174+
backgroundTaskProvider: backgroundTaskProvider,
163175
tunnelStore: tunnelStore,
164176
relayCacheTracker: relayCacheTracker,
165177
accountsProxy: accountsProxy,

ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
3434
/// Relay cache.
3535
private let cache: RelayCacheProtocol
3636

37-
private let application: UIApplication
37+
private let backgroundTaskProvider: BackgroundTaskProviding
3838

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

60-
init(relayCache: RelayCacheProtocol, application: UIApplication, apiProxy: APIQuerying) {
61-
self.application = application
60+
init(relayCache: RelayCacheProtocol, backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying) {
61+
self.backgroundTaskProvider = backgroundTaskProvider
6262
self.apiProxy = apiProxy
6363
cache = relayCache
6464

@@ -181,7 +181,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
181181

182182
operation.addObserver(
183183
BackgroundObserver(
184-
backgroundTaskProvider: application,
184+
backgroundTaskProvider: backgroundTaskProvider,
185185
name: "Update relays",
186186
cancelUponExpiration: true
187187
)

ios/MullvadVPN/StorePaymentManager/StorePaymentManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
3030
return queue
3131
}()
3232

33-
private let backgroundTaskProvider: BackgroundTaskProvider
33+
private let backgroundTaskProvider: BackgroundTaskProviding
3434
private let paymentQueue: SKPaymentQueue
3535
private let apiProxy: APIQuerying
3636
private let accountsProxy: RESTAccountHandling
@@ -57,7 +57,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
5757
/// - accountsProxy: the object implementing `RESTAccountHandling`.
5858
/// - transactionLog: an instance of transaction log. Typically ``StoreTransactionLog/default``.
5959
init(
60-
backgroundTaskProvider: BackgroundTaskProvider,
60+
backgroundTaskProvider: BackgroundTaskProviding,
6161
queue: SKPaymentQueue,
6262
apiProxy: APIQuerying,
6363
accountsProxy: RESTAccountHandling,

ios/MullvadVPN/TunnelManager/SendTunnelProviderMessageOperation.swift

+2-50
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private let defaultTimeout: Duration = .seconds(5)
2323
final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output> {
2424
typealias DecoderHandler = (Data?) throws -> Output
2525

26-
private let backgroundTaskProvider: BackgroundTaskProvider
26+
private let backgroundTaskProvider: BackgroundTaskProviding
2727
private let tunnel: any TunnelProtocol
2828
private let message: TunnelProviderMessage
2929
private let timeout: Duration
@@ -38,7 +38,7 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>
3838

3939
init(
4040
dispatchQueue: DispatchQueue,
41-
backgroundTaskProvider: BackgroundTaskProvider,
41+
backgroundTaskProvider: BackgroundTaskProviding,
4242
tunnel: any TunnelProtocol,
4343
message: TunnelProviderMessage,
4444
timeout: Duration? = nil,
@@ -215,54 +215,6 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>
215215
}
216216
}
217217

218-
extension SendTunnelProviderMessageOperation where Output: Codable {
219-
convenience init(
220-
dispatchQueue: DispatchQueue,
221-
backgroundTaskProvider: BackgroundTaskProvider,
222-
tunnel: any TunnelProtocol,
223-
message: TunnelProviderMessage,
224-
timeout: Duration? = nil,
225-
completionHandler: @escaping CompletionHandler
226-
) {
227-
self.init(
228-
dispatchQueue: dispatchQueue,
229-
backgroundTaskProvider: backgroundTaskProvider,
230-
tunnel: tunnel,
231-
message: message,
232-
timeout: timeout,
233-
decoderHandler: { data in
234-
if let data {
235-
return try TunnelProviderReply(messageData: data).value
236-
} else {
237-
throw EmptyTunnelProviderResponseError()
238-
}
239-
},
240-
completionHandler: completionHandler
241-
)
242-
}
243-
}
244-
245-
extension SendTunnelProviderMessageOperation where Output == Void {
246-
convenience init(
247-
dispatchQueue: DispatchQueue,
248-
backgroundTaskProvider: BackgroundTaskProvider,
249-
tunnel: any TunnelProtocol,
250-
message: TunnelProviderMessage,
251-
timeout: Duration? = nil,
252-
completionHandler: CompletionHandler?
253-
) {
254-
self.init(
255-
dispatchQueue: dispatchQueue,
256-
backgroundTaskProvider: backgroundTaskProvider,
257-
tunnel: tunnel,
258-
message: message,
259-
timeout: timeout,
260-
decoderHandler: { _ in () },
261-
completionHandler: completionHandler
262-
)
263-
}
264-
}
265-
266218
enum SendTunnelProviderMessageError: LocalizedError, WrappingError {
267219
/// Tunnel process is either down or about to go down.
268220
case tunnelDown(NEVPNStatus)

ios/MullvadVPN/TunnelManager/Tunnel+Messaging.swift

+21-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extension TunnelProtocol {
3232
backgroundTaskProvider: backgroundTaskProvider,
3333
tunnel: self,
3434
message: .reconnectTunnel(nextRelays),
35+
decoderHandler: { _ in () },
3536
completionHandler: completionHandler
3637
)
3738

@@ -44,16 +45,24 @@ extension TunnelProtocol {
4445
func getTunnelStatus(
4546
completionHandler: @escaping (Result<ObservedState, Error>) -> Void
4647
) -> Cancellable {
48+
let decoderHandler: (Data?) throws -> ObservedState = { data in
49+
if let data {
50+
return try TunnelProviderReply<ObservedState>(messageData: data).value
51+
} else {
52+
throw EmptyTunnelProviderResponseError()
53+
}
54+
}
55+
4756
let operation = SendTunnelProviderMessageOperation(
4857
dispatchQueue: dispatchQueue,
4958
backgroundTaskProvider: backgroundTaskProvider,
5059
tunnel: self,
5160
message: .getTunnelStatus,
61+
decoderHandler: decoderHandler,
5262
completionHandler: completionHandler
5363
)
5464

5565
operationQueue.addOperation(operation)
56-
5766
return operation
5867
}
5968

@@ -62,12 +71,21 @@ extension TunnelProtocol {
6271
_ proxyRequest: ProxyURLRequest,
6372
completionHandler: @escaping (Result<ProxyURLResponse, Error>) -> Void
6473
) -> Cancellable {
74+
let decoderHandler: (Data?) throws -> ProxyURLResponse = { data in
75+
if let data {
76+
return try TunnelProviderReply<ProxyURLResponse>(messageData: data).value
77+
} else {
78+
throw EmptyTunnelProviderResponseError()
79+
}
80+
}
81+
6582
let operation = SendTunnelProviderMessageOperation(
6683
dispatchQueue: dispatchQueue,
6784
backgroundTaskProvider: backgroundTaskProvider,
6885
tunnel: self,
6986
message: .sendURLRequest(proxyRequest),
7087
timeout: proxyRequestTimeout,
88+
decoderHandler: decoderHandler,
7189
completionHandler: completionHandler
7290
)
7391

@@ -79,6 +97,7 @@ extension TunnelProtocol {
7997
backgroundTaskProvider: backgroundTaskProvider,
8098
tunnel: self,
8199
message: .cancelURLRequest(proxyRequest.id),
100+
decoderHandler: decoderHandler,
82101
completionHandler: nil
83102
)
84103

@@ -99,6 +118,7 @@ extension TunnelProtocol {
99118
backgroundTaskProvider: backgroundTaskProvider,
100119
tunnel: self,
101120
message: .privateKeyRotation,
121+
decoderHandler: { _ in () },
102122
completionHandler: completionHandler
103123
)
104124

ios/MullvadVPN/TunnelManager/Tunnel.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ protocol TunnelProtocol: AnyObject {
2626
var status: NEVPNStatus { get }
2727
var isOnDemandEnabled: Bool { get set }
2828
var startDate: Date? { get }
29-
var backgroundTaskProvider: BackgroundTaskProvider { get }
29+
var backgroundTaskProvider: BackgroundTaskProviding { get }
3030

31-
init(tunnelProvider: TunnelManagerProtocol, backgroundTaskProvider: BackgroundTaskProvider)
31+
init(tunnelProvider: TunnelManagerProtocol, backgroundTaskProvider: BackgroundTaskProviding)
3232

3333
func addObserver(_ observer: any TunnelStatusObserver)
3434
func removeObserver(_ observer: any TunnelStatusObserver)
@@ -53,7 +53,7 @@ final class Tunnel: TunnelProtocol, Equatable {
5353
/// Unique identifier assigned to instance at the time of creation.
5454
let identifier = UUID()
5555

56-
var backgroundTaskProvider: any BackgroundTaskProvider
56+
var backgroundTaskProvider: BackgroundTaskProviding
5757

5858
#if DEBUG
5959
/// System VPN configuration identifier.
@@ -117,7 +117,7 @@ final class Tunnel: TunnelProtocol, Equatable {
117117
private var _startDate: Date?
118118
internal let tunnelProvider: TunnelProviderManagerType
119119

120-
init(tunnelProvider: TunnelProviderManagerType, backgroundTaskProvider: BackgroundTaskProvider) {
120+
init(tunnelProvider: TunnelProviderManagerType, backgroundTaskProvider: BackgroundTaskProviding) {
121121
self.tunnelProvider = tunnelProvider
122122
self.backgroundTaskProvider = backgroundTaskProvider
123123

ios/MullvadVPN/TunnelManager/TunnelInteractor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protocol TunnelInteractor {
1616
// MARK: - Tunnel manipulation
1717

1818
var tunnel: (any TunnelProtocol)? { get }
19-
var backgroundTaskProvider: any BackgroundTaskProvider { get }
19+
var backgroundTaskProvider: BackgroundTaskProviding { get }
2020

2121
func getPersistentTunnels() -> [any TunnelProtocol]
2222
func createNewTunnel() -> any TunnelProtocol

0 commit comments

Comments
 (0)