aboutsummaryrefslogtreecommitdiffstats
path: root/Sources/WireGuardApp/UI/iOS
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/WireGuardApp/UI/iOS')
-rw-r--r--Sources/WireGuardApp/UI/iOS/AppDelegate.swift28
-rw-r--r--Sources/WireGuardApp/UI/iOS/Info.plist17
-rw-r--r--Sources/WireGuardApp/UI/iOS/ViewController/MainViewController.swift33
3 files changed, 52 insertions, 26 deletions
diff --git a/Sources/WireGuardApp/UI/iOS/AppDelegate.swift b/Sources/WireGuardApp/UI/iOS/AppDelegate.swift
index fbb09c7..7623b7e 100644
--- a/Sources/WireGuardApp/UI/iOS/AppDelegate.swift
+++ b/Sources/WireGuardApp/UI/iOS/AppDelegate.swift
@@ -3,6 +3,7 @@
import UIKit
import os.log
+import AppIntents
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@@ -11,6 +12,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var mainVC: MainViewController?
var isLaunchedForSpecificAction = false
+ var tunnelsManager: TunnelsManager?
+
+ static let tunnelsManagerReadyNotificationName: Notification.Name = Notification.Name(rawValue: "com.wireguard.ios.tunnelsManagerReadyNotification")
+
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Logger.configureGlobal(tagged: "APP", withFilePath: FileManager.logFileURL?.path)
@@ -29,6 +34,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.mainVC = mainVC
+ // Create the tunnels manager, and when it's ready, inform tunnelsListVC
+ TunnelsManager.create { [weak self] result in
+ guard let self = self else { return }
+
+ switch result {
+ case .failure(let error):
+ ErrorPresenter.showErrorAlert(error: error, from: self.mainVC)
+ case .success(let tunnelsManager):
+ self.tunnelsManager = tunnelsManager
+ self.mainVC?.tunnelsListVC?.setTunnelsManager(tunnelsManager: tunnelsManager)
+
+ tunnelsManager.activationDelegate = self.mainVC
+
+ if #available(iOS 16.0, *) {
+ AppDependencyManager.shared.add(dependency: tunnelsManager)
+ }
+
+ NotificationCenter.default.post(name: AppDelegate.tunnelsManagerReadyNotificationName,
+ object: self,
+ userInfo: nil)
+ }
+ }
+
return true
}
diff --git a/Sources/WireGuardApp/UI/iOS/Info.plist b/Sources/WireGuardApp/UI/iOS/Info.plist
index 7d91077..bfe758d 100644
--- a/Sources/WireGuardApp/UI/iOS/Info.plist
+++ b/Sources/WireGuardApp/UI/iOS/Info.plist
@@ -2,10 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>ITSAppUsesNonExemptEncryption</key>
- <false/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
+ <key>CFBundleDisplayName</key>
+ <string>$(PRODUCT_NAME)</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
@@ -64,8 +64,6 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
- <key>CFBundleDisplayName</key>
- <string>$(PRODUCT_NAME)</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
@@ -74,17 +72,22 @@
<string>$(VERSION_NAME)</string>
<key>CFBundleVersion</key>
<string>$(VERSION_ID)</string>
+ <key>ITSAppUsesNonExemptEncryption</key>
+ <false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>NSCameraUsageDescription</key>
<string>Localized</string>
+ <key>NSFaceIDUsageDescription</key>
+ <string>Localized</string>
+ <key>NSUserActivityTypes</key>
+ <array/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
- <array>
- </array>
+ <array/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
@@ -123,8 +126,6 @@
</dict>
</dict>
</array>
- <key>NSFaceIDUsageDescription</key>
- <string>Localized</string>
<key>com.wireguard.ios.app_group_id</key>
<string>group.$(APP_ID_IOS)</string>
</dict>
diff --git a/Sources/WireGuardApp/UI/iOS/ViewController/MainViewController.swift b/Sources/WireGuardApp/UI/iOS/ViewController/MainViewController.swift
index 8542296..39780f1 100644
--- a/Sources/WireGuardApp/UI/iOS/ViewController/MainViewController.swift
+++ b/Sources/WireGuardApp/UI/iOS/ViewController/MainViewController.swift
@@ -5,7 +5,9 @@ import UIKit
class MainViewController: UISplitViewController {
- var tunnelsManager: TunnelsManager?
+ var tunnelsManager: TunnelsManager? {
+ return (UIApplication.shared.delegate as? AppDelegate)?.tunnelsManager
+ }
var onTunnelsManagerReady: ((TunnelsManager) -> Void)?
var tunnelsListVC: TunnelsListTableViewController?
@@ -38,29 +40,24 @@ class MainViewController: UISplitViewController {
// On iPad, always show both masterVC and detailVC, even in portrait mode, like the Settings app
preferredDisplayMode = .allVisible
- // Create the tunnels manager, and when it's ready, inform tunnelsListVC
- TunnelsManager.create { [weak self] result in
- guard let self = self else { return }
-
- switch result {
- case .failure(let error):
- ErrorPresenter.showErrorAlert(error: error, from: self)
- case .success(let tunnelsManager):
- self.tunnelsManager = tunnelsManager
- self.tunnelsListVC?.setTunnelsManager(tunnelsManager: tunnelsManager)
-
- tunnelsManager.activationDelegate = self
-
- self.onTunnelsManagerReady?(tunnelsManager)
- self.onTunnelsManagerReady = nil
- }
- }
+ NotificationCenter.default.addObserver(self, selector: #selector(handleTunnelsManagerReady(_:)),
+ name: AppDelegate.tunnelsManagerReadyNotificationName, object: nil)
}
func allTunnelNames() -> [String]? {
guard let tunnelsManager = self.tunnelsManager else { return nil }
return tunnelsManager.mapTunnels { $0.name }
}
+
+ @objc
+ func handleTunnelsManagerReady(_ notification: Notification) {
+ guard let tunnelsManager = self.tunnelsManager else { return }
+
+ self.onTunnelsManagerReady?(tunnelsManager)
+ self.onTunnelsManagerReady = nil
+
+ NotificationCenter.default.removeObserver(self, name: AppDelegate.tunnelsManagerReadyNotificationName, object: nil)
+ }
}
extension MainViewController: TunnelsManagerActivationDelegate {