Skip to content

Commit

Permalink
Issue ivanstegic#10: menu bar appearance changes
Browse files Browse the repository at this point in the history
  • Loading branch information
munirahmed007 committed Jan 23, 2021
1 parent 256bd23 commit 8035cb1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions Menu Bar DNS/Menu Bar DNS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions Menu Bar DNS/Menu Bar DNS/DNSConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = []

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<String>, Array<String>) {
Expand Down
8 changes: 5 additions & 3 deletions Menu Bar DNS/Menu Bar DNS/NSMenu+DNSItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 8035cb1

Please sign in to comment.