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

Background color parameter moved to CustomButtonTouchBarItem for future ability to change from config file

This commit is contained in:
ad 2018-04-21 15:01:09 +03:00
parent 9bf42dfb79
commit bb978f2de5
6 changed files with 8 additions and 11 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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()
}

View File

@ -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:

View File

@ -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()