From bb978f2de5f5e3b0fde77e77e76579ebed09028b Mon Sep 17 00:00:00 2001 From: ad Date: Sat, 21 Apr 2018 15:01:09 +0300 Subject: [PATCH] Background color parameter moved to CustomButtonTouchBarItem for future ability to change from config file --- MTMR/BatteryBarItem.swift | 1 - MTMR/CurrencyBarItem.swift | 1 - MTMR/CustomButtonTouchBarItem.swift | 3 ++- MTMR/TimeTouchBarItem.swift | 9 ++++----- MTMR/TouchBarController.swift | 4 ++-- MTMR/WeatherBarItem.swift | 1 - 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/MTMR/BatteryBarItem.swift b/MTMR/BatteryBarItem.swift index 4cf7c1d..296cdc1 100644 --- a/MTMR/BatteryBarItem.swift +++ b/MTMR/BatteryBarItem.swift @@ -15,7 +15,6 @@ class BatteryBarItem: CustomButtonTouchBarItem { init(identifier: NSTouchBarItem.Identifier, onTap: @escaping () -> (), onLongTap: @escaping () -> ()) { super.init(identifier: identifier, title: " ", onTap: onTap, onLongTap: onLongTap) self.view = button - button.bezelColor = .clear let batteryInfo = BatteryInfo(button: button) batteryInfo.start() diff --git a/MTMR/CurrencyBarItem.swift b/MTMR/CurrencyBarItem.swift index ae2e0fa..0fe6b7b 100644 --- a/MTMR/CurrencyBarItem.swift +++ b/MTMR/CurrencyBarItem.swift @@ -50,7 +50,6 @@ class CurrencyBarItem: CustomButtonTouchBarItem { super.init(identifier: identifier, title: "⏳", onTap: onTap, onLongTap: onLongTap) - button.bezelColor = .clear self.view = button timer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(updateCurrency), userInfo: nil, repeats: true) diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index 96130b8..671d20f 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -16,12 +16,13 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat private var singleClick: NSClickGestureRecognizer! private var longClick: NSPressGestureRecognizer! - init(identifier: NSTouchBarItem.Identifier, title: String, onTap callback: @escaping () -> (), onLongTap callbackLong: @escaping () -> ()) { + init(identifier: NSTouchBarItem.Identifier, title: String, onTap callback: @escaping () -> (), onLongTap callbackLong: @escaping () -> (), bezelColor: NSColor? = .clear) { self.tapClosure = callback self.longTapClosure = callbackLong super.init(identifier: identifier) button = NSButton(title: title, target: self, action: nil) + button.bezelColor = bezelColor button.title = title self.view = button diff --git a/MTMR/TimeTouchBarItem.swift b/MTMR/TimeTouchBarItem.swift index 045db1c..7178dd6 100644 --- a/MTMR/TimeTouchBarItem.swift +++ b/MTMR/TimeTouchBarItem.swift @@ -1,16 +1,15 @@ import Cocoa -class TimeTouchBarItem: NSCustomTouchBarItem { +class TimeTouchBarItem: CustomButtonTouchBarItem { private let dateFormatter = DateFormatter() private var timer: Timer! - private let button = NSButton(title: "", target: nil, action: nil) +// private let button = NSButton(title: "", target: nil, action: nil) - init(identifier: NSTouchBarItem.Identifier, formatTemplate: String) { + init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, onTap: @escaping () -> (), onLongTap: @escaping () -> ()) { dateFormatter.setLocalizedDateFormatFromTemplate(formatTemplate) - super.init(identifier: identifier) + super.init(identifier: identifier, title: " ", onTap: onTap, onLongTap: onLongTap) timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true) self.view = button - button.bezelColor = .clear updateTime() } diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 4f68516..b4f7f4f 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -165,11 +165,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate { var barItem: NSTouchBarItem! switch item.type { case .staticButton(title: let title): - barItem = CustomButtonTouchBarItem(identifier: identifier, title: title, onTap: action, onLongTap: longAction) + barItem = CustomButtonTouchBarItem(identifier: identifier, title: title, onTap: action, onLongTap: longAction, bezelColor: NSColor.controlColor) case .appleScriptTitledButton(source: let source, refreshInterval: let interval): barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval, onTap: action, onLongTap: longAction) case .timeButton(formatTemplate: let template): - barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template) + barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, onTap: action, onLongTap: longAction) case .battery(): barItem = BatteryBarItem(identifier: identifier, onTap: action, onLongTap: longAction) case .dock: diff --git a/MTMR/WeatherBarItem.swift b/MTMR/WeatherBarItem.swift index a8dac74..4104027 100644 --- a/MTMR/WeatherBarItem.swift +++ b/MTMR/WeatherBarItem.swift @@ -45,7 +45,6 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate { super.init(identifier: identifier, title: "⏳", onTap: onTap, onLongTap: onLongTap) - button.bezelColor = .clear self.view = button let status = CLLocationManager.authorizationStatus()