Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIA-887: Basic IKEv2 connection PoC #55

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading