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

View File

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