Skip to content

Commit

Permalink
feat(shortcuts): update AppDelegate.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Sep 4, 2024
1 parent d2c5b0d commit 9bc236e
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 230 deletions.
8 changes: 0 additions & 8 deletions IVPNClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
8206BAFF29ED6FFF00F916B7 /* ConnectionInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206BAFE29ED6FFF00F916B7 /* ConnectionInfoView.swift */; };
8206BB0129ED7BEE00F916B7 /* ConnectionInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206BB0029ED7BEE00F916B7 /* ConnectionInfo.swift */; };
8206BB0329ED7C3700F916B7 /* ConnectionInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206BB0229ED7C3700F916B7 /* ConnectionInfoViewModel.swift */; };
8206E5D022967E37003119AF /* UserActivityType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206E5CF22967E37003119AF /* UserActivityType.swift */; };
8206E5D222967EAF003119AF /* UserActivityTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206E5D122967EAF003119AF /* UserActivityTitle.swift */; };
8206F32124347A8F0056B465 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206F32024347A8F0056B465 /* MainView.swift */; };
8206F32324367A240056B465 /* VPNErrorObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8206F32224367A240056B465 /* VPNErrorObserver.swift */; };
8208525623FD56870008C112 /* FloatingPanelMainLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8208525523FD56870008C112 /* FloatingPanelMainLayout.swift */; };
Expand Down Expand Up @@ -473,8 +471,6 @@
8206BAFE29ED6FFF00F916B7 /* ConnectionInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionInfoView.swift; sourceTree = "<group>"; };
8206BB0029ED7BEE00F916B7 /* ConnectionInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionInfo.swift; sourceTree = "<group>"; };
8206BB0229ED7C3700F916B7 /* ConnectionInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionInfoViewModel.swift; sourceTree = "<group>"; };
8206E5CF22967E37003119AF /* UserActivityType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActivityType.swift; sourceTree = "<group>"; };
8206E5D122967EAF003119AF /* UserActivityTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserActivityTitle.swift; sourceTree = "<group>"; };
8206F32024347A8F0056B465 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
8206F32224367A240056B465 /* VPNErrorObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNErrorObserver.swift; sourceTree = "<group>"; };
8208525523FD56870008C112 /* FloatingPanelMainLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingPanelMainLayout.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1198,8 +1194,6 @@
82E716832181E8E100D6B7C2 /* ProviderConfigurationKeys.swift */,
82D598B321A5A7A3000FABDE /* NetworkTrust.swift */,
82D598C721A6ADF1000FABDE /* NetworkType.swift */,
8206E5CF22967E37003119AF /* UserActivityType.swift */,
8206E5D122967EAF003119AF /* UserActivityTitle.swift */,
823FFB062338DF1800F91A5D /* Capability.swift */,
8229209F2480FA3600476FC1 /* ServersSort.swift */,
826FBDA22461847D00B9E464 /* ServiceType.swift */,
Expand Down Expand Up @@ -2291,7 +2285,6 @@
82D598BC21A6949F000FABDE /* StorageManager.swift in Sources */,
826FBDA32461847D00B9E464 /* ServiceType.swift in Sources */,
821429B922FC2EA40056B8FF /* ApiService+Ext.swift in Sources */,
8206E5D222967EAF003119AF /* UserActivityTitle.swift in Sources */,
82E716902181E90500D6B7C2 /* ConnectionSettings.swift in Sources */,
8223C54C22E9E93A00CD283D /* Session.swift in Sources */,
822563922431E03A00AE7F8D /* AccountView.swift in Sources */,
Expand Down Expand Up @@ -2364,7 +2357,6 @@
82A3422524AB6AF700761AB0 /* Double+Ext.swift in Sources */,
8221377B2227E75E001E1BF5 /* CustomDNSViewController.swift in Sources */,
9C3031351DB42EF900C38B0C /* Application.swift in Sources */,
8206E5D022967E37003119AF /* UserActivityType.swift in Sources */,
82A6D74A24A3780B00D6C0E1 /* ConnectToServerPopupView.swift in Sources */,
828772FB221C28E000D5E330 /* FlagImageView.swift in Sources */,
8228C8D22B1DE906005977D3 /* PurchaseManager.swift in Sources */,
Expand Down
124 changes: 0 additions & 124 deletions IVPNClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,99 +178,6 @@ class AppDelegate: UIResponder {
}
}

