1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 17:08:39 +00:00

Merge pull request #24 from ad/currencyWidget

* currency list
This commit is contained in:
Anton Palgunov 2018-04-19 12:35:43 +01:00 committed by GitHub
commit e9de35ee37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,15 +12,39 @@ import CoreLocation
class CurrencyBarItem: NSCustomTouchBarItem {
private var timer: Timer!
private var interval: TimeInterval!
private var prefix: String
private var from: String
private var to: String
private let button = NSButton(title: "", target: nil, action: nil)
private let currencies = [
"USD": "$",
"EUR": "",
"RUB": "",
"JPY": "¥",
"GBP": "",
"CAD": "$",
"KRW": "",
"CNY": "¥",
"AUD": "$",
"BRL": "R$",
"IDR": "Rp",
"MXN": "$",
"SGD": "$",
"CHF": "Fr."
]
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) {
self.interval = interval
self.from = from
self.to = to
if let prefix = currencies[from] {
self.prefix = prefix
} else {
self.prefix = from
}
super.init(identifier: identifier)
button.bezelColor = .clear
@ -55,7 +79,7 @@ class CurrencyBarItem: NSCustomTouchBarItem {
}
if value != nil {
DispatchQueue.main.async {
self.setCurrency(text: "\(self.from)\(value!)")
self.setCurrency(text: "\(value!)")
}
}
} catch let jsonError {
@ -68,6 +92,6 @@ class CurrencyBarItem: NSCustomTouchBarItem {
}
func setCurrency(text: String) {
button.title = text
button.title = "\(self.prefix)\(text)"
}
}