Browse Source

Formatting.

pull/101/head
Abhishek Banthia 3 years ago
parent
commit
f26556cf53
  1. 7
      Clocker/Preferences/General/PreferencesDataSource.swift
  2. 45
      Clocker/Preferences/General/PreferencesViewController.swift
  3. 2
      Clocker/Preferences/General/SearchDataSource.swift
  4. 2
      Clocker/Preferences/Menu Bar/MenubarHandler.swift
  5. 9
      Clocker/Preferences/Menu Bar/StatusContainerView.swift
  6. 4
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift
  7. 5
      Clocker/Preferences/Menu Bar/StatusItemView.swift

7
Clocker/Preferences/General/PreferencesDataSource.swift

@ -104,7 +104,8 @@ extension PreferencesDataSource: NSTableViewDataSource {
var selectedDataSource: TimezoneData?
if selectedTimezones.count > row,
let model = TimezoneData.customObject(from: selectedTimezones[row]) {
let model = TimezoneData.customObject(from: selectedTimezones[row])
{
selectedDataSource = model
}
@ -163,7 +164,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue,
],
for: "Custom Label Changed")
for: "Custom Label Changed")
dataObject.setLabel(formattedValue)
@ -176,7 +177,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Selected Timezone Count": selectedTimezones.count,
"Current Row": row,
],
for: "Error in selected row count")
for: "Error in selected row count")
}
}

45
Clocker/Preferences/General/PreferencesViewController.swift

