diff --git a/Passepartout/App/Views/AddHostView.swift b/Passepartout/App/Views/AddHostView.swift index 7d5e4462..f122f554 100644 --- a/Passepartout/App/Views/AddHostView.swift +++ b/Passepartout/App/Views/AddHostView.swift @@ -95,10 +95,11 @@ struct AddHostView: View { private var processingView: some View { AddProfileView.ProfileNameSection( profileName: $viewModel.profileName, - initialName: url.normalizedFilename, errorMessage: viewModel.errorMessage ) { processProfile(replacingExisting: false) + }.onAppear { + viewModel.presetName(withURL: url) } if viewModel.requiresPassphrase { encryptionSection diff --git a/Passepartout/App/Views/AddHostViewModel.swift b/Passepartout/App/Views/AddHostViewModel.swift index f5436e27..cb82b660 100644 --- a/Passepartout/App/Views/AddHostViewModel.swift +++ b/Passepartout/App/Views/AddHostViewModel.swift @@ -30,6 +30,8 @@ import TunnelKitWireGuard extension AddHostView { struct ViewModel { + private var isNamePreset = false + var profileName = "" private(set) var requiresPassphrase = false @@ -41,6 +43,14 @@ extension AddHostView { private(set) var errorMessage: String? var isAskingOverwrite = false + + mutating func presetName(withURL url: URL) { + guard !isNamePreset else { + return + } + isNamePreset = true + profileName = url.normalizedFilename + } @MainActor mutating func processURL( diff --git a/Passepartout/App/Views/AddProfileView.swift b/Passepartout/App/Views/AddProfileView.swift index a23fa1c0..eef547f1 100644 --- a/Passepartout/App/Views/AddProfileView.swift +++ b/Passepartout/App/Views/AddProfileView.swift @@ -34,8 +34,6 @@ enum AddProfileView { struct ProfileNameSection: View { @Binding var profileName: String - let initialName: String - let errorMessage: String? let onCommit: () -> Void @@ -46,12 +44,6 @@ enum AddProfileView { footer: themeErrorMessage(errorMessage) ) { TextField(L10n.Global.Placeholders.profileName, text: $profileName, onCommit: onCommit) - .onAppear { - // XXX: this is reset on the way back, but: - // host: there is no back button after processing profile - // host/provider: back button is hidden after going to credentials - profileName = initialName - } } } } diff --git a/Passepartout/App/Views/AddProviderView+Name.swift b/Passepartout/App/Views/AddProviderView+Name.swift index 042825d0..dcfd706f 100644 --- a/Passepartout/App/Views/AddProviderView+Name.swift +++ b/Passepartout/App/Views/AddProviderView+Name.swift @@ -56,10 +56,11 @@ extension AddProviderView { List { AddProfileView.ProfileNameSection( profileName: $viewModel.profileName, - initialName: providerMetadata.fullName, errorMessage: viewModel.errorMessage ) { saveProfile(replacingExisting: false) + }.onAppear { + viewModel.presetName(withMetadata: providerMetadata) } let headers = profileManager.headers.sorted() if !headers.isEmpty { diff --git a/Passepartout/App/Views/AddProviderViewModel.swift b/Passepartout/App/Views/AddProviderViewModel.swift index 4f773df7..6c603193 100644 --- a/Passepartout/App/Views/AddProviderViewModel.swift +++ b/Passepartout/App/Views/AddProviderViewModel.swift @@ -124,11 +124,21 @@ extension AddProviderView { extension AddProviderView.NameView { struct ViewModel { + private var isNamePreset = false + var profileName = "" var isAskingOverwrite = false private(set) var errorMessage: String? + + mutating func presetName(withMetadata metadata: ProviderMetadata) { + guard !isNamePreset else { + return + } + isNamePreset = true + profileName = metadata.fullName + } @MainActor mutating func addProfile(