Refactor and move entities around (#698)
Do some housekeeping in AppLibrary/AppUI.
This commit is contained in:
parent
f4505d0efd
commit
504bcbdbd2
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// ProfileManagerProviding.swift
|
||||
// ProfileManager+Extensions.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 9/3/24.
|
||||
|
@ -27,22 +27,16 @@ import AppLibrary
|
|||
import Foundation
|
||||
import PassepartoutKit
|
||||
|
||||
protocol ProfileManagerProviding {
|
||||
var profileManager: ProfileManager { get }
|
||||
}
|
||||
|
||||
@MainActor
|
||||
extension ProfileManagerProviding {
|
||||
func removeProfiles(at offsets: IndexSet) {
|
||||
let idsToRemove = profileManager.headers
|
||||
extension ProfileManager {
|
||||
func removeProfiles(at offsets: IndexSet) async {
|
||||
let idsToRemove = headers
|
||||
.enumerated()
|
||||
.filter {
|
||||
offsets.contains($0.offset)
|
||||
}
|
||||
.map(\.element.id)
|
||||
|
||||
Task {
|
||||
await profileManager.remove(withIds: idsToRemove)
|
||||
}
|
||||
await remove(withIds: idsToRemove)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// ProfileProcessor.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 10/6/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 Foundation
|
||||
import PassepartoutKit
|
||||
|
||||
protocol ProfileProcessor {
|
||||
func processedProfile(_ profile: Profile) throws -> Profile
|
||||
}
|
|
@ -27,10 +27,7 @@ import CommonLibrary
|
|||
import Foundation
|
||||
import PassepartoutKit
|
||||
|
||||
protocol ProfileProcessor {
|
||||
func processedProfile(_ profile: Profile) throws -> Profile
|
||||
}
|
||||
|
||||
@MainActor
|
||||
extension Tunnel {
|
||||
func install(_ profile: Profile, processor: ProfileProcessor) async throws {
|
||||
let newProfile = try processor.processedProfile(profile)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public enum ProfilesLayout: String, RawRepresentable, CaseIterable, Codable {
|
||||
enum ProfilesLayout: String, RawRepresentable, CaseIterable, Codable {
|
||||
case list
|
||||
|
||||
case grid
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// TunnelInstallation.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 10/6/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 Foundation
|
||||
import PassepartoutKit
|
||||
|
||||
struct TunnelInstallation {
|
||||
let header: ProfileHeader
|
||||
|
||||
let onDemand: Bool
|
||||
}
|
|
@ -28,7 +28,7 @@ import PassepartoutKit
|
|||
import SwiftUI
|
||||
import UtilsLibrary
|
||||
|
||||
struct ProfileGridView: View, ProfileManagerProviding, TunnelInstallationProviding {
|
||||
struct ProfileGridView: View, TunnelInstallationProviding {
|
||||
|
||||
@Environment(\.isSearching)
|
||||
private var isSearching
|
||||
|
@ -61,7 +61,11 @@ struct ProfileGridView: View, ProfileManagerProviding, TunnelInstallationProvidi
|
|||
}
|
||||
LazyVGrid(columns: columns) {
|
||||
ForEach(allHeaders, content: profileView)
|
||||
.onDelete(perform: removeProfiles)
|
||||
.onDelete { offsets in
|
||||
Task {
|
||||
await profileManager.removeProfiles(at: offsets)
|
||||
}
|
||||
}
|
||||
}
|
||||
.themeGridHeader(title: Strings.Views.Profiles.Folders.default)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import PassepartoutKit
|
|||
import SwiftUI
|
||||
import UtilsLibrary
|
||||
|
||||
struct ProfileListView: View, ProfileManagerProviding, TunnelInstallationProviding {
|
||||
struct ProfileListView: View, TunnelInstallationProviding {
|
||||
|
||||
@Environment(\.horizontalSizeClass)
|
||||
private var hsClass
|
||||
|
@ -63,7 +63,11 @@ struct ProfileListView: View, ProfileManagerProviding, TunnelInstallationProvidi
|
|||
}
|
||||
Group {
|
||||
ForEach(allHeaders, content: profileView)
|
||||
.onDelete(perform: removeProfiles)
|
||||
.onDelete { offsets in
|
||||
Task {
|
||||
await profileManager.removeProfiles(at: offsets)
|
||||
}
|
||||
}
|
||||
}
|
||||
.themeSection(header: Strings.Views.Profiles.Folders.default)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// InteractiveViewProviding.swift
|
||||
// Passepartout
|
||||
//
|
||||
// Created by Davide De Rosa on 10/6/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 SwiftUI
|
||||
|
||||
protocol InteractiveViewProviding {
|
||||
associatedtype InteractiveContent: View
|
||||
|
||||
@MainActor
|
||||
func interactiveView(with editor: ProfileEditor) -> InteractiveContent
|
||||
}
|
|
@ -31,10 +31,3 @@ protocol ModuleViewProviding {
|
|||
@MainActor
|
||||
func moduleView(with editor: ProfileEditor) -> Content
|
||||
}
|
||||
|
||||
protocol InteractiveViewProviding {
|
||||
associatedtype InteractiveContent: View
|
||||
|
||||
@MainActor
|
||||
func interactiveView(with editor: ProfileEditor) -> InteractiveContent
|
||||
}
|
|
@ -33,12 +33,6 @@ protocol TunnelInstallationProviding {
|
|||
var tunnel: Tunnel { get }
|
||||
}
|
||||
|
||||
struct TunnelInstallation {
|
||||
let header: ProfileHeader
|
||||
|
||||
let onDemand: Bool
|
||||
}
|
||||
|
||||
@MainActor
|
||||
extension TunnelInstallationProviding {
|
||||
var installation: TunnelInstallation? {
|
|
@ -34,7 +34,7 @@ extension OpenVPNModule.Builder: ModuleViewProviding {
|
|||
|
||||
extension OpenVPNModule.Builder: InteractiveViewProviding {
|
||||
func interactiveView(with editor: ProfileEditor) -> some View {
|
||||
let draft: Binding<OpenVPNModule.Builder> = editor.binding(forModule: self)
|
||||
let draft = editor.binding(forModule: self)
|
||||
|
||||
return OpenVPNView.CredentialsView(
|
||||
isInteractive: draft.isInteractive,
|
||||
|
|
Loading…
Reference in New Issue