@ -42,8 +42,9 @@ class PreferencesViewController: ParentViewController {
private var geocodingKey: String = {
guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile: path),
let apiKey = dictionary["GeocodingKey"] as? String else {
let dictionary = NSDictionary(contentsOfFile: path),
let apiKey = dictionary["GeocodingKey"] as? String
else {
assertionFailure("Unable to find the API key")
return ""
}
@ -203,7 +204,6 @@ class PreferencesViewController: ParentViewController {
timezoneTableView.enclosingScrollView?.isHidden = true
showNoTimezoneState()
cleanup()
return
}
private func cleanup() {
@ -274,10 +274,10 @@ class PreferencesViewController: ParentViewController {
return
}
let newHotKey: PTHotKey = PTHotKey(identifier: keyPath,
keyCombo: newShortcut,
target: self,
action: #selector(ping(_:)))
let newHotKey = PTHotKey(identifier: keyPath,
keyCombo: newShortcut,
target: self,
action: #selector(ping(_:)))
hotKeyCenter?.register(newHotKey)
}
@ -333,9 +333,10 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
for: "favouriteRemoved")
if let appDelegate = NSApplication.shared.delegate as? AppDelegate,
let menubarFavourites = DataStore.shared().menubarTimezones(),
menubarFavourites.isEmpty,
DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false {
let menubarFavourites = DataStore.shared().menubarTimezones(),
menubarFavourites.isEmpty,
DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false
{
appDelegate.invalidateMenubarTimer(true)
}
@ -453,7 +454,7 @@ extension PreferencesViewController {
self.prepareUIForPresentingResults()
}
})
})
}
}
@ -817,7 +818,7 @@ extension PreferencesViewController {
var newDefaults = selectedTimeZones
let objectsToRemove = timezoneTableView.selectedRowIndexes.map { (index) -> Data in
let objectsToRemove = timezoneTableView.selectedRowIndexes.map { index -> Data in
selectedTimeZones[index]
}
@ -896,12 +897,13 @@ extension PreferencesViewController {
}
@IBAction func sortByTime(_ sender: NSButton) {
let sortedByTime = selectedTimeZones.sorted { (obj1, obj2) -> Bool in
let sortedByTime = selectedTimeZones.sorted { obj1, obj2 -> Bool in
let system = NSTimeZone.system
guard let object1 = TimezoneData.customObject(from: obj1),
let object2 = TimezoneData.customObject(from: obj2) else {
let object2 = TimezoneData.customObject(from: obj2)
else {
assertionFailure("Data was unexpectedly nil")
return false
}
@ -925,10 +927,11 @@ extension PreferencesViewController {
}
@IBAction func sortByLabel(_ sender: NSButton) {
let sortedLabels = selectedTimeZones.sorted { (obj1, obj2) -> Bool in
let sortedLabels = selectedTimeZones.sorted { obj1, obj2 -> Bool in
guard let object1 = TimezoneData.customObject(from: obj1),
let object2 = TimezoneData.customObject(from: obj2) else {
let object2 = TimezoneData.customObject(from: obj2)
else {
assertionFailure("Data was unexpectedly nil")
return false
}
@ -948,10 +951,11 @@ extension PreferencesViewController {
}
@IBAction func sortByFormattedAddress(_ sender: NSButton) {
let sortedByAddress = selectedTimeZones.sorted { (obj1, obj2) -> Bool in
let sortedByAddress = selectedTimeZones.sorted { obj1, obj2 -> Bool in
guard let object1 = TimezoneData.customObject(from: obj1),
let object2 = TimezoneData.customObject(from: obj2) else {
let object2 = TimezoneData.customObject(from: obj2)
else {
assertionFailure("Data was unexpectedly nil")
return false
}
@ -1014,10 +1018,11 @@ extension PreferencesViewController: PreferenceSelectionUpdates {
return
}
let sortedTimezones = selectedTimeZones.sorted { (obj1, obj2) -> Bool in
let sortedTimezones = selectedTimeZones.sorted { obj1, obj2 -> Bool in
guard let object1 = TimezoneData.customObject(from: obj1),
let object2 = TimezoneData.customObject(from: obj2) else {
let object2 = TimezoneData.customObject(from: obj2)
else {
assertionFailure("Data was unexpectedly nil")
return false
}

2
Clocker/Preferences/General/SearchDataSource.swift

@ -151,7 +151,7 @@ class SearchDataSource: NSObject {
func searchTimezones(_ searchString: String) {
timezoneFilteredArray = []
timezoneFilteredArray = timezoneArray.filter { (timezoneMetadata) -> Bool in
timezoneFilteredArray = timezoneArray.filter { timezoneMetadata -> Bool in
let tags = timezoneMetadata.tags
for tag in tags where tag.contains(searchString) {
return true

2
Clocker/Preferences/Menu Bar/MenubarHandler.swift

@ -21,7 +21,7 @@ class MenubarHandler: NSObject {
}
if menubarTitles.isEmpty == false {
let titles = menubarTitles.map { (data) -> String? in
let titles = menubarTitles.map { data -> String? in
let timezone = TimezoneData.customObject(from: data)
let operationsObject = TimezoneDataOperations(with: timezone!)
return "\(operationsObject.menuTitle().trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines))"

9
Clocker/Preferences/Menu Bar/StatusContainerView.swift

@ -33,10 +33,12 @@ func compactWidth(for timezone: TimezoneData) -> Int {
if timeFormat == DateFormat.twelveHour
|| timeFormat == DateFormat.twelveHourWithSeconds
|| timeFormat == DateFormat.twelveHourWithZero
|| timeFormat == DateFormat.twelveHourWithSeconds {
|| timeFormat == DateFormat.twelveHourWithSeconds
{
totalWidth += 20
} else if timeFormat == DateFormat.twentyFourHour
|| timeFormat == DateFormat.twentyFourHourWithSeconds {
|| timeFormat == DateFormat.twentyFourHourWithSeconds
{
totalWidth += 0
}
@ -81,7 +83,7 @@ class StatusContainerView: NSView {
]
func containerWidth(for timezones: [Data]) -> CGFloat {
let compressedWidth = timezones.reduce(0.0) { (result, timezone) -> CGFloat in
let compressedWidth = timezones.reduce(0.0) { result, timezone -> CGFloat in
if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject))
@ -108,6 +110,7 @@ class StatusContainerView: NSView {
addSubviews()
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

4
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -144,7 +144,7 @@ class StatusItemHandler: NSObject {
private func retrieveSyncedMenubarTimezones() -> [Data] {
let defaultPreferences = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data] ?? []
let menubarTimezones = defaultPreferences.filter { (data) -> Bool in
let menubarTimezones = defaultPreferences.filter { data -> Bool in
if let timezoneObj = TimezoneData.customObject(from: data) {
return timezoneObj.isFavourite == 1
}
@ -188,7 +188,7 @@ class StatusItemHandler: NSObject {
if let strongSelf = self {
strongSelf.performTimerWork()
}
})
})
// Tolerance, even a small amount, has a positive imapct on the power usage. As a rule, we set it to 10% of the interval
menubarTimer?.tolerance = shouldDisplaySeconds ? 0.5 : 20

5
Clocker/Preferences/Menu Bar/StatusItemView.swift

@ -37,8 +37,8 @@ extension NSView {
class StatusItemView: NSView {
// MARK: Private variables
private let locationView: NSTextField = NSTextField(labelWithString: "Hello")
private let timeView: NSTextField = NSTextField(labelWithString: "Mon 19:14 PM")
private let locationView = NSTextField(labelWithString: "Hello")
private let timeView = NSTextField(labelWithString: "Mon 19:14 PM")
private var operationsObject: TimezoneDataOperations {
return TimezoneDataOperations(with: dataObject)
}
@ -118,6 +118,7 @@ class StatusItemView: NSView {
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes)
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Loading…
Cancel
Save