Merge branch 'refine-service-delegation'

This commit is contained in:
Davide De Rosa 2018-11-04 10:51:21 +01:00
commit 2fe8bf92ac
3 changed files with 16 additions and 18 deletions

View File

@ -217,9 +217,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
// }
tableView.endUpdates()
let _ = service.removeProfile(rowProfile)
splitViewController?.serviceViewController?.hideProfileIfDeleted()
TransientStore.shared.serialize() // delete
service.removeProfile(rowProfile)
}
private func confirmVpnProfileDeletion() {
@ -453,15 +451,22 @@ extension OrganizerViewController: ConnectionServiceDelegate {
}
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) {
reloadModel()
tableView.reloadData()
TransientStore.shared.serialize() // delete
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()
}
func connectionService(didActivate profile: ConnectionProfile) {
TransientStore.shared.serialize() // activate
tableView.reloadData()
}
}

View File

@ -186,7 +186,6 @@ class ServiceViewController: UIViewController, TableModelHost {
private func activateProfile() {
service.activateProfile(uncheckedProfile)
TransientStore.shared.serialize() // activate
reloadModel()
tableView.reloadData()

View File

@ -37,9 +37,9 @@ protocol ConnectionServiceDelegate: class {
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 {
@ -120,7 +120,7 @@ class ConnectionService: Codable {
private(set) var activeProfileKey: ProfileKey? {
willSet {
if let oldProfile = activeProfile {
delegate?.connectionService(didDeactivate: oldProfile)
delegate?.connectionService(willDeactivate: oldProfile)
}
}
didSet {
@ -342,13 +342,10 @@ class ConnectionService: Codable {
activeProfileKey = key
}
// serialize immediately
saveProfiles()
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)
// WARNING: can be a placeholder
@ -381,16 +378,13 @@ class ConnectionService: Codable {
activeProfileKey = newKey
}
// serialize immediately
saveProfiles()
delegate = temporaryDelegate
delegate?.connectionService(didRename: oldProfile, to: 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)
}