Merge branch 'refine-service-delegation'
This commit is contained in:
commit
2fe8bf92ac
|
@ -217,9 +217,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
||||||
// }
|
// }
|
||||||
tableView.endUpdates()
|
tableView.endUpdates()
|
||||||
|
|
||||||
let _ = service.removeProfile(rowProfile)
|
service.removeProfile(rowProfile)
|
||||||
splitViewController?.serviceViewController?.hideProfileIfDeleted()
|
|
||||||
TransientStore.shared.serialize() // delete
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func confirmVpnProfileDeletion() {
|
private func confirmVpnProfileDeletion() {
|
||||||
|
@ -453,15 +451,22 @@ extension OrganizerViewController: ConnectionServiceDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) {
|
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) {
|
||||||
reloadModel()
|
TransientStore.shared.serialize() // delete
|
||||||
tableView.reloadData()
|
|
||||||
|
splitViewController?.serviceViewController?.hideProfileIfDeleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionService(didDeactivate profile: ConnectionProfile) {
|
// XXX: deactivate + activate leads to a redundant serialization
|
||||||
|
|
||||||
|
func connectionService(willDeactivate profile: ConnectionProfile) {
|
||||||
|
TransientStore.shared.serialize() // deactivate
|
||||||
|
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionService(didActivate profile: ConnectionProfile) {
|
func connectionService(didActivate profile: ConnectionProfile) {
|
||||||
|
TransientStore.shared.serialize() // activate
|
||||||
|
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,6 @@ class ServiceViewController: UIViewController, TableModelHost {
|
||||||
|
|
||||||
private func activateProfile() {
|
private func activateProfile() {
|
||||||
service.activateProfile(uncheckedProfile)
|
service.activateProfile(uncheckedProfile)
|
||||||
TransientStore.shared.serialize() // activate
|
|
||||||
|
|
||||||
reloadModel()
|
reloadModel()
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
|
|
|
@ -37,9 +37,9 @@ protocol ConnectionServiceDelegate: class {
|
||||||
|
|
||||||
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey)
|
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey)
|
||||||
|
|
||||||
func connectionService(didActivate profile: ConnectionProfile)
|
func connectionService(willDeactivate profile: ConnectionProfile)
|
||||||
|
|
||||||
func connectionService(didDeactivate profile: ConnectionProfile)
|
func connectionService(didActivate profile: ConnectionProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConnectionService: Codable {
|
class ConnectionService: Codable {
|
||||||
|
@ -120,7 +120,7 @@ class ConnectionService: Codable {
|
||||||
private(set) var activeProfileKey: ProfileKey? {
|
private(set) var activeProfileKey: ProfileKey? {
|
||||||
willSet {
|
willSet {
|
||||||
if let oldProfile = activeProfile {
|
if let oldProfile = activeProfile {
|
||||||
delegate?.connectionService(didDeactivate: oldProfile)
|
delegate?.connectionService(willDeactivate: oldProfile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -342,13 +342,10 @@ class ConnectionService: Codable {
|
||||||
activeProfileKey = key
|
activeProfileKey = key
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize immediately
|
|
||||||
saveProfiles()
|
|
||||||
|
|
||||||
delegate?.connectionService(didAdd: profile)
|
delegate?.connectionService(didAdd: profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? {
|
@discardableResult func renameProfile(_ key: ProfileKey, to newId: String) -> ConnectionProfile? {
|
||||||
precondition(newId != key.id)
|
precondition(newId != key.id)
|
||||||
|
|
||||||
// WARNING: can be a placeholder
|
// WARNING: can be a placeholder
|
||||||
|
@ -381,16 +378,13 @@ class ConnectionService: Codable {
|
||||||
activeProfileKey = newKey
|
activeProfileKey = newKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialize immediately
|
|
||||||
saveProfiles()
|
|
||||||
|
|
||||||
delegate = temporaryDelegate
|
delegate = temporaryDelegate
|
||||||
delegate?.connectionService(didRename: oldProfile, to: newProfile)
|
delegate?.connectionService(didRename: oldProfile, to: newProfile)
|
||||||
|
|
||||||
return newProfile
|
return newProfile
|
||||||
}
|
}
|
||||||
|
|
||||||
func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? {
|
@discardableResult func renameProfile(_ profile: ConnectionProfile, to id: String) -> ConnectionProfile? {
|
||||||
return renameProfile(ProfileKey(profile), to: id)
|
return renameProfile(ProfileKey(profile), to: id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue