Move ProfileKey to separate file

This commit is contained in:
Davide De Rosa 2018-11-06 11:08:15 +01:00
parent 389746180b
commit c7cb00f679
4 changed files with 69 additions and 39 deletions

View File

@ -382,14 +382,14 @@ extension OrganizerViewController {
return ids
}
private func profileKey(at indexPath: IndexPath) -> ConnectionService.ProfileKey {
private func profileKey(at indexPath: IndexPath) -> ProfileKey {
let section = model.section(for: indexPath.section)
switch section {
case .providers:
return ConnectionService.ProfileKey(.provider, providers[indexPath.row])
return ProfileKey(.provider, providers[indexPath.row])
case .hosts:
return ConnectionService.ProfileKey(.host, hosts[indexPath.row])
return ProfileKey(.host, hosts[indexPath.row])
default:
fatalError("Profile found in unexpected section: \(section)")
@ -450,7 +450,7 @@ extension OrganizerViewController: ConnectionServiceDelegate {
tableView.reloadData()
}
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey) {
func connectionService(didRemoveProfileWithKey key: ProfileKey) {
TransientStore.shared.serialize(withProfiles: false) // delete
splitViewController?.serviceViewController?.hideProfileIfDeleted()

View File

@ -41,6 +41,7 @@
0E6BE13A20CFB76800A6DD36 /* ApplicationError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13920CFB76800A6DD36 /* ApplicationError.swift */; };
0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */; };
0E79D13F21919EC900BB5FB2 /* PlaceholderConnectionProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E79D13E21919EC900BB5FB2 /* PlaceholderConnectionProfile.swift */; };
0E79D14121919F5600BB5FB2 /* ProfileKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E79D14021919F5600BB5FB2 /* ProfileKey.swift */; };
0E89DFC5213DF7AE00741BA1 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFC4213DF7AE00741BA1 /* Preferences.swift */; };
0E89DFC8213E8FC500741BA1 /* SessionProxy+Communication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */; };
0E89DFCE213EEDFA00741BA1 /* WizardProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */; };
@ -164,6 +165,7 @@
0E6BE13920CFB76800A6DD36 /* ApplicationError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationError.swift; sourceTree = "<group>"; };
0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugLogViewController.swift; sourceTree = "<group>"; };
0E79D13E21919EC900BB5FB2 /* PlaceholderConnectionProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceholderConnectionProfile.swift; sourceTree = "<group>"; };
0E79D14021919F5600BB5FB2 /* ProfileKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileKey.swift; sourceTree = "<group>"; };
0E89DFC4213DF7AE00741BA1 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+Communication.swift"; sourceTree = "<group>"; };
0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardProviderViewController.swift; sourceTree = "<group>"; };
@ -371,6 +373,7 @@
children = (
0EBE3AA3213DC1B000BFA2F5 /* HostConnectionProfile.swift */,
0E79D13E21919EC900BB5FB2 /* PlaceholderConnectionProfile.swift */,
0E79D14021919F5600BB5FB2 /* ProfileKey.swift */,
0EBE3AA4213DC1B000BFA2F5 /* ProviderConnectionProfile.swift */,
);
path = Profiles;
@ -837,6 +840,7 @@
0E39BCF3214DA9310035E9DE /* AppConstants.swift in Sources */,
0E05C5D620D1645F006EE732 /* SwiftGen+Scenes.swift in Sources */,
0E2B494220FD16540094784C /* TransientStore.swift in Sources */,
0E79D14121919F5600BB5FB2 /* ProfileKey.swift in Sources */,
0E89DFC5213DF7AE00741BA1 /* Preferences.swift in Sources */,
0E6BE13A20CFB76800A6DD36 /* ApplicationError.swift in Sources */,
0EFD9440215BED8E00529B64 /* LabelViewController.swift in Sources */,

View File

@ -35,7 +35,7 @@ protocol ConnectionServiceDelegate: class {
func connectionService(didRename oldProfile: ConnectionProfile, to newProfile: ConnectionProfile)
func connectionService(didRemoveProfileWithKey key: ConnectionService.ProfileKey)
func connectionService(didRemoveProfileWithKey key: ProfileKey)
func connectionService(willDeactivate profile: ConnectionProfile)
@ -55,40 +55,6 @@ class ConnectionService: Codable {
case preferences
}
struct ProfileKey: RawRepresentable, Hashable, Codable {
let context: Context
let id: String
init(_ context: Context, _ id: String) {
self.context = context
self.id = id
}
init(_ profile: ConnectionProfile) {
context = profile.context
id = profile.id
}
// MARK: RawRepresentable
var rawValue: String {
return "\(context).\(id)"
}
init?(rawValue: String) {
let comps = rawValue.components(separatedBy: ".")
guard comps.count == 2 else {
return nil
}
guard let context = Context(rawValue: comps[0]) else {
return nil
}
self.context = context
id = comps[1]
}
}
var directory: String? = nil
var rootURL: URL {

View File

@ -0,0 +1,60 @@
//
// ProfileKey.swift
// Passepartout
//
// Created by Davide De Rosa on 11/6/18.
// Copyright (c) 2018 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Passepartout is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
import Foundation
struct ProfileKey: RawRepresentable, Hashable, Codable {
let context: Context
let id: String
init(_ context: Context, _ id: String) {
self.context = context
self.id = id
}
init(_ profile: ConnectionProfile) {
context = profile.context
id = profile.id
}
// MARK: RawRepresentable
var rawValue: String {
return "\(context).\(id)"
}
init?(rawValue: String) {
let comps = rawValue.components(separatedBy: ".")
guard comps.count == 2 else {
return nil
}
guard let context = Context(rawValue: comps[0]) else {
return nil
}
self.context = context
id = comps[1]
}
}