Disable DNS HTTPS/TLS editing if non-manual

This commit is contained in:
Davide De Rosa 2021-01-22 20:19:45 +01:00
parent 7763e368b9
commit 6686184a9f
2 changed files with 20 additions and 4 deletions

View File

@ -451,12 +451,20 @@ extension NetworkSettingsViewController {
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = L10n.Core.Global.Captions.protocol
cell.rightText = (networkSettings.dnsProtocol ?? .fallback)?.description
if networkChoices.dns == .manual {
cell.accessoryType = .disclosureIndicator
cell.isTappable = true
} else {
cell.accessoryType = .none
cell.isTappable = false
}
return cell
case .dnsCustom:
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
cell.caption = nil
cell.field.tag = FieldTag.dnsCustom.rawValue
cell.field.isEnabled = (networkChoices.dns == .manual)
switch networkSettings.dnsProtocol {
case .https:
cell.field.placeholder = AppConstants.Placeholders.dohURL
@ -646,6 +654,10 @@ extension NetworkSettingsViewController {
navigationController?.pushViewController(vc, animated: true)
case .dnsProtocol:
guard networkChoices.dns == .manual else {
break
}
let vc = SingleOptionViewController<DNSProtocol>()
vc.applyTint(.current)
vc.title = (cell as? SettingTableViewCell)?.leftText

View File

@ -192,8 +192,11 @@ class DNSViewController: NSViewController, ProfileCustomization {
}
}
tableDNSAddresses.reset(withRows: networkSettings.dnsServers ?? [], isAddEnabled: currentChoice == .manual)
tableDNSDomains.reset(withRows: networkSettings.dnsSearchDomains ?? [], isAddEnabled: currentChoice == .manual)
let isManual = (currentChoice == .manual)
popupDNSProtocol.isEnabled = isManual
textDNSCustom.isEnabled = isManual
tableDNSAddresses.reset(withRows: networkSettings.dnsServers ?? [], isAddEnabled: isManual)
tableDNSDomains.reset(withRows: networkSettings.dnsSearchDomains ?? [], isAddEnabled: isManual)
let isServer = (currentChoice == .server)
constraintChoiceBottom.priority = isServer ? .defaultHigh : .defaultLow
@ -204,16 +207,17 @@ class DNSViewController: NSViewController, ProfileCustomization {
}
private func updateProtocolVisibility() {
let isManual = (currentChoice == .manual)
let isCustom: Bool
switch networkSettings.dnsProtocol {
case .https:
isCustom = true
textDNSCustom.placeholderString = AppConstants.Placeholders.dohURL
textDNSCustom.placeholderString = isManual ? AppConstants.Placeholders.dohURL : ""
textDNSCustom.stringValue = networkSettings.dnsHTTPSURL?.absoluteString ?? ""
case .tls:
isCustom = true
textDNSCustom.placeholderString = AppConstants.Placeholders.dotServerName
textDNSCustom.placeholderString = isManual ? AppConstants.Placeholders.dotServerName : ""
textDNSCustom.stringValue = networkSettings.dnsTLSServerName ?? ""
default: