diff --git a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift index 6f5c92d3..43c79a83 100644 --- a/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/OrganizerViewController.swift @@ -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() diff --git a/Passepartout.xcodeproj/project.pbxproj b/Passepartout.xcodeproj/project.pbxproj index f6dd95fa..3d068de8 100644 --- a/Passepartout.xcodeproj/project.pbxproj +++ b/Passepartout.xcodeproj/project.pbxproj @@ -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 = ""; }; 0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugLogViewController.swift; sourceTree = ""; }; 0E79D13E21919EC900BB5FB2 /* PlaceholderConnectionProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceholderConnectionProfile.swift; sourceTree = ""; }; + 0E79D14021919F5600BB5FB2 /* ProfileKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileKey.swift; sourceTree = ""; }; 0E89DFC4213DF7AE00741BA1 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = ""; }; 0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+Communication.swift"; sourceTree = ""; }; 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardProviderViewController.swift; sourceTree = ""; }; @@ -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 */, diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index 2d5ad38a..054fb23b 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -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 { diff --git a/Passepartout/Sources/Model/Profiles/ProfileKey.swift b/Passepartout/Sources/Model/Profiles/ProfileKey.swift new file mode 100644 index 00000000..4d99c62b --- /dev/null +++ b/Passepartout/Sources/Model/Profiles/ProfileKey.swift @@ -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 . +// + +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] + } +}