mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
feat(network): add relay connection policies
This commit is contained in:
@@ -248,7 +248,7 @@ final class SettingsModel: ObservableObject {
|
||||
func setRelayMode(_ mode: RelayPreferenceMode) {
|
||||
hasRelayConfigurationDraft = true
|
||||
state.relayMode = mode
|
||||
if mode == .custom && state.relayURLs.isEmpty { state.relayURLs = [""] }
|
||||
if mode.usesCustomRelayURLs && state.relayURLs.isEmpty { state.relayURLs = [""] }
|
||||
updateRelayConfigurationDraft()
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ final class SettingsModel: ObservableObject {
|
||||
state.relayValidationError = nil
|
||||
state.relayApplyErrorKey = nil
|
||||
let saved = preferences.preferences.relayConfiguration
|
||||
let draftURLs = state.relayMode == .automatic ? saved.relayURLs : state.relayURLs
|
||||
let draftURLs = state.relayMode.usesCustomRelayURLs ? state.relayURLs : saved.relayURLs
|
||||
state.relayConfigurationIsDirty = saved != RelayConfiguration(mode: state.relayMode, relayURLs: draftURLs)
|
||||
hasRelayConfigurationDraft = state.relayConfigurationIsDirty
|
||||
}
|
||||
|
||||
@@ -125,7 +125,18 @@ private struct SettingsSectionContent: View {
|
||||
func relayModeLabel(_ mode: RelayPreferenceMode) -> String {
|
||||
switch mode {
|
||||
case .automatic: return String(localized: "relay_mode_automatic")
|
||||
case .custom: return String(localized: "relay_mode_custom")
|
||||
case .strictCustom: return String(localized: "relay_mode_custom")
|
||||
case .customWithDirectFallback: return String(localized: "relay_mode_custom_direct_fallback")
|
||||
case .localOnly: return String(localized: "relay_mode_local_only")
|
||||
}
|
||||
}
|
||||
|
||||
func relayModeDescriptionKey(_ mode: RelayPreferenceMode) -> String {
|
||||
switch mode {
|
||||
case .automatic: return "relay_mode_automatic_description"
|
||||
case .strictCustom: return "relay_mode_custom_description"
|
||||
case .customWithDirectFallback: return "relay_mode_custom_direct_fallback_description"
|
||||
case .localOnly: return "relay_mode_local_only_description"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,15 +70,10 @@ struct NetworkSettings: View {
|
||||
Text(relayModeLabel(mode)).tag(mode)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
.pickerStyle(.inline)
|
||||
.disabled(model.state.isApplyingRelayConfiguration)
|
||||
} footer: {
|
||||
Text(LocalizedStringKey(
|
||||
model.state.relayMode == .automatic
|
||||
? "relay_mode_automatic_description"
|
||||
: "relay_mode_custom_description"
|
||||
))
|
||||
Text(LocalizedStringKey(relayModeDescriptionKey(model.state.relayMode)))
|
||||
}
|
||||
|
||||
Section {
|
||||
@@ -99,15 +94,17 @@ struct NetworkSettings: View {
|
||||
}
|
||||
}
|
||||
|
||||
if model.state.relayMode == .custom {
|
||||
if model.state.relayMode.usesCustomRelayURLs {
|
||||
Section {
|
||||
Label {
|
||||
Text(LocalizedStringKey("relay_strict_warning"))
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
} icon: {
|
||||
Image(systemName: "exclamationmark.shield.fill")
|
||||
if model.state.relayMode == .strictCustom {
|
||||
Label {
|
||||
Text(LocalizedStringKey("relay_strict_warning"))
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
} icon: {
|
||||
Image(systemName: "exclamationmark.shield.fill")
|
||||
}
|
||||
.foregroundStyle(.orange)
|
||||
}
|
||||
.foregroundStyle(.orange)
|
||||
|
||||
ForEach(Array(model.state.relayURLs.indices), id: \.self) { index in
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
|
||||
Reference in New Issue
Block a user