diff --git a/Menu Bar DNS/Menu Bar DNS/AppDelegate.swift b/Menu Bar DNS/Menu Bar DNS/AppDelegate.swift index 444257a..53fe77c 100644 --- a/Menu Bar DNS/Menu Bar DNS/AppDelegate.swift +++ b/Menu Bar DNS/Menu Bar DNS/AppDelegate.swift @@ -77,6 +77,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let wifiAddresses = dnsAddresses.1 rebuildMenuWithAddress(ethernetAddresses, wifiAddresses) + menu?.autoenablesItems = false statusItem?.menu = menu statusItem?.button?.performClick(self) statusItem?.menu = nil diff --git a/Menu Bar DNS/Menu Bar DNS/DNSConfiguration.swift b/Menu Bar DNS/Menu Bar DNS/DNSConfiguration.swift index 53595c5..6fcdfb7 100644 --- a/Menu Bar DNS/Menu Bar DNS/DNSConfiguration.swift +++ b/Menu Bar DNS/Menu Bar DNS/DNSConfiguration.swift @@ -46,18 +46,24 @@ class DNSConfiguration: NSObject { let serviceDNSKey = "State:/Network/Service/\(serviceID)/DNS" as CFString let serviceSetupDNSKey = "Setup:/Network/Service/\(serviceID)/DNS" as CFString let dynmaicStore = SCDynamicStoreCreate(kCFAllocatorSystemDefault, "DNSSETTING" as CFString, nil, nil) + var allDNSIPAddresses : Array = [] let dynamicPlist = SCDynamicStoreCopyValue(dynmaicStore, serviceDNSKey) let manualAddressPlist = SCDynamicStoreCopyValue(dynmaicStore, serviceSetupDNSKey) if let dnsValues = manualAddressPlist?[kSCPropNetDNSServerAddresses] as? [String] { - return dnsValues + allDNSIPAddresses += dnsValues } - if let manualDNS = dynamicPlist?[kSCPropNetDNSServerAddresses] as? [String] { - return manualDNS + if let dhcpValues = dynamicPlist?[kSCPropNetDNSServerAddresses] as? [String] { + var allDHCPStr = dhcpValues.joined(separator: "\n") + allDHCPStr = allDHCPStr.appending("\n") + let updatedDHCPValues = allDHCPStr.replacingOccurrences(of: "\n", with: "(via DHCP)\n") + var allDHCPValues = updatedDHCPValues.components(separatedBy: "\n") + allDHCPValues = allDHCPValues.filter({ $0 != "" }) + allDNSIPAddresses += Array(Set(allDHCPValues)) } - return [] + return allDNSIPAddresses } static func getAddresses() -> (Array, Array) { diff --git a/Menu Bar DNS/Menu Bar DNS/NSMenu+DNSItems.swift b/Menu Bar DNS/Menu Bar DNS/NSMenu+DNSItems.swift index 0191639..66a3c36 100644 --- a/Menu Bar DNS/Menu Bar DNS/NSMenu+DNSItems.swift +++ b/Menu Bar DNS/Menu Bar DNS/NSMenu+DNSItems.swift @@ -24,9 +24,11 @@ extension NSMenu { func addItemFromList(list items: [String], action selector: Selector?, keyEquivalent charCode: String, prefix string:String) { for itemTitle in items { - self.addItem(NSMenuItem.init(title: "\(string)\(itemTitle)", - action: selector, - keyEquivalent: charCode)) + let menuItem = NSMenuItem.init(title: "\(string)\(itemTitle)", + action: selector, + keyEquivalent: charCode) + menuItem.state = .on + self.addItem(menuItem) } } }