2022-04-12 13:09:14 +00:00
|
|
|
//
|
2022-06-23 21:31:01 +00:00
|
|
|
// DefaultProfileManager.swift
|
2022-04-12 13:09:14 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/25/22.
|
|
|
|
// Copyright (c) 2022 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
|
|
|
|
import Combine
|
|
|
|
import TunnelKitManager
|
2022-06-23 21:31:01 +00:00
|
|
|
import PassepartoutCore
|
|
|
|
import PassepartoutCore
|
2022-04-12 13:09:14 +00:00
|
|
|
import PassepartoutUtils
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
public class DefaultProfileManager: ProfileManagerWithCurrentProfile, ObservableObject {
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
// MARK: Initialization
|
|
|
|
|
2022-06-15 18:53:37 +00:00
|
|
|
private let store: KeyValueStore
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
private let providerManager: ProviderManager
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
let appGroup: String
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
let keychainLabel: (String, VPNProtocolType) -> String
|
|
|
|
|
|
|
|
let keychain: Keychain
|
|
|
|
|
|
|
|
private let strategy: ProfileManagerStrategy
|
|
|
|
|
2022-05-03 08:25:10 +00:00
|
|
|
// MARK: Observables
|
|
|
|
|
2022-06-15 18:53:37 +00:00
|
|
|
@Published private var internalActiveProfileId: UUID? {
|
2022-05-03 10:38:10 +00:00
|
|
|
willSet {
|
2022-05-04 07:45:35 +00:00
|
|
|
pp_log.debug("Setting active profile: \(newValue?.uuidString ?? "nil")")
|
2022-05-03 10:38:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 07:41:10 +00:00
|
|
|
@Published private var internalCurrentProfileId: UUID? {
|
2022-05-03 10:38:10 +00:00
|
|
|
willSet {
|
|
|
|
pp_log.debug("Setting current profile: \(newValue?.uuidString ?? "nil")")
|
2022-05-04 07:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public var currentProfileId: UUID? {
|
|
|
|
get {
|
|
|
|
internalCurrentProfileId
|
|
|
|
}
|
|
|
|
set {
|
2022-05-03 10:38:10 +00:00
|
|
|
guard let id = newValue else {
|
2022-05-04 07:41:10 +00:00
|
|
|
internalCurrentProfileId = nil
|
2022-05-03 10:38:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let profile = liveProfile(withId: id) else {
|
|
|
|
return
|
|
|
|
}
|
2022-05-04 07:41:10 +00:00
|
|
|
internalCurrentProfileId = id
|
2022-05-03 10:38:10 +00:00
|
|
|
setCurrentProfile(profile)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public let currentProfile: ObservableProfile
|
|
|
|
|
2022-07-14 15:05:35 +00:00
|
|
|
public let didUpdateActiveProfile = PassthroughSubject<UUID?, Never>()
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public let didCreateProfile = PassthroughSubject<Profile, Never>()
|
|
|
|
|
|
|
|
private var cancellables: Set<AnyCancellable> = []
|
|
|
|
|
|
|
|
public init(
|
2022-06-15 18:53:37 +00:00
|
|
|
store: KeyValueStore,
|
2022-04-12 13:09:14 +00:00
|
|
|
providerManager: ProviderManager,
|
|
|
|
appGroup: String,
|
|
|
|
keychainLabel: @escaping (String, VPNProtocolType) -> String,
|
|
|
|
strategy: ProfileManagerStrategy
|
|
|
|
) {
|
|
|
|
guard let _ = UserDefaults(suiteName: appGroup) else {
|
|
|
|
fatalError("No entitlements for group '\(appGroup)'")
|
|
|
|
}
|
2022-06-15 18:53:37 +00:00
|
|
|
self.store = store
|
2022-04-12 13:09:14 +00:00
|
|
|
self.providerManager = providerManager
|
|
|
|
self.appGroup = appGroup
|
|
|
|
self.keychainLabel = keychainLabel
|
|
|
|
keychain = Keychain(group: appGroup)
|
|
|
|
self.strategy = strategy
|
|
|
|
|
|
|
|
currentProfile = ObservableProfile()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Index
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-04-12 13:09:14 +00:00
|
|
|
private var allHeaders: [UUID: Profile.Header] {
|
|
|
|
strategy.allHeaders
|
|
|
|
}
|
|
|
|
|
|
|
|
public var headers: [Profile.Header] {
|
2022-05-04 21:14:16 +00:00
|
|
|
Array(allHeaders.values)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-04-22 13:58:03 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public func isExistingProfile(withId id: UUID) -> Bool {
|
|
|
|
allHeaders[id] != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
public func isExistingProfile(withName name: String) -> Bool {
|
|
|
|
allHeaders.contains {
|
|
|
|
$0.value.name == name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Profiles
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-05-03 10:38:10 +00:00
|
|
|
public func liveProfileEx(withId id: UUID) throws -> ProfileEx {
|
|
|
|
guard let profile = liveProfile(withId: id) else {
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.error("Profile not found: \(id)")
|
|
|
|
throw PassepartoutError.missingProfile
|
|
|
|
}
|
|
|
|
pp_log.info("Found profile: \(profile.logDescription)")
|
2022-04-27 15:02:54 +00:00
|
|
|
return (profile, isProfileReady(profile))
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 10:38:10 +00:00
|
|
|
private func liveProfile(withId id: UUID) -> Profile? {
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.debug("Searching profile \(id)")
|
|
|
|
|
|
|
|
// IMPORTANT: fetch live copy first (see intents)
|
|
|
|
if isCurrentProfile(id) {
|
2022-05-03 14:45:36 +00:00
|
|
|
pp_log.debug("Profile \(currentProfile.value.logDescription) found in memory (current profile)")
|
2022-04-12 13:09:14 +00:00
|
|
|
return currentProfile.value
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let profile = strategy.profile(withId: id) else {
|
2022-04-19 16:34:02 +00:00
|
|
|
assertionFailure("Profile in headers yet not found in persistent store")
|
2022-04-12 13:09:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
guard !profile.vpnProtocols.isEmpty else {
|
|
|
|
assertionFailure("Ditching profile, no OpenVPN/WireGuard settings found")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pp_log.debug("Profile \(profile.logDescription) found")
|
|
|
|
keychain.debugAllPasswords(matching: id, context: appGroup)
|
|
|
|
|
|
|
|
return profile
|
|
|
|
}
|
|
|
|
|
2022-04-28 14:58:36 +00:00
|
|
|
public func saveProfile(_ profile: Profile, isActive: Bool?, updateIfCurrent: Bool = true) {
|
2022-04-12 13:09:14 +00:00
|
|
|
guard !profile.isPlaceholder else {
|
|
|
|
assertionFailure("Placeholder")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pp_log.info("Writing profile \(profile.logDescription) to persistent store")
|
|
|
|
strategy.saveProfile(profile)
|
|
|
|
|
|
|
|
if let isActive = isActive {
|
|
|
|
if isActive {
|
|
|
|
pp_log.info("\tActivating profile...")
|
|
|
|
activeProfileId = profile.id
|
|
|
|
} else if activeProfileId == profile.id {
|
|
|
|
pp_log.info("\tDeactivating profile...")
|
|
|
|
activeProfileId = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 14:58:36 +00:00
|
|
|
// IMPORTANT: refresh live copy if just saved (e.g. via intents)
|
|
|
|
if updateIfCurrent && isCurrentProfile(profile.id) {
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.info("Saved profile is also current profile, updating...")
|
|
|
|
currentProfile.value = profile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func removeProfiles(withIds ids: [UUID]) {
|
|
|
|
pp_log.info("Deleting profiles with ids \(ids)")
|
|
|
|
|
|
|
|
pp_log.info("\tDeleting passwords from keychain...")
|
|
|
|
for id in ids {
|
|
|
|
keychain.removeAllPasswords(matching: id, context: appGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
pp_log.info("\tDeleting from persistent store...")
|
|
|
|
strategy.removeProfiles(withIds: ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
@available(*, deprecated, message: "only use for testing")
|
|
|
|
public func removeAllProfiles() {
|
|
|
|
let ids = Array(allHeaders.keys)
|
|
|
|
removeProfiles(withIds: ids)
|
|
|
|
}
|
2022-04-26 20:33:16 +00:00
|
|
|
|
2022-05-03 14:45:36 +00:00
|
|
|
public func duplicateProfile(withId id: UUID, setAsCurrent: Bool) {
|
2022-05-03 10:38:10 +00:00
|
|
|
guard let source = liveProfile(withId: id) else {
|
2022-05-03 14:45:36 +00:00
|
|
|
return
|
2022-04-26 20:33:16 +00:00
|
|
|
}
|
|
|
|
let copy = source
|
|
|
|
.withNewId()
|
2022-04-28 22:40:34 +00:00
|
|
|
.renamedUniquely(withLastUpdate: false)
|
2022-05-03 14:45:36 +00:00
|
|
|
|
|
|
|
if setAsCurrent {
|
2022-05-04 07:41:10 +00:00
|
|
|
|
|
|
|
// iOS 14 goes crazy when changing binding of a presented NavigationLink
|
2022-05-03 14:45:36 +00:00
|
|
|
if #available(iOS 15, *) {
|
2022-05-04 07:41:10 +00:00
|
|
|
internalCurrentProfileId = copy.id
|
2022-05-03 14:45:36 +00:00
|
|
|
}
|
2022-05-04 07:41:10 +00:00
|
|
|
|
|
|
|
// autosaves copy if non-existing in persistent store
|
|
|
|
setCurrentProfile(copy)
|
2022-05-03 14:45:36 +00:00
|
|
|
} else {
|
|
|
|
strategy.saveProfile(copy)
|
|
|
|
}
|
2022-04-26 20:33:16 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
public func persist() {
|
2022-05-03 10:38:10 +00:00
|
|
|
pp_log.info("Persisting pending profiles")
|
|
|
|
if !currentProfile.value.isPlaceholder {
|
|
|
|
saveProfile(currentProfile.value, isActive: nil, updateIfCurrent: false)
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Observation
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-05-03 10:38:10 +00:00
|
|
|
private func setCurrentProfile(_ profile: Profile) {
|
2022-05-01 08:55:07 +00:00
|
|
|
guard !currentProfile.isLoading else {
|
2022-04-22 13:58:03 +00:00
|
|
|
pp_log.warning("Already loading another profile")
|
|
|
|
return
|
|
|
|
}
|
2022-05-03 10:38:10 +00:00
|
|
|
guard profile.id != currentProfile.value.id else {
|
|
|
|
pp_log.debug("Profile \(profile.logDescription) is already current profile")
|
2022-04-22 13:58:03 +00:00
|
|
|
return
|
|
|
|
}
|
2022-05-03 10:38:10 +00:00
|
|
|
|
|
|
|
pp_log.info("Set current profile: \(profile.logDescription)")
|
|
|
|
|
|
|
|
//
|
|
|
|
// IMPORTANT: this method is called on app launch if there is an active profile, which
|
|
|
|
// means that carelessly calling .saveProfiles() may trigger an unnecessary
|
|
|
|
// willUpdateProfiles() and a potential animation in subscribers (e.g. OrganizerView)
|
|
|
|
//
|
2022-05-04 07:41:10 +00:00
|
|
|
// current profile, when set on launch, is always existing, so we take care
|
|
|
|
// checking that to avoid an undesired save
|
2022-05-03 10:38:10 +00:00
|
|
|
//
|
|
|
|
var profilesToSave: [Profile] = []
|
2022-04-12 13:09:14 +00:00
|
|
|
if isExistingProfile(withId: currentProfile.value.id) {
|
2022-05-03 10:38:10 +00:00
|
|
|
pp_log.info("Defer saving of former current profile \(currentProfile.value.logDescription)")
|
|
|
|
profilesToSave.append(currentProfile.value)
|
|
|
|
}
|
2022-05-04 07:41:10 +00:00
|
|
|
if !isExistingProfile(withId: profile.id) {
|
2022-05-03 10:38:10 +00:00
|
|
|
pp_log.info("Defer saving of transient current profile \(profile.logDescription)")
|
|
|
|
profilesToSave.append(profile)
|
|
|
|
}
|
|
|
|
defer {
|
|
|
|
if !profilesToSave.isEmpty {
|
|
|
|
strategy.saveProfiles(profilesToSave)
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-04-22 13:58:03 +00:00
|
|
|
|
2022-05-03 10:38:10 +00:00
|
|
|
if isProfileReady(profile) {
|
|
|
|
currentProfile.value = profile
|
2022-05-02 09:15:59 +00:00
|
|
|
} else {
|
|
|
|
currentProfile.isLoading = true
|
|
|
|
Task {
|
2022-05-03 10:38:10 +00:00
|
|
|
try await makeProfileReady(profile)
|
|
|
|
currentProfile.value = profile
|
2022-05-01 08:55:07 +00:00
|
|
|
currentProfile.isLoading = false
|
2022-04-22 13:58:03 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-04-18 13:32:28 +00:00
|
|
|
public func observeUpdates() {
|
2022-07-14 15:05:35 +00:00
|
|
|
$internalActiveProfileId
|
|
|
|
.sink {
|
|
|
|
self.didUpdateActiveProfile.send($0)
|
|
|
|
}.store(in: &cancellables)
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
strategy.willUpdateProfiles()
|
|
|
|
.dropFirst()
|
|
|
|
.sink {
|
|
|
|
self.willUpdateProfiles($0)
|
|
|
|
}.store(in: &cancellables)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func willUpdateProfiles(_ newHeaders: [UUID: Profile.Header]) {
|
|
|
|
pp_log.debug("Profiles updated: \(newHeaders)")
|
|
|
|
defer {
|
|
|
|
objectWillChange.send()
|
|
|
|
}
|
|
|
|
|
|
|
|
// IMPORTANT: invalidate current profile if deleted
|
2022-04-12 16:09:30 +00:00
|
|
|
if !currentProfile.value.isPlaceholder && !newHeaders.keys.contains(currentProfile.value.id) {
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.info("\tCurrent profile deleted, invalidating...")
|
|
|
|
currentProfile.value = .placeholder
|
|
|
|
}
|
|
|
|
|
|
|
|
let newProfile = strategy.profile(withId: currentProfile.value.id)
|
|
|
|
if let newProfile = newProfile, newProfile != currentProfile.value {
|
|
|
|
pp_log.info("Current profile remotely updated")
|
|
|
|
currentProfile.value = newProfile
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:21:27 +00:00
|
|
|
if let activeProfileId = activeProfileId, !newHeaders.keys.contains(activeProfileId) {
|
|
|
|
pp_log.info("\tActive profile was deleted")
|
|
|
|
self.activeProfileId = nil
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
// IMPORTANT: defer task to avoid recursive saves
|
|
|
|
// FIXME: Core Data, not sure about this workaround
|
|
|
|
Task {
|
|
|
|
fixDuplicateNames(in: newHeaders)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func fixDuplicateNames(in newHeaders: [UUID: Profile.Header]) {
|
|
|
|
var allNames = newHeaders.values.map(\.name)
|
|
|
|
let distinctNames = Set(allNames)
|
|
|
|
distinctNames.forEach {
|
|
|
|
guard let i = allNames.firstIndex(of: $0) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
allNames.remove(at: i)
|
|
|
|
}
|
|
|
|
let duplicates = Set(allNames)
|
2022-04-16 09:21:33 +00:00
|
|
|
guard !duplicates.isEmpty else {
|
|
|
|
pp_log.debug("No duplicated profiles")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pp_log.debug("Duplicated profile names: \(duplicates)")
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
var renamedProfiles: [Profile] = []
|
|
|
|
duplicates.forEach { name in
|
|
|
|
let headers = newHeaders.values.filter {
|
|
|
|
$0.name == name
|
|
|
|
}
|
|
|
|
guard headers.count > 1 else {
|
|
|
|
assertionFailure("Name '\(name)' marked as duplicate but headers.count not > 1")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// headers.removeFirst()
|
|
|
|
headers.forEach { dupHeader in
|
2022-04-26 20:33:16 +00:00
|
|
|
let uniqueHeader = dupHeader.renamedUniquely(withLastUpdate: true)
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.debug("Renaming duplicate profile \(dupHeader.logDescription) to \(uniqueHeader.logDescription)")
|
2022-05-03 10:38:10 +00:00
|
|
|
guard var uniqueProfile = liveProfile(withId: uniqueHeader.id) else {
|
2022-04-12 13:09:14 +00:00
|
|
|
pp_log.warning("Skipping profile \(dupHeader.logDescription) renaming, not found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
uniqueProfile.header = uniqueHeader
|
|
|
|
renamedProfiles.append(uniqueProfile)
|
|
|
|
}
|
|
|
|
}
|
2022-04-13 09:16:38 +00:00
|
|
|
if !renamedProfiles.isEmpty {
|
|
|
|
strategy.saveProfiles(renamedProfiles)
|
|
|
|
pp_log.debug("Duplicates successfully renamed!")
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Readiness
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-04-12 13:09:14 +00:00
|
|
|
private func isProfileReady(_ profile: Profile) -> Bool {
|
|
|
|
isProfileProviderAvailable(profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
public func makeProfileReady(_ profile: Profile) async throws {
|
|
|
|
try await fetchProfileProviderIfMissing(profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func isProfileProviderAvailable(_ profile: Profile) -> Bool {
|
|
|
|
guard let providerName = profile.header.providerName else {
|
|
|
|
return true // host
|
|
|
|
}
|
|
|
|
return providerManager.isAvailable(providerName, vpnProtocol: profile.currentVPNProtocol)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func fetchProfileProviderIfMissing(_ profile: Profile) async throws {
|
|
|
|
guard let providerName = profile.header.providerName else {
|
|
|
|
return // host
|
|
|
|
}
|
|
|
|
if providerManager.isAvailable(providerName, vpnProtocol: profile.currentVPNProtocol) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
pp_log.info("Importing missing provider \(providerName)...")
|
|
|
|
try await providerManager.fetchProviderPublisher(
|
|
|
|
withName: providerName,
|
|
|
|
vpnProtocol: profile.currentVPNProtocol,
|
|
|
|
priority: .remoteThenBundle
|
|
|
|
).async()
|
|
|
|
pp_log.info("Finished!")
|
|
|
|
} catch {
|
|
|
|
pp_log.error("Unable to import missing provider: \(error)")
|
|
|
|
throw PassepartoutError.missingProfile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-15 18:53:37 +00:00
|
|
|
|
|
|
|
// MARK: KeyValueStore
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
extension DefaultProfileManager {
|
2022-06-15 18:53:37 +00:00
|
|
|
public private(set) var activeProfileId: UUID? {
|
|
|
|
get {
|
|
|
|
guard let idString: String = store.value(forLocation: StoreKey.activeProfileId) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
guard let id = UUID(uuidString: idString) else {
|
|
|
|
pp_log.warning("Active profile id is malformed, ignoring")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
guard isExistingProfile(withId: id) else {
|
|
|
|
pp_log.warning("Active profile \(id) does not exist, ignoring")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
|
|
|
|
// trigger publisher
|
|
|
|
internalActiveProfileId = newValue
|
|
|
|
|
|
|
|
store.setValue(newValue?.uuidString, forLocation: StoreKey.activeProfileId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 21:31:01 +00:00
|
|
|
private extension DefaultProfileManager {
|
2022-06-15 18:53:37 +00:00
|
|
|
private enum StoreKey: String, KeyStoreDomainLocation {
|
|
|
|
case activeProfileId
|
|
|
|
|
|
|
|
var domain: String {
|
2022-06-17 07:32:56 +00:00
|
|
|
"Passepartout.ProfileManager"
|
2022-06-15 18:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|