Reuse intent creation code from IntentDispatcher
This commit is contained in:
parent
d24295295a
commit
e2cd0bc7e1
|
@ -175,27 +175,27 @@ class ShortcutsAddViewController: UITableViewController, TableModelHost {
|
|||
}
|
||||
|
||||
private func addEnable() {
|
||||
addShortcut(with: EnableVPNIntent())
|
||||
addShortcut(with: IntentDispatcher.intentEnable())
|
||||
}
|
||||
|
||||
private func addDisable() {
|
||||
addShortcut(with: DisableVPNIntent())
|
||||
addShortcut(with: IntentDispatcher.intentDisable())
|
||||
}
|
||||
|
||||
private func addTrustWiFi() {
|
||||
addShortcut(with: TrustCurrentNetworkIntent())
|
||||
addShortcut(with: IntentDispatcher.intentTrustWiFi())
|
||||
}
|
||||
|
||||
private func addUntrustWiFi() {
|
||||
addShortcut(with: UntrustCurrentNetworkIntent())
|
||||
addShortcut(with: IntentDispatcher.intentUntrustWiFi())
|
||||
}
|
||||
|
||||
private func addTrustCellular() {
|
||||
addShortcut(with: TrustCellularNetworkIntent())
|
||||
addShortcut(with: IntentDispatcher.intentTrustCellular())
|
||||
}
|
||||
|
||||
private func addUntrustCellular() {
|
||||
addShortcut(with: UntrustCellularNetworkIntent())
|
||||
addShortcut(with: IntentDispatcher.intentUntrustCellular())
|
||||
}
|
||||
|
||||
private func addShortcut(with intent: INIntent) {
|
||||
|
|
|
@ -150,21 +150,14 @@ class ShortcutsConnectToViewController: UITableViewController, ProviderPoolViewC
|
|||
guard let host = selectedProfile as? HostConnectionProfile else {
|
||||
fatalError("Not a HostConnectionProfile")
|
||||
}
|
||||
let intent = ConnectVPNIntent()
|
||||
intent.context = host.context.rawValue
|
||||
intent.profileId = host.id
|
||||
addShortcut(with: intent)
|
||||
addShortcut(with: IntentDispatcher.intentConnect(profile: host))
|
||||
}
|
||||
|
||||
private func addMoveToLocation(pool: Pool) {
|
||||
guard let provider = selectedProfile as? ProviderConnectionProfile else {
|
||||
fatalError("Not a ProviderConnectionProfile")
|
||||
}
|
||||
let intent = MoveToLocationIntent()
|
||||
intent.providerId = provider.id
|
||||
intent.poolId = pool.id
|
||||
intent.poolName = pool.localizedName
|
||||
addShortcut(with: intent)
|
||||
addShortcut(with: IntentDispatcher.intentMoveTo(profile: provider, pool: pool))
|
||||
}
|
||||
|
||||
private func addShortcut(with intent: INIntent) {
|
||||
|
|
|
@ -41,72 +41,94 @@ public class IntentDispatcher {
|
|||
static let trust = "Trust"
|
||||
}
|
||||
|
||||
// MARK: Intents
|
||||
|
||||
public static func intentConnect(profile: ConnectionProfile) -> ConnectVPNIntent {
|
||||
let intent = ConnectVPNIntent()
|
||||
intent.context = profile.context.rawValue
|
||||
intent.profileId = profile.id
|
||||
return intent
|
||||
}
|
||||
|
||||
public static func intentMoveTo(profile: ProviderConnectionProfile, pool: Pool) -> MoveToLocationIntent {
|
||||
let intent = MoveToLocationIntent()
|
||||
intent.providerId = profile.id
|
||||
intent.poolId = pool.id
|
||||
intent.poolName = pool.localizedName
|
||||
return intent
|
||||
}
|
||||
|
||||
public static func intentEnable() -> EnableVPNIntent {
|
||||
return EnableVPNIntent()
|
||||
}
|
||||
|
||||
public static func intentDisable() -> DisableVPNIntent {
|
||||
return DisableVPNIntent()
|
||||
}
|
||||
|
||||
public static func intentTrustWiFi() -> TrustCurrentNetworkIntent {
|
||||
return TrustCurrentNetworkIntent()
|
||||
}
|
||||
|
||||
public static func intentUntrustWiFi() -> UntrustCurrentNetworkIntent {
|
||||
return UntrustCurrentNetworkIntent()
|
||||
}
|
||||
|
||||
public static func intentTrustCellular() -> TrustCellularNetworkIntent {
|
||||
return TrustCellularNetworkIntent()
|
||||
}
|
||||
|
||||
public static func intentUntrustCellular() -> UntrustCellularNetworkIntent {
|
||||
return UntrustCellularNetworkIntent()
|
||||
}
|
||||
|
||||
// MARK: Donations
|
||||
|
||||
public static func donateConnection(with profile: ConnectionProfile) {
|
||||
let profileKey = ProfileKey(profile)
|
||||
let genericIntent: INIntent
|
||||
|
||||
if let provider = profile as? ProviderConnectionProfile, let pool = provider.pool {
|
||||
let intent = MoveToLocationIntent()
|
||||
intent.providerId = profile.id
|
||||
intent.poolId = pool.id
|
||||
intent.poolName = pool.localizedName
|
||||
genericIntent = intent
|
||||
genericIntent = intentMoveTo(profile: provider, pool: pool)
|
||||
} else {
|
||||
let intent = ConnectVPNIntent()
|
||||
intent.context = profileKey.context.rawValue
|
||||
intent.profileId = profileKey.id
|
||||
genericIntent = intent
|
||||
genericIntent = intentConnect(profile: profile)
|
||||
}
|
||||
|
||||
let interaction = INInteraction(intent: genericIntent, response: nil)
|
||||
interaction.groupIdentifier = profileKey.rawValue
|
||||
interaction.groupIdentifier = ProfileKey(profile).rawValue
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateEnableVPN() {
|
||||
let intent = EnableVPNIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentEnable(), response: nil)
|
||||
interaction.groupIdentifier = Groups.vpn
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateDisableVPN() {
|
||||
let intent = DisableVPNIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentDisable(), response: nil)
|
||||
interaction.groupIdentifier = Groups.vpn
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateTrustCurrentNetwork() {
|
||||
let intent = TrustCurrentNetworkIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentTrustWiFi(), response: nil)
|
||||
interaction.groupIdentifier = Groups.trust
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateUntrustCurrentNetwork() {
|
||||
let intent = UntrustCurrentNetworkIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentUntrustWiFi(), response: nil)
|
||||
interaction.groupIdentifier = Groups.trust
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateTrustCellularNetwork() {
|
||||
let intent = TrustCellularNetworkIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentTrustCellular(), response: nil)
|
||||
interaction.groupIdentifier = Groups.trust
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
||||
public static func donateUntrustCellularNetwork() {
|
||||
let intent = UntrustCellularNetworkIntent()
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
let interaction = INInteraction(intent: intentUntrustCellular(), response: nil)
|
||||
interaction.groupIdentifier = Groups.trust
|
||||
interaction.donateAndLog()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue