mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
* currency list
This commit is contained in:
parent
42c1ff27c4
commit
242e2d3c22
@ -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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user