2024-12-06 10:24:51 +00:00
|
|
|
//
|
|
|
|
// PreferencesManager.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 12/4/24.
|
|
|
|
// Copyright (c) 2024 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 CommonUtils
|
|
|
|
import Foundation
|
|
|
|
import PassepartoutKit
|
|
|
|
|
2024-12-10 14:19:07 +00:00
|
|
|
@MainActor
|
|
|
|
public final class PreferencesManager: ObservableObject {
|
|
|
|
private let modulesFactory: (UUID) throws -> ModulePreferencesRepository
|
2024-12-10 13:13:10 +00:00
|
|
|
|
2024-12-10 14:19:07 +00:00
|
|
|
private let providersFactory: (ProviderID) throws -> ProviderPreferencesRepository
|
2024-12-06 10:24:51 +00:00
|
|
|
|
|
|
|
public init(
|
2024-12-10 14:19:07 +00:00
|
|
|
modulesFactory: ((UUID) throws -> ModulePreferencesRepository)? = nil,
|
|
|
|
providersFactory: ((ProviderID) throws -> ProviderPreferencesRepository)? = nil
|
2024-12-06 10:24:51 +00:00
|
|
|
) {
|
2024-12-10 13:13:10 +00:00
|
|
|
self.modulesFactory = modulesFactory ?? { _ in
|
|
|
|
DummyModulePreferencesRepository()
|
|
|
|
}
|
2024-12-08 15:05:23 +00:00
|
|
|
self.providersFactory = providersFactory ?? { _ in
|
|
|
|
DummyProviderPreferencesRepository()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PreferencesManager {
|
2024-12-10 13:13:10 +00:00
|
|
|
public func preferencesRepository(forModuleWithId moduleId: UUID) throws -> ModulePreferencesRepository {
|
|
|
|
try modulesFactory(moduleId)
|
2024-12-06 10:24:51 +00:00
|
|
|
}
|
|
|
|
|
2024-12-10 13:13:10 +00:00
|
|
|
public func preferencesRepository(forProviderWithId providerId: ProviderID) throws -> ProviderPreferencesRepository {
|
|
|
|
try providersFactory(providerId)
|
2024-12-06 10:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Dummy
|
|
|
|
|
2024-12-10 14:19:07 +00:00
|
|
|
@MainActor
|
2024-12-10 13:13:10 +00:00
|
|
|
private final class DummyModulePreferencesRepository: ModulePreferencesRepository {
|
2024-12-09 01:00:55 +00:00
|
|
|
func isExcludedEndpoint(_ endpoint: ExtendedEndpoint) -> Bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
func addExcludedEndpoint(_ endpoint: ExtendedEndpoint) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeExcludedEndpoint(_ endpoint: ExtendedEndpoint) {
|
|
|
|
}
|
|
|
|
|
2024-12-08 15:05:23 +00:00
|
|
|
func save() throws {
|
2024-12-06 10:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
2024-12-10 13:13:10 +00:00
|
|
|
|
2024-12-10 14:19:07 +00:00
|
|
|
@MainActor
|
2024-12-10 13:13:10 +00:00
|
|
|
private final class DummyProviderPreferencesRepository: ProviderPreferencesRepository {
|
2024-12-10 14:19:07 +00:00
|
|
|
func isFavoriteServer(_ serverId: String) -> Bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
func addFavoriteServer(_ serverId: String) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeFavoriteServer(_ serverId: String) {
|
|
|
|
}
|
2024-12-10 13:13:10 +00:00
|
|
|
|
|
|
|
func save() throws {
|
|
|
|
}
|
|
|
|
}
|