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 enum ProfileContext {
/// Move to...
public static let moveTo = Strings.tr("Localizable", "ui.profile_context.move_to", fallback: "Move to...")
/// Connect to...
public static let connectTo = Strings.tr("Localizable", "ui.profile_context.connect_to", fallback: "Connect to...")
}
}
public enum Views {

View File

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

View File

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

View File

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

View File

@ -29,9 +29,15 @@ import SwiftUI
struct ProviderSelectorView: View {
@EnvironmentObject
private var profileProcessor: ProfileProcessor
@ObservedObject
var profileManager: ProfileManager
@ObservedObject
var tunnel: Tunnel
let profile: Profile
let module: Module
@ -49,9 +55,19 @@ struct ProviderSelectorView: View {
private extension ProviderSelectorView {
func onSelect(_ entity: any ProviderEntity & Encodable) async throws {
pp_log(.app, .info, "Select new provider entity: \(entity)")
var builder = profile.builder()
try builder.setProviderEntity(entity, forModuleWithId: module.id)
let newProfile = try builder.tryBuild()
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 {
tunnelToggleButton
providerEntityButton
providerConnectToButton
if isInstalledProfile {
tunnelRestartButton
}
@ -78,11 +78,11 @@ private extension ProfileContextMenu {
}
}
var providerEntityButton: some View {
var providerConnectToButton: some View {
profile?
.firstProviderModule
.map { _ in
Button(Strings.Ui.ProfileContext.moveTo) {
Button(Strings.Ui.ProfileContext.connectTo) {
flow?.onEditProviderEntity(profile!)
}
}