Check and clear old configs on app start and app foreground.
This commit is contained in:
parent
65220e8d81
commit
07be1c5398
|
@ -14,8 +14,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
|
||||||
self.window = UIWindow(frame: UIScreen.main.bounds)
|
self.window = UIWindow(frame: UIScreen.main.bounds)
|
||||||
self.appCoordinator = AppCoordinator(window: self.window!)
|
appCoordinator = AppCoordinator(window: self.window!)
|
||||||
self.appCoordinator.start()
|
appCoordinator.start()
|
||||||
|
|
||||||
|
appCoordinator.checkAndCleanConfigs()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -48,4 +50,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
return false
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||||
|
appCoordinator.checkAndCleanConfigs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,42 @@ class AppCoordinator: RootViewCoordinator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkAndCleanConfigs() {
|
||||||
|
_ = refreshProviderManagers().then { () -> Promise<Void> in
|
||||||
|
guard let providerManagers = self.providerManagers else {
|
||||||
|
return Promise.value(())
|
||||||
|
}
|
||||||
|
let tunnels = try Tunnel.allInContext(self.persistentContainer.viewContext)
|
||||||
|
let tunnelIdentifiers = tunnels.compactMap {$0.tunnelIdentifier}
|
||||||
|
|
||||||
|
let unknownManagers = providerManagers.filter {
|
||||||
|
guard let prot = $0.protocolConfiguration as? NETunnelProviderProtocol else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
guard let candidateTunnelIdentifier = prot.providerConfiguration?[PCKeys.tunnelIdentifier.rawValue] as? String else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return !tunnelIdentifiers.contains(candidateTunnelIdentifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
let deletionPromises = unknownManagers.map({ (manager) -> Promise<NETunnelProviderManager> in
|
||||||
|
return Promise(resolver: { resolver in
|
||||||
|
return manager.removeFromPreferences(completionHandler: { (error) in
|
||||||
|
if let error = error {
|
||||||
|
resolver.reject(error)
|
||||||
|
} else {
|
||||||
|
resolver.fulfill(manager)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return when(resolved: deletionPromises).asVoid()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// swiftlint:disable next function_body_length
|
// swiftlint:disable next function_body_length
|
||||||
func exportConfigs(sourceView: UIView) {
|
func exportConfigs(sourceView: UIView) {
|
||||||
guard let path = FileManager.default
|
guard let path = FileManager.default
|
||||||
|
|
Loading…
Reference in New Issue