Browse Source

Swiftformat.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
1c569432b6
  1. 1
      Clocker/Preferences/Calendar/CalendarViewController.swift
  2. 48
      Clocker/Preferences/Menu Bar/StatusContainerView.swift
  3. 3
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

1
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -5,7 +5,6 @@ import CoreLoggerKit
import EventKit import EventKit
class ClockerTextBackgroundView: NSView { class ClockerTextBackgroundView: NSView {
override func awakeFromNib() { override func awakeFromNib() {
wantsLayer = true wantsLayer = true
layer?.cornerRadius = 8.0 layer?.cornerRadius = 8.0

48
Clocker/Preferences/Menu Bar/StatusContainerView.swift

@ -4,11 +4,11 @@ import Cocoa
import CoreLoggerKit import CoreLoggerKit
import CoreModelKit import CoreModelKit
func compactWidth(for timezone: TimezoneData) -> Int { func compactWidth(for timezone: TimezoneData, with store: DataStore) -> Int {
var totalWidth = 55 var totalWidth = 55
let timeFormat = timezone.timezoneFormat(DataStore.shared().timezoneFormat()) let timeFormat = timezone.timezoneFormat(store.timezoneFormat())
if DataStore.shared().shouldShowDayInMenubar() { if store.shouldShowDayInMenubar() {
totalWidth += 12 totalWidth += 12
} }
@ -24,12 +24,12 @@ func compactWidth(for timezone: TimezoneData) -> Int {
totalWidth += 0 totalWidth += 0
} }
if timezone.shouldShowSeconds(DataStore.shared().timezoneFormat()) { if timezone.shouldShowSeconds(store.timezoneFormat()) {
// Slight buffer needed when the Menubar supplementary text was Mon 9:27:58 AM // Slight buffer needed when the Menubar supplementary text was Mon 9:27:58 AM
totalWidth += 15 totalWidth += 15
} }
if DataStore.shared().shouldShowDateInMenubar() { if store.shouldShowDateInMenubar() {
totalWidth += 20 totalWidth += 20
} }
@ -49,6 +49,7 @@ protocol StatusItemViewConforming {
class StatusContainerView: NSView { class StatusContainerView: NSView {
private var previousX: Int = 0 private var previousX: Int = 0
private let store: DataStore
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
@ -56,7 +57,13 @@ class StatusContainerView: NSView {
layer?.backgroundColor = NSColor.clear.cgColor layer?.backgroundColor = NSColor.clear.cgColor
} }
init(with timezones: [Data], showUpcomingEventView: Bool, bufferContainerWidth: Int) { init(with timezones: [Data],
store: DataStore,
showUpcomingEventView: Bool,
bufferContainerWidth: Int)
{
self.store = store
func addSubviews() { func addSubviews() {
if showUpcomingEventView, if showUpcomingEventView,
let events = EventCenter.sharedCenter().eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: Date())], let events = EventCenter.sharedCenter().eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: Date())],
@ -88,11 +95,15 @@ class StatusContainerView: NSView {
var compressedWidth = timezones.reduce(0.0) { result, timezone -> CGFloat in var compressedWidth = timezones.reduce(0.0) { result, timezone -> CGFloat in
if let timezoneObject = TimezoneData.customObject(from: timezone) { if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) let precalculatedWidth = Double(compactWidth(for: timezoneObject, with: store))
let operationObject = TimezoneDataOperations(with: timezoneObject) let operationObject = TimezoneDataOperations(with: timezoneObject)
let calculatedSubtitleSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeBasedAttributes) let calculatedSubtitleSize = compactModeTimeFont.size(for: operationObject.compactMenuSubtitle(),
let calculatedTitleSize = compactModeTimeFont.size(operationObject.compactMenuTitle(), precalculatedWidth, attributes: timeBasedAttributes) width: precalculatedWidth,
let showSeconds = timezoneObject.shouldShowSeconds(DataStore.shared().timezoneFormat()) attributes: timeBasedAttributes)
let calculatedTitleSize = compactModeTimeFont.size(for: operationObject.compactMenuTitle(),
width: precalculatedWidth,
attributes: timeBasedAttributes)
let showSeconds = timezoneObject.shouldShowSeconds(store.timezoneFormat())
let secondsBuffer: CGFloat = showSeconds ? 7 : 0 let secondsBuffer: CGFloat = showSeconds ? 7 : 0
return result + max(calculatedTitleSize.width, calculatedSubtitleSize.width) + bufferWidth + secondsBuffer return result + max(calculatedTitleSize.width, calculatedSubtitleSize.width) + bufferWidth + secondsBuffer
} }
@ -148,9 +159,12 @@ class StatusContainerView: NSView {
] ]
let operation = TimezoneDataOperations(with: timezone) let operation = TimezoneDataOperations(with: timezone)
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(), let bestSize = compactModeTimeFont.size(for: operation.compactMenuSubtitle(),
Double(compactWidth(for: timezone)), attributes: timeBasedAttributes) width: Double(compactWidth(for: timezone, with: store)),
let bestTitleSize = compactModeTimeFont.size(operation.compactMenuTitle(), Double(compactWidth(for: timezone)), attributes: timeBasedAttributes) attributes: timeBasedAttributes)
let bestTitleSize = compactModeTimeFont.size(for: operation.compactMenuTitle(),
width: Double(compactWidth(for: timezone, with: store)),
attributes: timeBasedAttributes)
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth) return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth)
} }
@ -169,11 +183,11 @@ class StatusContainerView: NSView {
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle,
] ]
let bestSize = compactModeTimeFont.size(eventInfo.metadataForMeeting(), let bestSize = compactModeTimeFont.size(for: eventInfo.metadataForMeeting(),
55, // Default for a location based status view width: 55, // Default for a location based status view
attributes: timeBasedAttributes) attributes: timeBasedAttributes)
let bestTitleSize = compactModeTimeFont.size(eventInfo.event.title, let bestTitleSize = compactModeTimeFont.size(for: eventInfo.event.title,
70, // Little more buffer since meeting titles tend to be longer width: 70, // Little more buffer since meeting titles tend to be longer
attributes: timeBasedAttributes) attributes: timeBasedAttributes)
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth) return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth)

3
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -66,7 +66,7 @@ class StatusItemHandler: NSObject {
} }
init(with dataStore: DataStore) { init(with dataStore: DataStore) {
self.store = dataStore store = dataStore
super.init() super.init()
setupStatusItem() setupStatusItem()
@ -148,6 +148,7 @@ class StatusItemHandler: NSObject {
} }
statusContainerView = StatusContainerView(with: menubarTimezones, statusContainerView = StatusContainerView(with: menubarTimezones,
store: store,
showUpcomingEventView: upcomingEventView, showUpcomingEventView: upcomingEventView,
bufferContainerWidth: bufferCalculatedWidth()) bufferContainerWidth: bufferCalculatedWidth())
statusItem.view = statusContainerView statusItem.view = statusContainerView

Loading…
Cancel
Save