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? var selectedDataSource: TimezoneData?
if selectedTimezones.count > row, if selectedTimezones.count > row,
let model = TimezoneData.customObject(from: selectedTimezones[row]) { let model = TimezoneData.customObject(from: selectedTimezones[row])
{
selectedDataSource = model selectedDataSource = model
} }
@ -163,7 +164,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Old Label": dataObject.customLabel ?? "Error", "Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue, "New Label": formattedValue,
], ],
for: "Custom Label Changed") for: "Custom Label Changed")
dataObject.setLabel(formattedValue) dataObject.setLabel(formattedValue)
@ -176,7 +177,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
"Selected Timezone Count": selectedTimezones.count, "Selected Timezone Count": selectedTimezones.count,
"Current Row": row, "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 = { private var geocodingKey: String = {
guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist"), guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile: path), let dictionary = NSDictionary(contentsOfFile: path),
let apiKey = dictionary["GeocodingKey"] as? String else { let apiKey = dictionary["GeocodingKey"] as? String
else {
assertionFailure("Unable to find the API key") assertionFailure("Unable to find the API key")
return "" return ""
} }
@ -203,7 +204,6 @@ class PreferencesViewController: ParentViewController {
timezoneTableView.enclosingScrollView?.isHidden = true timezoneTableView.enclosingScrollView?.isHidden = true
showNoTimezoneState() showNoTimezoneState()
cleanup() cleanup()
return
} }
private func cleanup() { private func cleanup() {
@ -274,10 +274,10 @@ class PreferencesViewController: ParentViewController {
return return
} }
let newHotKey: PTHotKey = PTHotKey(identifier: keyPath, let newHotKey = PTHotKey(identifier: keyPath,
keyCombo: newShortcut, keyCombo: newShortcut,
target: self, target: self,
action: #selector(ping(_:))) action: #selector(ping(_:)))
hotKeyCenter?.register(newHotKey) hotKeyCenter?.register(newHotKey)
} }
@ -333,9 +333,10 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
for: "favouriteRemoved") for: "favouriteRemoved")
if let appDelegate = NSApplication.shared.delegate as? AppDelegate, if let appDelegate = NSApplication.shared.delegate as? AppDelegate,
let menubarFavourites = DataStore.shared().menubarTimezones(), let menubarFavourites = DataStore.shared().menubarTimezones(),
menubarFavourites.isEmpty, menubarFavourites.isEmpty,
DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false
{
appDelegate.invalidateMenubarTimer(true) appDelegate.invalidateMenubarTimer(true)
} }
@ -453,7 +454,7 @@ extension PreferencesViewController {
self.prepareUIForPresentingResults() self.prepareUIForPresentingResults()
} }
}) })
} }
} }
@ -817,7 +818,7 @@ extension PreferencesViewController {
var newDefaults = selectedTimeZones var newDefaults = selectedTimeZones
let objectsToRemove = timezoneTableView.selectedRowIndexes.map { (index) -> Data in let objectsToRemove = timezoneTableView.selectedRowIndexes.map { index -> Data in
selectedTimeZones[index] selectedTimeZones[index]
} }
@ -896,12 +897,13 @@ extension PreferencesViewController {
} }
@IBAction func sortByTime(_ sender: NSButton) { @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 let system = NSTimeZone.system
guard let object1 = TimezoneData.customObject(from: obj1), 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") assertionFailure("Data was unexpectedly nil")
return false return false
} }
@ -925,10 +927,11 @@ extension PreferencesViewController {
} }
@IBAction func sortByLabel(_ sender: NSButton) { @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), 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") assertionFailure("Data was unexpectedly nil")
return false return false
} }
@ -948,10 +951,11 @@ extension PreferencesViewController {
} }
@IBAction func sortByFormattedAddress(_ sender: NSButton) { @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), 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") assertionFailure("Data was unexpectedly nil")
return false return false
} }
@ -1014,10 +1018,11 @@ extension PreferencesViewController: PreferenceSelectionUpdates {
return return
} }
let sortedTimezones = selectedTimeZones.sorted { (obj1, obj2) -> Bool in let sortedTimezones = selectedTimeZones.sorted { obj1, obj2 -> Bool in
guard let object1 = TimezoneData.customObject(from: obj1), 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") assertionFailure("Data was unexpectedly nil")
return false return false
} }

2
Clocker/Preferences/General/SearchDataSource.swift

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

2
Clocker/Preferences/Menu Bar/MenubarHandler.swift

@ -21,7 +21,7 @@ class MenubarHandler: NSObject {
} }
if menubarTitles.isEmpty == false { 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 timezone = TimezoneData.customObject(from: data)
let operationsObject = TimezoneDataOperations(with: timezone!) let operationsObject = TimezoneDataOperations(with: timezone!)
return "\(operationsObject.menuTitle().trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines))" 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 if timeFormat == DateFormat.twelveHour
|| timeFormat == DateFormat.twelveHourWithSeconds || timeFormat == DateFormat.twelveHourWithSeconds
|| timeFormat == DateFormat.twelveHourWithZero || timeFormat == DateFormat.twelveHourWithZero
|| timeFormat == DateFormat.twelveHourWithSeconds { || timeFormat == DateFormat.twelveHourWithSeconds
{
totalWidth += 20 totalWidth += 20
} else if timeFormat == DateFormat.twentyFourHour } else if timeFormat == DateFormat.twentyFourHour
|| timeFormat == DateFormat.twentyFourHourWithSeconds { || timeFormat == DateFormat.twentyFourHourWithSeconds
{
totalWidth += 0 totalWidth += 0
} }
@ -81,7 +83,7 @@ class StatusContainerView: NSView {
] ]
func containerWidth(for timezones: [Data]) -> CGFloat { 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) { if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) let precalculatedWidth = Double(compactWidth(for: timezoneObject))
@ -108,6 +110,7 @@ class StatusContainerView: NSView {
addSubviews() addSubviews()
} }
@available(*, unavailable)
required init?(coder _: NSCoder) { required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") 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] { private func retrieveSyncedMenubarTimezones() -> [Data] {
let defaultPreferences = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [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) { if let timezoneObj = TimezoneData.customObject(from: data) {
return timezoneObj.isFavourite == 1 return timezoneObj.isFavourite == 1
} }
@ -188,7 +188,7 @@ class StatusItemHandler: NSObject {
if let strongSelf = self { if let strongSelf = self {
strongSelf.performTimerWork() 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 // 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 menubarTimer?.tolerance = shouldDisplaySeconds ? 0.5 : 20

5
Clocker/Preferences/Menu Bar/StatusItemView.swift

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

Loading…
Cancel
Save