Skip to content

Commit

Permalink
PIA-887: Basic IKEv2 connection PoC (#55)
Browse files Browse the repository at this point in the history
* PIA-886: Selected region dashboard section (UI)

* PIA-886: Quick connect  dashboard section (UI)

* PIA-887: IKev2 connection PoC
  • Loading branch information
kp-laura-sempere authored Jan 8, 2024
1 parent 14d53bc commit 2b2709b
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 43 deletions.
14 changes: 12 additions & 2 deletions PIA VPN-tvOS/Dashboard/UseCases/VpnConnectionUseCase.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import Foundation
import PIALibrary

protocol VpnConnectionUseCaseType {
func connect()
Expand All @@ -16,11 +17,20 @@ class VpnConnectionUseCase: VpnConnectionUseCaseType {
}

func connect() {
// TODO: Implement
// TODO: Inject VPNProvider object
let vpnProvider = Client.providers.vpnProvider
vpnProvider.connect { error in
NSLog("Connection error: \(error)")
}
}

func disconnect() {
// TODO: Implement
// TODO: Inject VPNProvider object
let vpnProvider = Client.providers.vpnProvider
vpnProvider.disconnect { error in
NSLog("Disconnect error: \(error)")
}

}

func connect(to server: ServerType) {
Expand Down
11 changes: 10 additions & 1 deletion PIA VPN-tvOS/PIA VPN-tvOS.entitlements
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>packet-tunnel-provider</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.privateinternetaccess</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import Foundation
import SwiftUI
import PIALibrary

class RootContainerViewModel: ObservableObject {
enum State {
Expand All @@ -11,9 +12,10 @@ class RootContainerViewModel: ObservableObject {
}

@Published var state: State = .splash
@Published private var isBootstrapped: Bool = false

// TODO: Update this value from the Vpn OnBoarding installation profile screen
@AppStorage(.kOnboardingVpnProfileInstalled) var onBoardingVpnProfileInstalled = true
@AppStorage(.kOnboardingVpnProfileInstalled) var onBoardingVpnProfileInstalled = false

let accountProvider: AccountProviderType
let notificationCenter: NotificationCenterType
Expand All @@ -30,7 +32,17 @@ class RootContainerViewModel: ObservableObject {
notificationCenter.removeObserver(self)
}

func phaseDidBecomeActive() {
// Bootstrap PIALibrary preferences and settings
Bootstrapper.shared.bootstrap()
isBootstrapped = true
updateState()
}

private func updateState() {
guard isBootstrapped else {
return
}
switch (accountProvider.isLoggedIn, onBoardingVpnProfileInstalled) {
// logged in, vpn profile installed
case (true, true):
Expand All @@ -43,7 +55,12 @@ class RootContainerViewModel: ObservableObject {
state = .notActivated
}
}


}

// NotificationCenter subscriptions

extension RootContainerViewModel {
private func subscribeToAccountUpdates() {
notificationCenter.addObserver(self, selector: #selector(handleAccountDidLogin), name: .PIAAccountDidLogin, object: nil)

Expand All @@ -57,6 +74,19 @@ class RootContainerViewModel: ObservableObject {
@objc func handleAccountDidLogout() {
updateState()
}


}

extension RootContainerViewModel {
// FIXME: this method should be in the VpnProfile installation VM object
// Implemented in PIA-888
func installVpnProfile() {
let vpnProvider = Client.providers.vpnProvider
vpnProvider.install(force: true) { error in
NSLog("Install VPN profile error: \(String(describing: error))")
if error == nil {
self.onBoardingVpnProfileInstalled = true
}
}

}
}
48 changes: 34 additions & 14 deletions PIA VPN-tvOS/RootContainer/UI/RootContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,45 @@ import SwiftUI

struct RootContainerView: View {
@ObservedObject var viewModel: RootContainerViewModel
@Environment(\.scenePhase) var scenePhase

var body: some View {
switch viewModel.state {
case .splash:
VStack {
// TODO: Add Splash screen here
VStack {
switch viewModel.state {
case .splash:
VStack {
// TODO: Add Splash screen here
}
case .notActivated:
LoginFactory.makeLoginView()
case .activatedNotOnboarded:
// TODO: Replace this view with the Onboarding Vpn Profile installation view
VStack {
Text("Show Onboarding vpn installation view")
Button {
viewModel.installVpnProfile()
} label: {
Text("Install Vpn profile")
}

}
case .activated:
DashboardFactory.makeDashboardView()

}
case .notActivated:
LoginFactory.makeLoginView()
case .activatedNotOnboarded:
// TODO: Replace this view with the Onboarding Vpn Profile installation view
VStack {
Text("Show Onboarding vpn installation view")


}.onChange(of: scenePhase) { newPhase in

if newPhase == .active {
NSLog(">>> Active")
viewModel.phaseDidBecomeActive()
} else if newPhase == .inactive {
NSLog(">>> Inactive")
} else if newPhase == .background {
NSLog(">>> Background")
}
case .activated:
DashboardFactory.makeDashboardView()
}
}


}

Loading

0 comments on commit 2b2709b

Please sign in to comment.