1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 09:28:38 +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 { class CurrencyBarItem: NSCustomTouchBarItem {
private var timer: Timer! private var timer: Timer!
private var interval: TimeInterval! private var interval: TimeInterval!
private var prefix: String
private var from: String private var from: String
private var to: String private var to: String
private let button = NSButton(title: "", target: nil, action: nil) 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) { init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) {
self.interval = interval self.interval = interval
self.from = from self.from = from
self.to = to self.to = to
if let prefix = currencies[from] {
self.prefix = prefix
} else {
self.prefix = from
}
super.init(identifier: identifier) super.init(identifier: identifier)
button.bezelColor = .clear button.bezelColor = .clear
@ -55,7 +79,7 @@ class CurrencyBarItem: NSCustomTouchBarItem {
} }
if value != nil { if value != nil {
DispatchQueue.main.async { DispatchQueue.main.async {
self.setCurrency(text: "\(self.from)\(value!)") self.setCurrency(text: "\(value!)")
} }
} }
} catch let jsonError { } catch let jsonError {
@ -68,6 +92,6 @@ class CurrencyBarItem: NSCustomTouchBarItem {
} }
func setCurrency(text: String) { func setCurrency(text: String) {
button.title = text button.title = "\(self.prefix)\(text)"
} }
} }