Browse Source

Imp fixes!

pull/92/head
Abhishek 5 years ago
parent
commit
331b667797
  1. 28
      Clocker/Events and Reminders/CalendarHandler.swift
  2. 23
      Clocker/Menu Bar/StatusContainerView.swift

28
Clocker/Events and Reminders/CalendarHandler.swift

@ -53,6 +53,34 @@ extension EventCenter {
return sourcesAndCalendars
}
func isThereAnUpcomingCalendarEvent() -> Bool {
if DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
let filteredDates = EventCenter.sharedCenter().eventsForDate
let autoupdatingCal = EventCenter.sharedCenter().autoupdatingCalendar
guard let events = filteredDates[autoupdatingCal.startOfDay(for: Date())] else {
return false
}
for event in events {
if event.event.startDate.timeIntervalSinceNow > 0, !event.isAllDay {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
print("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}
return true
}
}
}
return false
}
/* Used for the compact menubar mode.
Returns a tuple with 0 as the header string and 1 as the subtitle string
*/
func separateFormat(event: EKEvent) -> (String, String)? {
guard let truncateLength = DataStore.shared().retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title else {
return nil

23
Clocker/Menu Bar/StatusContainerView.swift

@ -77,8 +77,9 @@ class StatusContainerView: NSView {
if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject))
let operationObject = TimezoneDataOperations(with: timezoneObject)
let calculatedSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeAttributes)
return result + calculatedSize.width + bufferWidth
let calculatedSubtitleSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeAttributes)
let calculatedTitleSize = compactModeTimeFont.size(operationObject.compactMenuTitle(), precalculatedWidth, attributes: timeAttributes)
return result + max(calculatedTitleSize.width, calculatedSubtitleSize.width) + bufferWidth
}
return result + CGFloat(bufferCalculatedWidth())
@ -114,10 +115,11 @@ class StatusContainerView: NSView {
private func bestWidth(for timezone: TimezoneData) -> Int {
let operation = TimezoneDataOperations(with: timezone)
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(),
Double(compactWidth(for: timezone)), attributes: timeAttributes)
let bestTitleSize = compactModeTimeFont.size(operation.compactMenuTitle(), Double(compactWidth(for: timezone)), attributes: timeAttributes)
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(), Double(compactWidth(for: timezone)), attributes: timeAttributes)
return Int(bestSize.width + bufferWidth)
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth)
}
func updateTime() {
@ -126,16 +128,25 @@ class StatusContainerView: NSView {
}
// See if frame's width needs any adjustment
adjustWidthIfNeccessary()
}
private func adjustWidthIfNeccessary() {
var newWidth: CGFloat = 0
subviews.forEach {
if let statusItem = $0 as? StatusItemView {
if let statusItem = $0 as? StatusItemView, statusItem.isHidden == false {
// Determine what's the best width required to display the current string.
let newBestWidth = CGFloat(bestWidth(for: statusItem.dataObject))
// Let's note if the current width is too small/correct
newWidth += statusItem.frame.size.width != newBestWidth ? newBestWidth : statusItem.frame.size.width
statusItem.frame = CGRect(x: statusItem.frame.origin.x,
y: statusItem.frame.origin.y,
width: newBestWidth,
height: statusItem.frame.size.height)
statusItem.updateTimeInMenubar()
}
}

Loading…
Cancel
Save