private func userActivityConnect() {
DispatchQueue.delay(0.75) {
if UserDefaults.shared.networkProtectionEnabled {
Application.shared.connectionManager.resetRulesAndConnectShortcut(closeApp: true, actionType: .connect)
return
}
Application.shared.connectionManager.connectShortcut(closeApp: true, actionType: .connect)
}
}

private func userActivityDisconnect() {
DispatchQueue.delay(0.75) {
if UserDefaults.shared.networkProtectionEnabled {
Application.shared.connectionManager.resetRulesAndDisconnectShortcut(closeApp: true, actionType: .disconnect)
return
}
Application.shared.connectionManager.disconnectShortcut(closeApp: true, actionType: .disconnect)
}
}

private func userActivityAntiTrackerEnable() {
DispatchQueue.async {
if let viewController = UIApplication.topViewController() {
if Application.shared.settings.connectionProtocol.tunnelType() == .ipsec {
viewController.showAlert(title: "IKEv2 not supported", message: "AntiTracker is supported only for OpenVPN and WireGuard protocols.") { _ in
}
return
}

UserDefaults.shared.set(true, forKey: UserDefaults.Key.isAntiTracker)
NotificationCenter.default.post(name: Notification.Name.AntiTrackerUpdated, object: nil)
if UIApplication.topViewController() as? MainViewController != nil {
NotificationCenter.default.post(name: Notification.Name.EvaluateReconnect, object: nil)
} else {
viewController.evaluateReconnect(sender: viewController.view)
}
}
}
}

private func userActivityAntiTrackerDisable() {
DispatchQueue.async {
if let viewController = UIApplication.topViewController() {
UserDefaults.shared.set(false, forKey: UserDefaults.Key.isAntiTracker)
NotificationCenter.default.post(name: Notification.Name.AntiTrackerUpdated, object: nil)
if UIApplication.topViewController() as? MainViewController != nil {
NotificationCenter.default.post(name: Notification.Name.EvaluateReconnect, object: nil)
} else {
viewController.evaluateReconnect(sender: viewController.view)
}
}
}
}

private func userActivityCustomDNSEnable() {
DispatchQueue.async {
if let viewController = UIApplication.topViewController() {
if Application.shared.settings.connectionProtocol.tunnelType() == .ipsec {
viewController.showAlert(title: "IKEv2 not supported", message: "Custom DNS is supported only for OpenVPN and WireGuard protocols.") { _ in
}
return
}

guard !UserDefaults.shared.customDNS.isEmpty else {
viewController.showAlert(title: "", message: "Please enter DNS server info")
return
}

UserDefaults.shared.set(true, forKey: UserDefaults.Key.isCustomDNS)
NotificationCenter.default.post(name: Notification.Name.CustomDNSUpdated, object: nil)
if UIApplication.topViewController() as? MainViewController != nil {
NotificationCenter.default.post(name: Notification.Name.EvaluateReconnect, object: nil)
} else {
viewController.evaluateReconnect(sender: viewController.view)
}
}
}
}

private func userActivityCustomDNSDisable() {
DispatchQueue.async {
if let viewController = UIApplication.topViewController() {
UserDefaults.shared.set(false, forKey: UserDefaults.Key.isCustomDNS)
NotificationCenter.default.post(name: Notification.Name.CustomDNSUpdated, object: nil)
if UIApplication.topViewController() as? MainViewController != nil {
NotificationCenter.default.post(name: Notification.Name.EvaluateReconnect, object: nil)
} else {
viewController.evaluateReconnect(sender: viewController.view)
}
}
}
}

