Observe currentProfile in ProfileView
ProfileView is not interested in changes in other profiles notified by ProfileManager. Set isLoading inside ObservableObject for observable to be self-contained. Loses observation of profile deletion, but dismiss on removal is actually handled by OrganizerView, not ProfileView. Also drop unused presentationMode.
This commit is contained in:
parent
107de2d843
commit
8003b4a92d
|
@ -43,22 +43,20 @@ struct ProfileView: View {
|
|||
}
|
||||
}
|
||||
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
|
||||
@ObservedObject private var profileManager: ProfileManager
|
||||
@ObservedObject private var currentProfile: ObservableProfile
|
||||
|
||||
private var isLoading: Bool {
|
||||
profileManager.isLoadingCurrentProfile
|
||||
currentProfile.isLoading
|
||||
}
|
||||
|
||||
private var isExisting: Bool {
|
||||
profileManager.isCurrentProfileExisting()
|
||||
!currentProfile.value.isPlaceholder
|
||||
}
|
||||
|
||||
@State private var modalType: ModalType?
|
||||
|
||||
init() {
|
||||
profileManager = .shared
|
||||
currentProfile = ProfileManager.shared.currentProfile
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
@ -71,7 +69,7 @@ struct ProfileView: View {
|
|||
}
|
||||
}.toolbar {
|
||||
MainMenu(
|
||||
currentProfile: profileManager.currentProfile,
|
||||
currentProfile: currentProfile,
|
||||
modalType: $modalType
|
||||
).disabled(!isExisting)
|
||||
}.sheet(item: $modalType, content: presentedModal)
|
||||
|
@ -80,23 +78,23 @@ struct ProfileView: View {
|
|||
}
|
||||
|
||||
private var title: String {
|
||||
profileManager.currentProfile.name
|
||||
currentProfile.name
|
||||
}
|
||||
|
||||
private var mainView: some View {
|
||||
List {
|
||||
VPNSection(
|
||||
currentProfile: profileManager.currentProfile,
|
||||
currentProfile: currentProfile,
|
||||
isLoading: isLoading
|
||||
)
|
||||
if !isLoading {
|
||||
ProviderSection(currentProfile: profileManager.currentProfile)
|
||||
ProviderSection(currentProfile: currentProfile)
|
||||
ConfigurationSection(
|
||||
currentProfile: profileManager.currentProfile,
|
||||
currentProfile: currentProfile,
|
||||
modalType: $modalType
|
||||
)
|
||||
ExtraSection(currentProfile: profileManager.currentProfile)
|
||||
DiagnosticsSection(currentProfile: profileManager.currentProfile)
|
||||
ExtraSection(currentProfile: currentProfile)
|
||||
DiagnosticsSection(currentProfile: currentProfile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,12 +104,12 @@ struct ProfileView: View {
|
|||
switch modalType {
|
||||
case .shortcuts:
|
||||
NavigationView {
|
||||
ShortcutsView(target: profileManager.currentProfile.value)
|
||||
ShortcutsView(target: currentProfile.value)
|
||||
}.themeGlobal()
|
||||
|
||||
case .rename:
|
||||
NavigationView {
|
||||
RenameView(currentProfile: profileManager.currentProfile)
|
||||
RenameView(currentProfile: currentProfile)
|
||||
}.themeGlobal()
|
||||
|
||||
case .paywallShortcuts:
|
||||
|
|
|
@ -58,8 +58,6 @@ public class ProfileManager: ObservableObject {
|
|||
|
||||
// MARK: Observables
|
||||
|
||||
@Published public private(set) var isLoadingCurrentProfile = false
|
||||
|
||||
public let currentProfile: ObservableProfile
|
||||
|
||||
public let willUpdateActiveId = PassthroughSubject<UUID?, Never>()
|
||||
|
@ -255,7 +253,7 @@ extension ProfileManager {
|
|||
|
||||
extension ProfileManager {
|
||||
public func loadCurrentProfile(withId id: UUID) throws {
|
||||
guard !isLoadingCurrentProfile else {
|
||||
guard !currentProfile.isLoading else {
|
||||
pp_log.warning("Already loading another profile")
|
||||
return
|
||||
}
|
||||
|
@ -263,7 +261,7 @@ extension ProfileManager {
|
|||
pp_log.debug("Profile \(id) is already current profile")
|
||||
return
|
||||
}
|
||||
isLoadingCurrentProfile = true
|
||||
currentProfile.isLoading = true
|
||||
if isExistingProfile(withId: currentProfile.value.id) {
|
||||
pp_log.info("Committing changes of former current profile \(currentProfile.value.logDescription)")
|
||||
saveCurrentProfile()
|
||||
|
@ -274,20 +272,24 @@ extension ProfileManager {
|
|||
|
||||
currentProfile.value = result.profile
|
||||
if result.isReady {
|
||||
isLoadingCurrentProfile = false
|
||||
currentProfile.isLoading = false
|
||||
} else {
|
||||
Task {
|
||||
try await makeProfileReady(result.profile)
|
||||
isLoadingCurrentProfile = false
|
||||
currentProfile.isLoading = false
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
currentProfile.value = .placeholder
|
||||
isLoadingCurrentProfile = false
|
||||
currentProfile.isLoading = false
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
public func isCurrentProfileLoading() -> Bool {
|
||||
currentProfile.isLoading
|
||||
}
|
||||
|
||||
public func isCurrentProfileExisting() -> Bool {
|
||||
isExistingProfile(withId: currentProfile.value.id)
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import Foundation
|
|||
import PassepartoutUtils
|
||||
|
||||
public class ObservableProfile: ValueHolder, ObservableObject {
|
||||
@Published public internal(set) var isLoading = false
|
||||
|
||||
@Published public var value: Profile
|
||||
|
||||
public var name: String {
|
||||
|
|
Loading…
Reference in New Issue