Skip to content

Commit

Permalink
Use the NETunnelProviderManager to determine whether Outline was co…
Browse files Browse the repository at this point in the history
…nnected and the launcher should launch the application.
  • Loading branch information
sbruens committed Jul 19, 2023
1 parent 8de5137 commit 179a5b0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/cordova/apple/xcode/ios/Outline.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = OutlineLauncher/OutlineLauncher.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -988,6 +989,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = OutlineLauncher/OutlineLauncher.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
Expand Down
48 changes: 30 additions & 18 deletions src/cordova/apple/xcode/ios/OutlineLauncher/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import Cocoa
import NetworkExtension
import OutlineTunnel
import UIKit

Expand All @@ -22,28 +23,39 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let appKitBundle = AppKitBundleLoader()
defer {
NSLog("Exiting...")
appKitBundle.appKitBridge!.terminate()
}

if !self.shouldLaunchMainApp() {
NSLog("Not launching, Outline not connected at shutdown")
return false
}
NSLog("Outline connected at shutdown. Launching")

guard let launcherBundleId = Bundle.main.bundleIdentifier else {
NSLog("Failed to retrieve the bundle ID for the launcher app.")
return false
self.shouldLaunchMainApp() { shouldLaunch in
defer {
NSLog("Exiting launcher...")
appKitBundle.appKitBridge!.terminate()
}
if !shouldLaunch {
NSLog("Not launching, Outline not connected at shutdown")
return
}
NSLog("Outline connected at shutdown. Launching")

guard let launcherBundleId = Bundle.main.bundleIdentifier else {
NSLog("Failed to retrieve the bundle ID for the launcher app.")
return
}
appKitBundle.appKitBridge!.loadMainApp(launcherBundleId)
}
appKitBundle.appKitBridge!.loadMainApp(launcherBundleId)
return true
}

// Returns whether the launcher should launch the main app.
private func shouldLaunchMainApp() -> Bool {
let tunnelStore = OutlineTunnelStore(appGroup: AppDelegate.kAppGroup)
return tunnelStore.status == OutlineTunnel.TunnelStatus.connected
private func shouldLaunchMainApp(completion: @escaping(Bool) -> Void) {
NETunnelProviderManager.loadAllFromPreferences() { (managers, error) in
guard error == nil, managers != nil else {
NSLog("Failed to get tunnel manager: \(String(describing: error))")
return completion(false)
}
guard let manager: NETunnelProviderManager = managers!.first, managers!.count > 0 else {
NSLog("No tunnel managers found.")
return completion(false)
}
NSLog("Tunnel manager found.")
return completion(manager.isOnDemandEnabled)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>packet-tunnel-provider</string>
<string>app-proxy-provider</string>
<string>content-filter-provider</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.application-groups</key>
Expand Down

0 comments on commit 179a5b0

Please sign in to comment.