private func startPurchaseObserver() {
PurchaseManager.shared.delegate = self
PurchaseManager.shared.startObserver()
Expand Down Expand Up @@ -361,37 +268,6 @@ extension AppDelegate: UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let url = userActivity.webpageURL {
let endpoint = url.lastPathComponent
handleURLEndpoint(endpoint)
return false
}

guard Application.shared.authentication.isLoggedIn, Application.shared.serviceStatus.isActive else {
return false
}

switch userActivity.activityType {
case UserActivityType.Connect:
userActivityConnect()
case UserActivityType.Disconnect:
userActivityDisconnect()
case UserActivityType.AntiTrackerEnable:
userActivityAntiTrackerEnable()
case UserActivityType.AntiTrackerDisable:
userActivityAntiTrackerDisable()
case UserActivityType.CustomDNSEnable:
userActivityCustomDNSEnable()
case UserActivityType.CustomDNSDisable:
userActivityCustomDNSDisable()
default:
log(.info, message: "No such user activity")
}

return false
}

}

// MARK: - PurchaseManagerDelegate -
Expand Down
33 changes: 0 additions & 33 deletions IVPNClient/Enums/UserActivityTitle.swift

This file was deleted.

33 changes: 0 additions & 33 deletions IVPNClient/Enums/UserActivityType.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ class ControlPanelViewController: UITableViewController {
WidgetCenter.shared.reloadTimelines(ofKind: "IVPNWidget")
evaluateReconnect(sender: sender as UIView)
controlPanelView.updateAntiTracker(viewModel: vpnStatusViewModel)

if sender.isOn {
registerUserActivity(type: UserActivityType.AntiTrackerEnable, title: UserActivityTitle.AntiTrackerEnable)
} else {
registerUserActivity(type: UserActivityType.AntiTrackerDisable, title: UserActivityTitle.AntiTrackerDisable)
}
}

@IBAction func selectIpProtocol(_ sender: UISegmentedControl) {
Expand Down Expand Up @@ -223,8 +217,6 @@ class ControlPanelViewController: UITableViewController {
manager.resetRulesAndConnect()
}

registerUserActivity(type: UserActivityType.Connect, title: UserActivityTitle.Connect)

NotificationCenter.default.removeObserver(self, name: Notification.Name.ServiceAuthorized, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil)
}
Expand All @@ -240,8 +232,6 @@ class ControlPanelViewController: UITableViewController {
manager.resetRulesAndDisconnect()
}

registerUserActivity(type: UserActivityType.Disconnect, title: UserActivityTitle.Disconnect)

DispatchQueue.delay(0.5) {
if Application.shared.connectionManager.status.isDisconnected() {
Pinger.shared.ping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class AntiTrackerViewController: UITableViewController {
antiTrackerHardcoreSwitch.isEnabled = sender.isOn
evaluateReconnect(sender: sender as UIView)
NotificationCenter.default.post(name: Notification.Name.UpdateControlPanel, object: nil)

if sender.isOn {
registerUserActivity(type: UserActivityType.AntiTrackerEnable, title: UserActivityTitle.AntiTrackerEnable)
} else {
registerUserActivity(type: UserActivityType.AntiTrackerDisable, title: UserActivityTitle.AntiTrackerDisable)
}
}

@IBAction func toggleAntiTrackerHardcore(_ sender: UISwitch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ class CustomDNSViewController: UITableViewController {

UserDefaults.shared.set(sender.isOn, forKey: UserDefaults.Key.isCustomDNS)
evaluateReconnect(sender: sender)

if sender.isOn {
registerUserActivity(type: UserActivityType.CustomDNSEnable, title: UserActivityTitle.CustomDNSEnable)
} else {
registerUserActivity(type: UserActivityType.CustomDNSDisable, title: UserActivityTitle.CustomDNSDisable)
}
}

@IBAction func enableSecureDNS(_ sender: UISwitch) {
Expand Down
10 changes: 0 additions & 10 deletions IVPNClient/Utilities/Extensions/UIViewController+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@ extension UIViewController {
openWebPage("https://www.ivpn.net/privacy-mobile-app/")
}

func registerUserActivity(type: String, title: String) {
let activity = NSUserActivity(activityType: type)
activity.title = title
activity.isEligibleForSearch = true
activity.isEligibleForPrediction = true

userActivity = activity
userActivity?.becomeCurrent()
}

func hideKeyboardOnTap() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
Expand Down

0 comments on commit 9bc236e

Please sign in to comment.