diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index 636d3ce..298ade0 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -9,8 +9,8 @@ import Cocoa class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate { - private let tapClosure: () -> ()? - private let longTapClosure: () -> ()? + private let tapClosure: (() -> ())? + private let longTapClosure: (() -> ())? private(set) var button: NSButton! private var singleClick: NSClickGestureRecognizer! @@ -59,7 +59,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat switch gr.state { case .ended: hf.tap(strong: 2) - self.tapClosure() + self.tapClosure?() break default: break @@ -70,12 +70,12 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat let hf: HapticFeedback = HapticFeedback() switch gr.state { case .began: - if self.longTapClosure != nil { + if let closure = self.longTapClosure { hf.tap(strong: 2) - self.longTapClosure() - } else { + closure() + } else if let closure = self.tapClosure { hf.tap(strong: 6) - self.tapClosure() + closure() print("long click") } break diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index d2632b7..7d44dfc 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -231,7 +231,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub public func getDockPersistentAppsList() -> [DockItem] { var returnable: [DockItem] = [] - for (index, bundleIdentifier) in persistentAppIdentifiers.enumerated() { + for bundleIdentifier in persistentAppIdentifiers { if !self.runningAppsIdentifiers.contains(bundleIdentifier) { let dockItem = DockItem(bundleIdentifier: bundleIdentifier, icon: getIcon(forBundleIdentifier: bundleIdentifier)) returnable.append(dockItem) diff --git a/MTMR/Widgets/BatteryBarItem.swift b/MTMR/Widgets/BatteryBarItem.swift index ef9462d..6d07354 100644 --- a/MTMR/Widgets/BatteryBarItem.swift +++ b/MTMR/Widgets/BatteryBarItem.swift @@ -35,13 +35,12 @@ class BatteryInfo: NSObject { var ACPower: String = "" var timeRemaining: String = "" - var button: NSButton? + var button: NSButton var loop:CFRunLoopSource? init(button: NSButton) { - super.init() - self.button = button + super.init() self.start() } @@ -135,11 +134,12 @@ class BatteryInfo: NSObject { color = NSColor.red } - let newTitle = NSMutableAttributedString(string: title as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: button?.attributedTitle.attribute(NSAttributedStringKey.font, at: 0, effectiveRange: nil), NSAttributedStringKey.baselineOffset: 1]) + let regularFont = button.attributedTitle.attribute(.font, at: 0, effectiveRange: nil) as? NSFont ?? NSFont.systemFont(ofSize: 15) + let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont, .baselineOffset: 1]) let newTitleSecond = NSMutableAttributedString(string: timeRemaining as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 8, weight: .regular), NSAttributedStringKey.baselineOffset: 7]) newTitle.append(newTitleSecond) newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count)) - button?.attributedTitle = newTitle + button.attributedTitle = newTitle } } diff --git a/MTMR/Widgets/CurrencyBarItem.swift b/MTMR/Widgets/CurrencyBarItem.swift index 2a4b512..9e9137d 100644 --- a/MTMR/Widgets/CurrencyBarItem.swift +++ b/MTMR/Widgets/CurrencyBarItem.swift @@ -109,7 +109,8 @@ class CurrencyBarItem: CustomButtonTouchBarItem { let title = String(format: "%@%.2f", self.prefix, value) - let newTitle = NSMutableAttributedString(string: title as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: button.attributedTitle.attribute(NSAttributedStringKey.font, at: 0, effectiveRange: nil)]) + let regularFont = button.attributedTitle.attribute(.font, at: 0, effectiveRange: nil) as? NSFont ?? NSFont.systemFont(ofSize: 15) + let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont]) newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count)) button.attributedTitle = newTitle }