diff --git a/MTMR/CurrencyBarItem.swift b/MTMR/CurrencyBarItem.swift index af05bbd..8d2ed32 100644 --- a/MTMR/CurrencyBarItem.swift +++ b/MTMR/CurrencyBarItem.swift @@ -9,14 +9,13 @@ import Cocoa import CoreLocation -class CurrencyBarItem: NSCustomTouchBarItem { +class CurrencyBarItem: CustomButtonTouchBarItem { private var timer: Timer! private var interval: TimeInterval! private var prefix: String private var from: String private var to: String private var oldValue: Float32! - private let button = NSButton(title: "", target: nil, action: nil) private let currencies = [ "USD": "$", @@ -35,7 +34,7 @@ class CurrencyBarItem: NSCustomTouchBarItem { "CHF": "Fr." ] - init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) { + init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, onTap: @escaping () -> ()) { self.interval = interval self.from = from self.to = to @@ -46,10 +45,9 @@ class CurrencyBarItem: NSCustomTouchBarItem { self.prefix = from } - super.init(identifier: identifier) + super.init(identifier: identifier, title: "⏳", onTap: onTap) button.bezelColor = .clear - button.title = "⏳" self.view = button timer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(updateCurrency), userInfo: nil, repeats: true) diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 11bae48..4cf4086 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -179,9 +179,9 @@ class TouchBarController: NSObject, NSTouchBarDelegate { barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval) } case .weather(interval: let interval, units: let units, api_key: let api_key, icon_type: let icon_type): - barItem = WeatherBarItem(identifier: identifier, interval: interval, units: units, api_key: api_key, icon_type: icon_type) + barItem = WeatherBarItem(identifier: identifier, interval: interval, units: units, api_key: api_key, icon_type: icon_type, onTap: action) case .currency(interval: let interval, from: let from, to: let to): - barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to) + barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, onTap: action) } if case .width(let value)? = item.additionalParameters[.width], let widthBarItem = barItem as? CanSetWidth { diff --git a/MTMR/WeatherBarItem.swift b/MTMR/WeatherBarItem.swift index 6092d5b..9ace384 100644 --- a/MTMR/WeatherBarItem.swift +++ b/MTMR/WeatherBarItem.swift @@ -9,14 +9,13 @@ import Cocoa import CoreLocation -class WeatherBarItem: NSCustomTouchBarItem, CLLocationManagerDelegate { +class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate { private let dateFormatter = DateFormatter() private var timer: Timer! private var interval: TimeInterval! private var units: String private var api_key: String private var units_str = "°F" - private let button = NSButton(title: "", target: nil, action: nil) private var prev_location: CLLocation! private var location: CLLocation! private let iconsImages = ["01d": "☀️", "01n": "☀️", "02d": "⛅️", "02n": "⛅️", "03d": "☁️", "03n": "☁️", "04d": "☁️", "04n": "☁️", "09d": "⛅️", "09n": "⛅️", "10d": "🌦", "10n": "🌦", "11d": "🌩", "11n": "🌩", "13d": "❄️", "13n": "❄️", "50d": "🌫", "50n": "🌫"] @@ -25,7 +24,7 @@ class WeatherBarItem: NSCustomTouchBarItem, CLLocationManagerDelegate { private var manager:CLLocationManager! - init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, units: String, api_key: String, icon_type: String? = "text") { + init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, units: String, api_key: String, icon_type: String? = "text", onTap: @escaping () -> ()) { self.interval = interval self.units = units self.api_key = api_key @@ -40,10 +39,9 @@ class WeatherBarItem: NSCustomTouchBarItem, CLLocationManagerDelegate { iconsSource = iconsText } - super.init(identifier: identifier) + super.init(identifier: identifier, title: "⏳", onTap: onTap) button.bezelColor = .clear - button.title = "⏳" self.view = button let status = CLLocationManager.authorizationStatus()