Browse Source

Linting.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
cc8d4429a7
  1. 6
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  2. 7
      Clocker/Dependencies/Date Additions/Date+TimeAgo.swift
  3. 2
      Clocker/Dependencies/Date Additions/TimePeriodCollection.swift
  4. 44
      Clocker/Dependencies/Solar.swift
  5. 73
      Clocker/Overall App/DataStore.swift
  6. 19
      Clocker/Panel/Data Layer/TimezoneData.swift
  7. 20
      Clocker/Panel/Notes Popover/NotesPopover.swift
  8. 16
      Clocker/Panel/PanelController.swift
  9. 2
      Clocker/Panel/ParentPanelController.swift
  10. 2
      Clocker/Panel/UI/CustomSliderCell.swift
  11. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  12. 6
      Clocker/Preferences/General/PreferencesViewController.swift

6
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -90,7 +90,11 @@ class ClockerUnitTests: XCTestCase {
func testDeletingATimezone() { func testDeletingATimezone() {
let defaults = UserDefaults.standard let defaults = UserDefaults.standard
var currentFavourites = defaults.object(forKey: CLDefaultPreferenceKey) as! [Data]
guard var currentFavourites = defaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else {
XCTFail("Default preferences aren't in the correct format")
return
}
let oldCount = currentFavourites.count let oldCount = currentFavourites.count
currentFavourites = currentFavourites.filter { currentFavourites = currentFavourites.filter {

7
Clocker/Dependencies/Date Additions/Date+TimeAgo.swift

@ -173,12 +173,7 @@ public extension Date {
} }
private func logicalLocalizedStringFromFormat(format: String, value: Int) -> String { private func logicalLocalizedStringFromFormat(format: String, value: Int) -> String {
#if os(Linux) let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value)))
let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value)) as! CVarArg) // this may not work, unclear!!
#else
let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value)))
#endif
return String.init(format: DateToolsLocalizedStrings(localeFormat), value) return String.init(format: DateToolsLocalizedStrings(localeFormat), value)
} }

2
Clocker/Dependencies/Date Additions/TimePeriodCollection.swift

