Reconnect on provider server selection (#753)

Trigger reconnection on server selection, otherwise the installed
profile would display an outdated region. It's also more convenient.
This commit is contained in:
Davide 2024-10-23 18:51:22 +02:00 committed by GitHub
parent 12d3bd20f5
commit 99b9aeaa9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 24 additions and 6 deletions

View File

@ -464,8 +464,8 @@ public enum Strings {
public static let onDemandSuffix = Strings.tr("Localizable", "ui.connection_status.on_demand_suffix", fallback: " (on-demand)") public static let onDemandSuffix = Strings.tr("Localizable", "ui.connection_status.on_demand_suffix", fallback: " (on-demand)")
} }
public enum ProfileContext { public enum ProfileContext {
/// Move to... /// Connect to...
public static let moveTo = Strings.tr("Localizable", "ui.profile_context.move_to", fallback: "Move to...") public static let connectTo = Strings.tr("Localizable", "ui.profile_context.connect_to", fallback: "Connect to...")
} }
} }
public enum Views { public enum Views {

View File

@ -235,7 +235,7 @@
// MARK: - Components // MARK: - Components
"ui.connection_status.on_demand_suffix" = " (on-demand)"; "ui.connection_status.on_demand_suffix" = " (on-demand)";
"ui.profile_context.move_to" = "Move to..."; "ui.profile_context.connect_to" = "Connect to...";
// MARK: - Alerts // MARK: - Alerts

View File

@ -145,6 +145,7 @@ private extension AppInlineCoordinator {
case .editProviderEntity(let profile, let module, let provider): case .editProviderEntity(let profile, let module, let provider):
ProviderSelectorView( ProviderSelectorView(
profileManager: profileManager, profileManager: profileManager,
tunnel: tunnel,
profile: profile, profile: profile,
module: module, module: module,
provider: provider provider: provider

View File

@ -137,6 +137,7 @@ extension AppModalCoordinator {
case .editProviderEntity(let profile, let module, let provider): case .editProviderEntity(let profile, let module, let provider):
ProviderSelectorView( ProviderSelectorView(
profileManager: profileManager, profileManager: profileManager,
tunnel: tunnel,
profile: profile, profile: profile,
module: module, module: module,
provider: provider provider: provider

View File

@ -29,9 +29,15 @@ import SwiftUI
struct ProviderSelectorView: View { struct ProviderSelectorView: View {
@EnvironmentObject
private var profileProcessor: ProfileProcessor
@ObservedObject @ObservedObject
var profileManager: ProfileManager var profileManager: ProfileManager
@ObservedObject
var tunnel: Tunnel
let profile: Profile let profile: Profile
let module: Module let module: Module
@ -49,9 +55,19 @@ struct ProviderSelectorView: View {
private extension ProviderSelectorView { private extension ProviderSelectorView {
func onSelect(_ entity: any ProviderEntity & Encodable) async throws { func onSelect(_ entity: any ProviderEntity & Encodable) async throws {
pp_log(.app, .info, "Select new provider entity: \(entity)")
var builder = profile.builder() var builder = profile.builder()
try builder.setProviderEntity(entity, forModuleWithId: module.id) try builder.setProviderEntity(entity, forModuleWithId: module.id)
let newProfile = try builder.tryBuild() let newProfile = try builder.tryBuild()
try await profileManager.save(newProfile) try await profileManager.save(newProfile)
Task {
do {
try await tunnel.connect(with: newProfile, processor: profileProcessor)
} catch {
pp_log(.app, .error, "Unable to connect with new provider entity: \(error)")
}
}
} }
} }

View File

@ -45,7 +45,7 @@ struct ProfileContextMenu: View, Routable {
var body: some View { var body: some View {
tunnelToggleButton tunnelToggleButton
providerEntityButton providerConnectToButton
if isInstalledProfile { if isInstalledProfile {
tunnelRestartButton tunnelRestartButton
} }
@ -78,11 +78,11 @@ private extension ProfileContextMenu {
} }
} }
var providerEntityButton: some View { var providerConnectToButton: some View {
profile? profile?
.firstProviderModule .firstProviderModule
.map { _ in .map { _ in
Button(Strings.Ui.ProfileContext.moveTo) { Button(Strings.Ui.ProfileContext.connectTo) {
flow?.onEditProviderEntity(profile!) flow?.onEditProviderEntity(profile!)
} }
} }