@ -238,7 +238,7 @@ open class TimePeriodCollection: TimePeriodGroup {
} }
internal func updateExtremes() { internal func updateExtremes() {
if periods.count == 0 { if periods.isEmpty {
_beginning = nil _beginning = nil
_end = nil _end = nil
} else { } else {

44
Clocker/Dependencies/Solar.swift

@ -78,35 +78,35 @@ public struct Solar {
let lngHour = coordinate.longitude / 15 let lngHour = coordinate.longitude / 15
let hourTime: Double = sunriseSunset == .sunrise ? 6 : 18 let hourTime: Double = sunriseSunset == .sunrise ? 6 : 18
let t = day + ((hourTime - lngHour) / 24) let time = day + ((hourTime - lngHour) / 24)
// Calculate the suns mean anomaly // Calculate the suns mean anomaly
let M = (0.9856 * t) - 3.289 let meanAnomaly = (0.9856 * time) - 3.289
// Calculate the sun's true longitude // Calculate the sun's true longitude
let subexpression1 = 1.916 * sin(M.degreesToRadians) let subexpression1 = 1.916 * sin(meanAnomaly.degreesToRadians)
let subexpression2 = 0.020 * sin(2 * M.degreesToRadians) let subexpression2 = 0.020 * sin(2 * meanAnomaly.degreesToRadians)
var L = M + subexpression1 + subexpression2 + 282.634 var longitude = meanAnomaly + subexpression1 + subexpression2 + 282.634
// Normalise L into [0, 360] range // Normalise L into [0, 360] range
L = normalise(L, withMaximum: 360) longitude = normalise(longitude, withMaximum: 360)
// Calculate the Sun's right ascension // Calculate the Sun's right ascension
var RA = atan(0.91764 * tan(L.degreesToRadians)).radiansToDegrees var rightAscenscion = atan(0.91764 * tan(longitude.degreesToRadians)).radiansToDegrees
// Normalise RA into [0, 360] range // Normalise RA into [0, 360] range
RA = normalise(RA, withMaximum: 360) rightAscenscion = normalise(rightAscenscion, withMaximum: 360)
// Right ascension value needs to be in the same quadrant as L... // Right ascension value needs to be in the same quadrant as L...
let Lquadrant = floor(L / 90) * 90 let Lquadrant = floor(longitude / 90) * 90
let RAquadrant = floor(RA / 90) * 90 let RAquadrant = floor(rightAscenscion / 90) * 90
RA = RA + (Lquadrant - RAquadrant) rightAscenscion = rightAscenscion + (Lquadrant - RAquadrant)
// Convert RA into hours // Convert RA into hours
RA = RA / 15 rightAscenscion = rightAscenscion / 15
// Calculate Sun's declination // Calculate Sun's declination
let sinDec = 0.39782 * sin(L.degreesToRadians) let sinDec = 0.39782 * sin(longitude.degreesToRadians)
let cosDec = cos(asin(sinDec)) let cosDec = cos(asin(sinDec))
// Calculate the Sun's local hour angle // Calculate the Sun's local hour angle
@ -124,24 +124,24 @@ public struct Solar {
// Finish calculating H and convert into hours // Finish calculating H and convert into hours
let tempH = sunriseSunset == .sunrise ? 360 - acos(cosH).radiansToDegrees : acos(cosH).radiansToDegrees let tempH = sunriseSunset == .sunrise ? 360 - acos(cosH).radiansToDegrees : acos(cosH).radiansToDegrees
let H = tempH / 15.0 let hours = tempH / 15.0
// Calculate local mean time of rising // Calculate local mean time of rising
let T = H + RA - (0.06571 * t) - 6.622 let localMeanRisingTime = hours + rightAscenscion - (0.06571 * time) - 6.622
// Adjust time back to UTC // Adjust time back to UTC
var UT = T - lngHour var utcCompatibleTime = localMeanRisingTime - lngHour
// Normalise UT into [0, 24] range // Normalise UT into [0, 24] range
UT = normalise(UT, withMaximum: 24) utcCompatibleTime = normalise(utcCompatibleTime, withMaximum: 24)
// Calculate all of the sunrise's / sunset's date components // Calculate all of the sunrise's / sunset's date components
let hour = floor(UT) let hour = floor(utcCompatibleTime)
let minute = floor((UT - hour) * 60.0) let minute = floor((utcCompatibleTime - hour) * 60.0)
let second = (((UT - hour) * 60) - minute) * 60.0 let second = (((utcCompatibleTime - hour) * 60) - minute) * 60.0
let shouldBeYesterday = lngHour > 0 && UT > 12 && sunriseSunset == .sunrise let shouldBeYesterday = lngHour > 0 && utcCompatibleTime > 12 && sunriseSunset == .sunrise
let shouldBeTomorrow = lngHour < 0 && UT < 12 && sunriseSunset == .sunset let shouldBeTomorrow = lngHour < 0 && utcCompatibleTime < 12 && sunriseSunset == .sunset
let setDate: Date let setDate: Date
if shouldBeYesterday { if shouldBeYesterday {

73
Clocker/Overall App/DataStore.swift

@ -81,85 +81,44 @@ class DataStore: NSObject {
userDefaults.set(currentLineup, forKey: CLDefaultPreferenceKey) userDefaults.set(currentLineup, forKey: CLDefaultPreferenceKey)
} }
private func shouldDisplayHelper(_ key: String) -> Bool {
guard let value = retrieve(key: key) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
}
func shouldDisplay(_ type: ViewType) -> Bool { func shouldDisplay(_ type: ViewType) -> Bool {
switch type { switch type {
case .futureSlider: case .futureSlider:
guard let value = retrieve(key: CLDisplayFutureSliderKey) as? NSNumber else { return shouldDisplayHelper(CLDisplayFutureSliderKey)
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .upcomingEventView: case .upcomingEventView:
guard let value = retrieve(key: CLShowUpcomingEventView) as? NSString else { guard let value = retrieve(key: CLShowUpcomingEventView) as? NSString else {
return false return false
} }
return value == "YES" return value == "YES"
case .twelveHour: case .twelveHour:
return shouldDisplayHelper(CL24hourFormatSelectedKey)
guard let value = retrieve(key: CL24hourFormatSelectedKey) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .showAllDayEventsInMenubar: case .showAllDayEventsInMenubar:
return shouldDisplayHelper(CLShowAllDayEventsInUpcomingView)
guard let value = retrieve(key: CLShowAllDayEventsInUpcomingView) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .sunrise: case .sunrise:
return shouldDisplayHelper(CLSunriseSunsetTime)
guard let value = retrieve(key: CLSunriseSunsetTime) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .seconds: case .seconds:
return shouldDisplayHelper(CLShowSecondsInMenubar)
guard let value = retrieve(key: CLShowSecondsInMenubar) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .showMeetingInMenubar: case .showMeetingInMenubar:
return shouldDisplayHelper(CLShowMeetingInMenubar)
guard let value = retrieve(key: CLShowMeetingInMenubar) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .showAppInForeground: case .showAppInForeground:
guard let value = retrieve(key: CLShowAppInForeground) as? NSNumber else { guard let value = retrieve(key: CLShowAppInForeground) as? NSNumber else {
return false return false
} }
return value.isEqual(to: NSNumber(value: 1)) return value.isEqual(to: NSNumber(value: 1))
case .dateInMenubar: case .dateInMenubar:
return shouldDisplayHelper(CLShowDateInMenu)
guard let value = retrieve(key: CLShowDateInMenu) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .placeInMenubar: case .placeInMenubar:
return shouldDisplayHelper(CLShowPlaceInMenu)
guard let value = retrieve(key: CLShowPlaceInMenu) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .dayInMenubar: case .dayInMenubar:
return shouldDisplayHelper(CLShowDayInMenu)
guard let value = retrieve(key: CLShowDayInMenu) as? NSNumber else {
return false
}
return value.isEqual(to: NSNumber(value: 0))
case .menubarCompactMode: case .menubarCompactMode:
guard let value = retrieve(key: CLMenubarCompactMode) as? Int else { guard let value = retrieve(key: CLMenubarCompactMode) as? Int else {
return false return false
} }

19
Clocker/Panel/Data Layer/TimezoneData.swift

@ -30,8 +30,8 @@ class TimezoneData: NSObject, NSCoding {
} }
enum SecondsOverride: Int { enum SecondsOverride: Int {
case yes case showSeconds
case no case hideSeconds
case globalFormat case globalFormat
} }
@ -87,7 +87,7 @@ class TimezoneData: NSObject, NSCoding {
overrideSecondsFormat = .globalFormat overrideSecondsFormat = .globalFormat
} }
init(with dictionary: Dictionary<String, Any>) { init(with dictionary: [String: Any]) {
if let label = dictionary[CLCustomLabel] as? String { if let label = dictionary[CLCustomLabel] as? String {
customLabel = label customLabel = label
} else { } else {
@ -338,9 +338,9 @@ class TimezoneData: NSObject, NSCoding {
func setShouldOverrideSecondsFormat(_ shouldOverride: Int) { func setShouldOverrideSecondsFormat(_ shouldOverride: Int) {
if shouldOverride == 0 { if shouldOverride == 0 {
overrideSecondsFormat = .yes overrideSecondsFormat = .showSeconds
} else if shouldOverride == 1 { } else if shouldOverride == 1 {
overrideSecondsFormat = .no overrideSecondsFormat = .hideSeconds
} else { } else {
overrideSecondsFormat = .globalFormat overrideSecondsFormat = .globalFormat
} }
@ -410,7 +410,7 @@ class TimezoneData: NSObject, NSCoding {
return DataStore.shared().shouldDisplay(.seconds) return DataStore.shared().shouldDisplay(.seconds)
} }
return overrideSecondsFormat == .yes return overrideSecondsFormat == .showSeconds
} }
override var hash: Int { override var hash: Int {
@ -425,6 +425,13 @@ class TimezoneData: NSObject, NSCoding {
return lhs.placeID == rhs.placeID return lhs.placeID == rhs.placeID
} }
override func isEqual(to object: Any?) -> Bool {
if let other = object as? TimezoneData {
return placeID == other.placeID
}
return false
}
override func isEqual(_ object: Any?) -> Bool { override func isEqual(_ object: Any?) -> Bool {
guard let compared = object as? TimezoneData else { guard let compared = object as? TimezoneData else {
return false return false

20
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -320,12 +320,10 @@ class NotesPopover: NSViewController {
} }
} }
for timezoneObject in timezoneObjects { for timezoneObject in timezoneObjects where timezoneObject == dataObject {
if timezoneObject == dataObject { overrideType == .timezoneFormat ?
overrideType == .timezoneFormat ? timezoneObject.setShouldOverrideGlobalTimeFormat(override) :
timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideSecondsFormat(override)
timezoneObject.setShouldOverrideSecondsFormat(override)
}
} }
var datas: [Data] = [] var datas: [Data] = []
@ -351,12 +349,10 @@ class NotesPopover: NSViewController {
} }
} }
for timezoneObject in timezoneObjects { for timezoneObject in timezoneObjects where timezoneObject == dataObject {
if timezoneObject == dataObject { overrideType == .timezoneFormat ?
overrideType == .timezoneFormat ? timezoneObject.setShouldOverrideGlobalTimeFormat(override) :
timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideSecondsFormat(override)
timezoneObject.setShouldOverrideSecondsFormat(override)
}
} }
var datas: [Data] = [] var datas: [Data] = []

16
Clocker/Panel/PanelController.swift

@ -46,7 +46,7 @@ class PanelController: ParentPanelController {
func setFrameTheNewWay(_ rect: NSRect, _ maxX: CGFloat) { func setFrameTheNewWay(_ rect: NSRect, _ maxX: CGFloat) {
// Calculate window's top left point. // Calculate window's top left point.
// First, center window under status item. // First, center window under status item.
let w = CGFloat(NSWidth((window?.frame)!)) let w = (window?.frame)!.width
var x = CGFloat(roundf(Float(rect.midX - w / 2))) var x = CGFloat(roundf(Float(rect.midX - w / 2)))
let y = CGFloat(rect.minY - 2) let y = CGFloat(rect.minY - 2)
let kMinimumSpaceBetweenWindowAndScreenEdge: CGFloat = 10 let kMinimumSpaceBetweenWindowAndScreenEdge: CGFloat = 10
@ -120,15 +120,15 @@ class PanelController: ParentPanelController {
var testPoint = statusItemFrame.origin var testPoint = statusItemFrame.origin
testPoint.y -= 100 testPoint.y -= 100
for screen in NSScreen.screens { for screen in NSScreen.screens where screen.frame.contains(testPoint) {
if NSPointInRect(testPoint, screen.frame) { statusItemScreen = screen
statusItemScreen = screen break
break
}
} }
let screenMaxX = NSMaxX((statusItemScreen?.frame)!) let screenMaxX = (statusItemScreen?.frame)!.maxX
let minY = statusItemFrame.origin.y < NSMaxY((statusItemScreen?.frame)!) ? statusItemFrame.origin.y : NSMaxY((statusItemScreen?.frame)!) let minY = statusItemFrame.origin.y < (statusItemScreen?.frame)!.maxY ?
statusItemFrame.origin.y :
(statusItemScreen?.frame)!.maxY
statusItemFrame.origin.y = minY statusItemFrame.origin.y = minY
setFrameTheNewWay(statusItemFrame, screenMaxX) setFrameTheNewWay(statusItemFrame, screenMaxX)

2
Clocker/Panel/ParentPanelController.swift

@ -378,7 +378,7 @@ class ParentPanelController: NSWindowController {
} }
// This is for the Add Cell View case // This is for the Add Cell View case
if preferences.count == 0 { if preferences.isEmpty {
scrollViewHeight.constant = 100.0 scrollViewHeight.constant = 100.0
return return
} }

2
Clocker/Panel/UI/CustomSliderCell.swift

@ -14,7 +14,7 @@ class CustomSliderCell: NSSliderCell {
return return
} }
let finalWidth = value * (NSWidth(control.frame) - 8) let finalWidth = value * (control.frame.width - 8)
// Left Part // Left Part
var leftRect = rect var leftRect = rect

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -151,7 +151,7 @@ class AppearanceViewController: ParentViewController {
panelController.sharingButton.image = Themer.shared().sharingImage() panelController.sharingButton.image = Themer.shared().sharingImage()
let defaultTimezones = panelController.defaultPreferences let defaultTimezones = panelController.defaultPreferences
if defaultTimezones.count == 0 { if defaultTimezones.isEmpty {
panelController.updatePanelColor() panelController.updatePanelColor()
} }

6
Clocker/Preferences/General/PreferencesViewController.swift

@ -218,7 +218,7 @@ class PreferencesViewController: ParentViewController {
[placeholderLabel, additionalSortOptions].forEach { $0.isHidden = true } [placeholderLabel, additionalSortOptions].forEach { $0.isHidden = true }
if timezoneArray.count == 0 { if timezoneArray.isEmpty {
timezoneArray.append("UTC") timezoneArray.append("UTC")
timezoneArray.append("Anywhere on Earth") timezoneArray.append("Anywhere on Earth")
timezoneArray.append(contentsOf: NSTimeZone.knownTimeZoneNames) timezoneArray.append(contentsOf: NSTimeZone.knownTimeZoneNames)
@ -936,7 +936,7 @@ extension PreferencesViewController {
return return
} }
if messageLabel.stringValue.count == 0 { if messageLabel.stringValue.isEmpty {
searchField.stringValue = CLEmptyString searchField.stringValue = CLEmptyString
guard let latitude = dataObject.latitude, let longitude = dataObject.longitude else { guard let latitude = dataObject.latitude, let longitude = dataObject.longitude else {
@ -1075,7 +1075,7 @@ extension PreferencesViewController {
refreshMainTable() refreshMainTable()
if selectedTimeZones.count == 0 { if selectedTimeZones.isEmpty {
UserDefaults.standard.set(nil, forKey: CLMenubarFavorites) UserDefaults.standard.set(nil, forKey: CLMenubarFavorites)
} }

Loading…
Cancel
Save