Browse Source

Move to Constants enum.

master
Abhishek Banthia 7 months ago
parent
commit
bb0e0120a7
  1. 6
      Clocker/Overall App/UserDefaults + KVOExtensions.swift
  2. 34
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  3. 2
      Clocker/Panel/Notes Popover/NotesPopover.swift
  4. 2
      Clocker/Panel/Notes Popover/TextViewWithPlaceholder.swift
  5. 22
      Clocker/Panel/PanelController.swift
  6. 6
      Clocker/Panel/ParentPanelController+ModernSlider.swift
  7. 22
      Clocker/Panel/ParentPanelController.swift
  8. 2
      Clocker/Panel/Rate Controller/ReviewController.swift
  9. 4
      Clocker/Panel/UI/TimezoneCellView.swift
  10. 10
      Clocker/Panel/UI/TimezoneDataSource.swift
  11. 2
      Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift
  12. 12
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
  13. 12
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  14. 8
      Clocker/Preferences/Calendar/CalendarViewController.swift
  15. 56
      Clocker/Preferences/General/PreferencesViewController.swift
  16. 6
      Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift
  17. 6
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

6
Clocker/Overall App/UserDefaults + KVOExtensions.swift

@ -4,14 +4,14 @@ import Cocoa
extension UserDefaults {
@objc dynamic var displayFutureSlider: Int {
return integer(forKey: CLDisplayFutureSliderKey)
return integer(forKey: UserDefaultKeys.displayFutureSliderKey)
}
@objc dynamic var userFontSize: Int {
return integer(forKey: CLUserFontSizePreference)
return integer(forKey: UserDefaultKeys.userFontSizePreference)
}
@objc dynamic var sliderDayRange: Int {
return integer(forKey: CLFutureSliderRange)
return integer(forKey: UserDefaultKeys.futureSliderRange)
}
}

34
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -28,7 +28,7 @@ extension TimezoneDataOperations {
options: .matchFirst)
else {
assertionFailure("Data was unexpectedly nil")
return CLEmptyString
return UserDefaultKeys.emptyString
}
if dataObject.timezoneFormat(store.timezoneFormat()) == DateFormat.epochTime {
@ -81,7 +81,7 @@ extension TimezoneDataOperations {
}
func compactMenuTitle() -> String {
var subtitle = CLEmptyString
var subtitle = UserDefaultKeys.emptyString
let shouldLabelBeShownAlongWithTime = !store.shouldDisplay(.placeInMenubar)
@ -105,7 +105,7 @@ extension TimezoneDataOperations {
}
func compactMenuSubtitle() -> String {
var subtitle = CLEmptyString
var subtitle = UserDefaultKeys.emptyString
let shouldDayBeShown = store.shouldShowDayInMenubar()
let shouldLabelsNotBeShownAlongWithTime = store.shouldDisplay(.placeInMenubar)
@ -127,7 +127,7 @@ extension TimezoneDataOperations {
}
func menuTitle() -> String {
var menuTitle = CLEmptyString
var menuTitle = UserDefaultKeys.emptyString
let dataStore = store
@ -206,13 +206,13 @@ extension TimezoneDataOperations {
}
func date(with sliderValue: Int, displayType: TimezoneData.DateDisplayType) -> String {
guard let relativeDayPreference = store.retrieve(key: CLRelativeDateKey) as? NSNumber else {
guard let relativeDayPreference = store.retrieve(key: UserDefaultKeys.relativeDateKey) as? NSNumber else {
assertionFailure("Data was unexpectedly nil")
return CLEmptyString
return UserDefaultKeys.emptyString
}
if relativeDayPreference.intValue == 3 {
return CLEmptyString
return UserDefaultKeys.emptyString
}
var currentCalendar = Calendar(identifier: .gregorian)
@ -293,24 +293,24 @@ extension TimezoneDataOperations {
"Locale": dateFormatter.locale.identifier,
] as [String: Any]
Logger.log(object: unableToConvertDateParameters, for: "Date conversion failure - New Date is nil")
return CLEmptyString
return UserDefaultKeys.emptyString
}
let timeDifference = local.timeAgo(since: timezoneDate)
if timeDifference.isEmpty {
return CLEmptyString
return UserDefaultKeys.emptyString
}
if (local as NSDate).earlierDate(timezoneDate) == local {
var replaceAgo = CLEmptyString
var replaceAgo = UserDefaultKeys.emptyString
replaceAgo.append(", +")
let agoString = timezoneDate.timeAgo(since: local, numericDates: true)
replaceAgo.append(agoString.replacingOccurrences(of: "ago", with: CLEmptyString))
replaceAgo.append(agoString.replacingOccurrences(of: "ago", with: UserDefaultKeys.emptyString))
if !TimezoneDataOperations.currentLocale.contains("en") {
if TimezoneDataOperations.currentLocale.contains("de") {
replaceAgo = replaceAgo.replacingOccurrences(of: "Vor ", with: CLEmptyString)
replaceAgo = replaceAgo.replacingOccurrences(of: "Vor ", with: UserDefaultKeys.emptyString)
replaceAgo.append(" vor")
}
@ -322,15 +322,15 @@ extension TimezoneDataOperations {
return replaceAgo.lowercased()
}
var replaceAgo = CLEmptyString
var replaceAgo = UserDefaultKeys.emptyString
replaceAgo.append(", -")
let replaced = timeDifference.replacingOccurrences(of: "ago", with: CLEmptyString)
let replaced = timeDifference.replacingOccurrences(of: "ago", with: UserDefaultKeys.emptyString)
replaceAgo.append(replaced)
if !TimezoneDataOperations.currentLocale.contains("en") {
if TimezoneDataOperations.currentLocale.contains("de") {
replaceAgo = replaceAgo.replacingOccurrences(of: "Vor ", with: CLEmptyString)
replaceAgo = replaceAgo.replacingOccurrences(of: "Vor ", with: UserDefaultKeys.emptyString)
replaceAgo.append(" zurück")
}
@ -384,7 +384,7 @@ extension TimezoneDataOperations {
/* We have to call this everytime so that we get an updated value everytime! */
if dataObject.selectionType == .timezone || (dataObject.latitude == nil || dataObject.longitude == nil) {
return CLEmptyString
return UserDefaultKeys.emptyString
}
initializeSunriseSunset(with: sliderValue)
@ -399,7 +399,7 @@ extension TimezoneDataOperations {
return dateFormatter.string(from: correct)
}
return CLEmptyString
return UserDefaultKeys.emptyString
}
func todaysDate(with sliderValue: Int, locale: Locale = Locale(identifier: "en-US")) -> String {

2
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -476,7 +476,7 @@ extension NotesPopover {
if let note = model.note, !note.isEmpty {
notesTextView.string = note
} else {
notesTextView.string = CLEmptyString
notesTextView.string = UserDefaultKeys.emptyString
}
setInitialReminderTime()

2
Clocker/Panel/Notes Popover/TextViewWithPlaceholder.swift

@ -32,7 +32,7 @@ class TextViewWithPlaceholder: NSTextView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
if string == CLEmptyString, self != window?.firstResponder {
if string == UserDefaultKeys.emptyString, self != window?.firstResponder {
placeholder.draw(at: NSPoint(x: 0, y: 0))
}
}

22
Clocker/Panel/PanelController.swift

@ -82,7 +82,7 @@ class PanelController: ParentPanelController {
if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false {
modernContainerView.isHidden = true
} else if let value = DataStore.shared().retrieve(key: CLDisplayFutureSliderKey) as? NSNumber, modernContainerView != nil {
} else if let value = DataStore.shared().retrieve(key: UserDefaultKeys.displayFutureSliderKey) as? NSNumber, modernContainerView != nil {
if value.intValue == 1 {
modernContainerView.isHidden = true
} else if value.intValue == 0 {
@ -185,16 +185,16 @@ class PanelController: ParentPanelController {
let preferences = DataStore.shared().timezones()
guard let theme = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber,
let displayFutureSliderKey = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber,
let showAppInForeground = DataStore.shared().retrieve(key: CLShowAppInForeground) as? NSNumber,
let relativeDateKey = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber,
let fontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber,
let sunriseTime = DataStore.shared().retrieve(key: CLSunriseSunsetTime) as? NSNumber,
let showDayInMenu = DataStore.shared().retrieve(key: CLShowDayInMenu) as? NSNumber,
let showDateInMenu = DataStore.shared().retrieve(key: CLShowDateInMenu) as? NSNumber,
let showPlaceInMenu = DataStore.shared().retrieve(key: CLShowPlaceInMenu) as? NSNumber,
let showUpcomingEventView = DataStore.shared().retrieve(key: CLShowUpcomingEventView) as? String,
guard let theme = DataStore.shared().retrieve(key: UserDefaultKeys.themeKey) as? NSNumber,
let displayFutureSliderKey = DataStore.shared().retrieve(key: UserDefaultKeys.themeKey) as? NSNumber,
let showAppInForeground = DataStore.shared().retrieve(key: UserDefaultKeys.showAppInForeground) as? NSNumber,
let relativeDateKey = DataStore.shared().retrieve(key: UserDefaultKeys.relativeDateKey) as? NSNumber,
let fontSize = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber,
let sunriseTime = DataStore.shared().retrieve(key: UserDefaultKeys.sunriseSunsetTime) as? NSNumber,
let showDayInMenu = DataStore.shared().retrieve(key: UserDefaultKeys.showDayInMenu) as? NSNumber,
let showDateInMenu = DataStore.shared().retrieve(key: UserDefaultKeys.showDateInMenu) as? NSNumber,
let showPlaceInMenu = DataStore.shared().retrieve(key: UserDefaultKeys.showPlaceInMenu) as? NSNumber,
let showUpcomingEventView = DataStore.shared().retrieve(key: UserDefaultKeys.showUpcomingEventView) as? String,
let country = Locale.autoupdatingCurrent.regionCode
else {
return

6
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -6,7 +6,7 @@ import Foundation
extension ParentPanelController: NSCollectionViewDataSource {
func collectionView(_: NSCollectionView, numberOfItemsInSection _: Int) -> Int {
let futureSliderDayPreference = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber ?? 5
let futureSliderDayPreference = DataStore.shared().retrieve(key: UserDefaultKeys.futureSliderRange) as? NSNumber ?? 5
let futureSliderDayRange = (futureSliderDayPreference.intValue + 1)
return (PanelConstants.modernSliderPointsInADay * futureSliderDayRange * 2) + 1
}
@ -23,6 +23,8 @@ extension ParentPanelController: NSCollectionViewDataSource {
extension ParentPanelController {
func setupModernSliderIfNeccessary() {
if modernSlider != nil {
modernSliderLabel.alignment = .center
if #available(OSX 11.0, *) {
resetModernSliderButton.image = Themer.shared().resetModernSliderImage()
} else {
@ -159,7 +161,7 @@ extension ParentPanelController {
}
public func setDefaultDateLabel(_ index: Int) -> Int {
let futureSliderDayPreference = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber ?? 5
let futureSliderDayPreference = DataStore.shared().retrieve(key: UserDefaultKeys.futureSliderRange) as? NSNumber ?? 5
let futureSliderDayRange = (futureSliderDayPreference.intValue + 1)
let totalCount = (PanelConstants.modernSliderPointsInADay * futureSliderDayRange * 2) + 1
let centerPoint = Int(ceil(Double(totalCount / 2)))

22
Clocker/Panel/ParentPanelController.swift

@ -218,7 +218,7 @@ class ParentPanelController: NSWindowController {
if modernContainerView != nil {
modernContainerView.isHidden = true
}
} else if let value = DataStore.shared().retrieve(key: CLDisplayFutureSliderKey) as? NSNumber {
} else if let value = DataStore.shared().retrieve(key: UserDefaultKeys.displayFutureSliderKey) as? NSNumber {
if value.intValue == 1 {
if modernContainerView != nil {
modernContainerView.isHidden = true
@ -312,7 +312,7 @@ class ParentPanelController: NSWindowController {
// Setting up Slider's Date Picker
sliderDatePicker.minDate = Date()
guard let sliderRange = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber else {
guard let sliderRange = DataStore.shared().retrieve(key: UserDefaultKeys.futureSliderRange) as? NSNumber else {
sliderDatePicker.maxDate = Date(timeInterval: 1 * 24 * 60 * 60, since: Date())
return
}
@ -410,7 +410,7 @@ class ParentPanelController: NSWindowController {
}
private func getAdjustedRowHeight(for object: TimezoneData?, _ currentHeight: CGFloat) -> CGFloat {
let userFontSize: NSNumber = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber ?? 4
let userFontSize: NSNumber = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber ?? 4
let shouldShowSunrise = DataStore.shared().shouldDisplay(.sunrise)
var newHeight = currentHeight
@ -468,7 +468,7 @@ class ParentPanelController: NSWindowController {
return
}
if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber {
if let userFontSize = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber {
if userFontSize == 4 {
scrollViewHeight.constant = totalHeight + CGFloat(userFontSize.intValue * 2)
} else {
@ -487,7 +487,7 @@ class ParentPanelController: NSWindowController {
}
if DataStore.shared().shouldDisplay(.futureSlider) {
let isModernSliderDisplayed = DataStore.shared().retrieve(key: CLDisplayFutureSliderKey) as? NSNumber ?? 0
let isModernSliderDisplayed = DataStore.shared().retrieve(key: UserDefaultKeys.displayFutureSliderKey) as? NSNumber ?? 0
if isModernSliderDisplayed == 0 {
if scrollViewHeight.constant >= (screenHeight() - 200) {
scrollViewHeight.constant = (screenHeight() - 300)
@ -529,7 +529,7 @@ class ParentPanelController: NSWindowController {
datasource?.setItems(items: timezones)
datasource?.setSlider(value: futureSliderValue)
if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber {
if let userFontSize = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber {
scrollViewHeight.constant = CGFloat(timezones.count) * (mainTableView.rowHeight + CGFloat(userFontSize.floatValue * 1.5))
setScrollViewConstraint()
@ -647,7 +647,7 @@ class ParentPanelController: NSWindowController {
} else if let value = TimezoneDataOperations(with: model, store: DataStore.shared()).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) {
cellView.noteLabel.stringValue = value
} else {
cellView.noteLabel.stringValue = CLEmptyString
cellView.noteLabel.stringValue = UserDefaultKeys.emptyString
}
cellView.layout(with: model)
updateDatePicker()
@ -657,7 +657,7 @@ class ParentPanelController: NSWindowController {
private func updateDatePicker() {
sliderDatePicker.minDate = Date()
guard let sliderRange = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber else {
guard let sliderRange = DataStore.shared().retrieve(key: UserDefaultKeys.futureSliderRange) as? NSNumber else {
sliderDatePicker.maxDate = Date(timeInterval: 1 * 24 * 60 * 60, since: Date())
return
}
@ -735,7 +735,7 @@ class ParentPanelController: NSWindowController {
if self.upcomingEventCollectionView != nil {
if self.stackView.arrangedSubviews.contains(self.upcomingEventContainerView!), self.upcomingEventContainerView?.isHidden == false {
self.upcomingEventContainerView?.isHidden = true
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
UserDefaults.standard.set("NO", forKey: UserDefaultKeys.showUpcomingEventView)
Logger.log(object: ["Removed": "YES"], for: "Removed Upcoming Event View")
}
}
@ -798,7 +798,7 @@ class ParentPanelController: NSWindowController {
let inverseSelection = showAppInForeground ? NSNumber(value: 0) : NSNumber(value: 1)
UserDefaults.standard.set(inverseSelection, forKey: CLShowAppInForeground)
UserDefaults.standard.set(inverseSelection, forKey: UserDefaultKeys.showAppInForeground)
close()
@ -818,7 +818,7 @@ class ParentPanelController: NSWindowController {
OperationQueue.main.addOperation {
if let upcomingView = self.upcomingEventContainerView, upcomingView.isHidden {
self.upcomingEventContainerView?.isHidden = false
UserDefaults.standard.set("YES", forKey: CLShowUpcomingEventView)
UserDefaults.standard.set("YES", forKey: UserDefaultKeys.showUpcomingEventView)
Logger.log(object: ["Shown": "YES"], for: "Added Upcoming Event View")
self.themeChanged()
}

2
Clocker/Panel/Rate Controller/ReviewController.swift

@ -14,7 +14,7 @@ final class ReviewController {
}
class func applicationDidLaunch(_ defaults: UserDefaults) {
if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) {
if ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.testingLaunchArgument) {
debugging = true
}

4
Clocker/Panel/UI/TimezoneCellView.swift

@ -20,7 +20,7 @@ class TimezoneCellView: NSTableCellView {
var isPopoverDisplayed: Bool = false
override func awakeFromNib() {
if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) {
if ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.testingLaunchArgument) {
extraOptions.isHidden = false
return
}
@ -125,7 +125,7 @@ class TimezoneCellView: NSTableCellView {
}
private func setupTextSize() {
guard let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber else {
guard let userFontSize = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber else {
assertionFailure("User Font Size is in unexpected format")
return
}

10
Clocker/Panel/UI/TimezoneDataSource.swift

@ -65,7 +65,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
cellView.rowNumber = row
cellView.customName.stringValue = currentModel.formattedTimezoneLabel()
cellView.time.stringValue = operation.time(with: sliderValue)
cellView.noteLabel.toolTip = currentModel.note ?? CLEmptyString
cellView.noteLabel.toolTip = currentModel.note ?? UserDefaultKeys.emptyString
cellView.currentLocationIndicator.isHidden = !currentModel.isSystemTimezone
cellView.time.setAccessibilityIdentifier("ActualTime")
cellView.relativeDate.setAccessibilityIdentifier("RelativeDate")
@ -76,7 +76,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
cellView.noteLabel.stringValue = value
cellView.noteLabel.isHidden = false
} else {
cellView.noteLabel.stringValue = CLEmptyString
cellView.noteLabel.stringValue = UserDefaultKeys.emptyString
cellView.noteLabel.isHidden = true
}
cellView.layout(with: currentModel)
@ -91,9 +91,9 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
return 100
}
if let userFontSize = dataStore.retrieve(key: CLUserFontSizePreference) as? NSNumber,
if let userFontSize = dataStore.retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber,
timezones.count > row,
let relativeDisplay = dataStore.retrieve(key: CLRelativeDateKey) as? NSNumber
let relativeDisplay = dataStore.retrieve(key: UserDefaultKeys.relativeDateKey) as? NSNumber
{
let model = timezones[row]
let shouldShowSunrise = dataStore.shouldDisplay(.sunrise)
@ -223,7 +223,7 @@ extension TimezoneDataSource: PanelTableViewDelegate {
if offSet == 0.0 {
return "\(localizedName)"
} else {
let offSetSign = offSet > 0 ? "+" : CLEmptyString
let offSetSign = offSet > 0 ? "+" : UserDefaultKeys.emptyString
let offsetString = "UTC\(offSetSign)\(offSet)"
return "\(localizedName) (\(offsetString))"
}

2
Clocker/Panel/Upcoming Events/UpcomingEventsDataSource.swift

@ -61,7 +61,7 @@ class UpcomingEventsDataSource: NSObject, NSCollectionViewDataSource, NSCollecti
let currentEventInfo = upcomingEvents[indexPath.item]
let bufferWidth: CGFloat = currentEventInfo.meetingURL != nil ? 60.0 : 20.0
let longerString = currentEventInfo.event.title.count >= currentEventInfo.metadataForMeeting().count ? currentEventInfo.event.title : currentEventInfo.metadataForMeeting()
let attributedString = NSAttributedString(string: longerString ?? CLEmptyString, attributes: [NSAttributedString.Key.font: avenirBookFont])
let attributedString = NSAttributedString(string: longerString ?? UserDefaultKeys.emptyString, attributes: [NSAttributedString.Key.font: avenirBookFont])
let maxWidth = min((attributedString.size().width + 15) + bufferWidth, UpcomingEventsDataSource.panelWidth / 2)
return NSSize(width: maxWidth, height: collectionView.frame.height - 20)
}

12
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -144,9 +144,9 @@ class AppFeedbackWindowController: NSWindowController {
private func generateUserPreferences() -> String {
let preferences = DataStore.shared().timezones()
guard let theme = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber,
let displayFutureSliderKey = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber,
let relativeDateKey = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber,
guard let theme = DataStore.shared().retrieve(key: UserDefaultKeys.themeKey) as? NSNumber,
let displayFutureSliderKey = DataStore.shared().retrieve(key: UserDefaultKeys.themeKey) as? NSNumber,
let relativeDateKey = DataStore.shared().retrieve(key: UserDefaultKeys.relativeDateKey) as? NSNumber,
let country = Locale.autoupdatingCurrent.regionCode
else {
return "Error"
@ -322,9 +322,9 @@ extension AppFeedbackWindowController: NSWindowDelegate {
}
func performClosingCleanUp() {
nameField.stringValue = CLEmptyString
emailField.stringValue = CLEmptyString
feedbackTextView.string = CLEmptyString
nameField.stringValue = UserDefaultKeys.emptyString
emailField.stringValue = UserDefaultKeys.emptyString
feedbackTextView.string = UserDefaultKeys.emptyString
isActivityInProgress = false
appFeedbackWindowDelegate?.appFeedbackWindowWillClose()
}

12
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -122,7 +122,7 @@ class AppearanceViewController: ParentViewController {
informationLabel.isHidden = menubarFavourites.isEmpty ? false : true
}
if let selectedIndex = DataStore.shared().retrieve(key: CLFutureSliderRange) as? NSNumber {
if let selectedIndex = DataStore.shared().retrieve(key: UserDefaultKeys.futureSliderRange) as? NSNumber {
sliderDayRangePopup.selectItem(at: selectedIndex.intValue)
}
@ -138,7 +138,7 @@ class AppearanceViewController: ParentViewController {
appDisplayControl.setSelected(true, forSegment: appDisplayOptions ? 0 : 1)
// Set the Sync value from NSUbiqutousKeyValueStore
let syncEnabled = NSUbiquitousKeyValueStore.default.bool(forKey: CLEnableSyncKey)
let syncEnabled = NSUbiquitousKeyValueStore.default.bool(forKey: UserDefaultKeys.enableSyncKey)
syncSegementedControl.setSelected(true, forSegment: syncEnabled ? 0 : 1)
}
@ -190,7 +190,7 @@ class AppearanceViewController: ParentViewController {
@IBAction func timeFormatSelectionChanged(_ sender: NSPopUpButton) {
let selection = NSNumber(value: sender.indexOfSelectedItem)
UserDefaults.standard.set(selection, forKey: CLSelectedTimeZoneFormatKey)
UserDefaults.standard.set(selection, forKey: UserDefaultKeys.selectedTimeZoneFormatKey)
refresh(panel: true, floating: true)
if let selectedFormat = sender.selectedItem?.title,
@ -357,7 +357,7 @@ class AppearanceViewController: ParentViewController {
}
@IBAction func toggleSync(_ sender: NSSegmentedControl) {
NSUbiquitousKeyValueStore.default.set(sender.selectedSegment == 0, forKey: CLEnableSyncKey)
NSUbiquitousKeyValueStore.default.set(sender.selectedSegment == 0, forKey: UserDefaultKeys.enableSyncKey)
DataStore.shared().setupSyncNotification()
}
}
@ -389,7 +389,7 @@ extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate {
if let note = currentModel.note, !note.isEmpty {
cellView.noteLabel.stringValue = note
} else {
cellView.noteLabel.stringValue = CLEmptyString
cellView.noteLabel.stringValue = UserDefaultKeys.emptyString
}
cellView.currentLocationIndicator.isHidden = !currentModel.isSystemTimezone
cellView.time.setAccessibilityIdentifier("ActualTime")
@ -402,7 +402,7 @@ extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate {
}
func tableView(_: NSTableView, heightOfRow row: Int) -> CGFloat {
if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber, previewTimezones.count > row {
if let userFontSize = DataStore.shared().retrieve(key: UserDefaultKeys.userFontSizePreference) as? NSNumber, previewTimezones.count > row {
let model = previewTimezones[row]
let rowHeight: Int = userFontSize == 4 ? 60 : 65

8
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -94,7 +94,7 @@ class CalendarViewController: ParentViewController {
setGrantAccess(title: "Grant Access".localized())
} else if hasDeniedCalendarAccess {
// The informationField text is taken care off in the XIB. Just set the grant button to empty because we can't do anything.
setGrantAccess(title: CLEmptyString)
setGrantAccess(title: UserDefaultKeys.emptyString)
} else {
calendarsTableView.reloadData()
}
@ -124,7 +124,7 @@ class CalendarViewController: ParentViewController {
setGrantAccess(title: "Launch Preferences".localized())
// Remove upcoming event view if possible
UserDefaults.standard.set("NO", forKey: CLShowUpcomingEventView)
UserDefaults.standard.set("NO", forKey: UserDefaultKeys.showUpcomingEventView)
}
@IBAction func grantAccess(_: Any) {
@ -163,7 +163,7 @@ class CalendarViewController: ParentViewController {
showUpcomingEventView = "NO"
}
UserDefaults.standard.set(showUpcomingEventView, forKey: CLShowUpcomingEventView)
UserDefaults.standard.set(showUpcomingEventView, forKey: UserDefaultKeys.showUpcomingEventView)
if DataStore.shared().shouldDisplay(ViewType.showAppInForeground) {
let floatingWindow = FloatingWindowController.shared()
@ -284,7 +284,7 @@ extension CalendarViewController: NSTableViewDelegate {
}
}
UserDefaults.standard.set(selectedCalendars, forKey: CLSelectedCalendars)
UserDefaults.standard.set(selectedCalendars, forKey: UserDefaultKeys.selectedCalendars)
calendars = EventCenter.sharedCenter().fetchSourcesAndCalendars()

56
Clocker/Preferences/General/PreferencesViewController.swift

@ -228,7 +228,7 @@ class PreferencesViewController: ParentViewController {
[placeholderLabel].forEach { $0.isHidden = true }
messageLabel.stringValue = CLEmptyString
messageLabel.stringValue = UserDefaultKeys.emptyString
timezoneTableView.registerForDraggedTypes([.dragSession])
@ -238,7 +238,7 @@ class PreferencesViewController: ParentViewController {
setupColor()
startupCheckbox.integerValue = DataStore.shared().retrieve(key: CLStartAtLogin) as? Int ?? 0
startupCheckbox.integerValue = DataStore.shared().retrieve(key: UserDefaultKeys.startAtLogin) as? Int ?? 0
searchField.bezelStyle = .roundedBezel
}
@ -249,7 +249,7 @@ class PreferencesViewController: ParentViewController {
startAtLoginLabel.textColor = Themer.shared().mainTextColor()
[timezoneNameSortButton, labelSortButton, timezoneSortButton].forEach {
$0?.attributedTitle = NSAttributedString(string: $0?.title ?? CLEmptyString, attributes: [
$0?.attributedTitle = NSAttributedString(string: $0?.title ?? UserDefaultKeys.emptyString, attributes: [
NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(),
NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!,
])
@ -360,10 +360,10 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
}
private func showAlertIfMoreThanOneTimezoneHasBeenAddedToTheMenubar() {
let isUITestRunning = ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument)
let isUITestRunning = ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.testingLaunchArgument)
// If we have seen displayed the message before, abort!
let haveWeSeenThisMessageBefore = UserDefaults.standard.bool(forKey: CLLongStatusBarWarningMessage)
let haveWeSeenThisMessageBefore = UserDefaults.standard.bool(forKey: UserDefaultKeys.longStatusBarWarningMessage)
if haveWeSeenThisMessageBefore, !isUITestRunning {
return
@ -393,10 +393,10 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
if response.rawValue == 1000 {
OperationQueue.main.addOperation {
UserDefaults.standard.set(0, forKey: CLMenubarCompactMode)
UserDefaults.standard.set(0, forKey: UserDefaultKeys.menubarCompactMode)
if alert.suppressionButton?.state == NSControl.StateValue.on {
UserDefaults.standard.set(true, forKey: CLLongStatusBarWarningMessage)
UserDefaults.standard.set(true, forKey: UserDefaultKeys.longStatusBarWarningMessage)
}
self.updateStatusBarAppearance()
@ -458,14 +458,14 @@ extension PreferencesViewController {
if searchResults.status == ResultStatus.zeroResults {
Logger.info("Zero Results returned")
self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : CLEmptyString
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : UserDefaultKeys.emptyString
self.reloadSearchResults()
self.isActivityInProgress = false
return
} else if searchResults.status == ResultStatus.requestDenied && searchResults.results.isEmpty {
Logger.info("Request denied!")
self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "Update Clocker to get a faster experience 😃" : CLEmptyString
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "Update Clocker to get a faster experience 😃" : UserDefaultKeys.emptyString
self.reloadSearchResults()
self.isActivityInProgress = false
return
@ -490,7 +490,7 @@ extension PreferencesViewController {
var searchString = searchField.stringValue
let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines)
searchString = words.joined(separator: CLEmptyString)
searchString = words.joined(separator: UserDefaultKeys.emptyString)
return "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchString)&key=\(geocodingKey)&language=\(userPreferredLanguage)"
}
@ -511,10 +511,10 @@ extension PreferencesViewController {
let totalPackage = [
"latitude": latitude,
"longitude": longitude,
CLTimezoneName: formattedAddress,
CLCustomLabel: formattedAddress,
CLTimezoneID: CLEmptyString,
CLPlaceIdentifier: $0.placeId,
UserDefaultKeys.timezoneName: formattedAddress,
UserDefaultKeys.customLabel: formattedAddress,
UserDefaultKeys.timezoneID: UserDefaultKeys.emptyString,
UserDefaultKeys.placeIdentifier: $0.placeId,
] as [String: Any]
finalResults.append(TimezoneData(with: totalPackage))
@ -523,7 +523,7 @@ extension PreferencesViewController {
}
private func prepareUIForPresentingResults() {
placeholderLabel.placeholderString = CLEmptyString
placeholderLabel.placeholderString = UserDefaultKeys.emptyString
isActivityInProgress = false
reloadSearchResults()
}
@ -541,7 +541,7 @@ extension PreferencesViewController {
}
isActivityInProgress = false
placeholderLabel.placeholderString = CLEmptyString
placeholderLabel.placeholderString = UserDefaultKeys.emptyString
}
private func getTimezone(for latitude: Double, and longitude: Double) {
@ -600,13 +600,13 @@ extension PreferencesViewController {
}
let newTimeZone = [
CLTimezoneID: timezone.timeZoneId,
CLTimezoneName: filteredAddress,
CLPlaceIdentifier: dataObject.placeID!,
UserDefaultKeys.timezoneID: timezone.timeZoneId,
UserDefaultKeys.timezoneName: filteredAddress,
UserDefaultKeys.placeIdentifier: dataObject.placeID!,
"latitude": dataObject.latitude!,
"longitude": dataObject.longitude!,
"nextUpdate": CLEmptyString,
CLCustomLabel: filteredAddress,
"nextUpdate": UserDefaultKeys.emptyString,
UserDefaultKeys.customLabel: filteredAddress,
] as [String: Any]
// Mark if the timezone is same as local timezone
@ -658,7 +658,7 @@ extension PreferencesViewController {
refreshTimezoneTableView(true)
refreshMainTable()
timezonePanel.close()
placeholderLabel.placeholderString = CLEmptyString
placeholderLabel.placeholderString = UserDefaultKeys.emptyString
searchField.placeholderString = NSLocalizedString("Search Field Placeholder",
comment: "Search Field Placeholder")
availableTimezoneTableView.isHidden = false
@ -723,7 +723,7 @@ extension PreferencesViewController {
}
if messageLabel.stringValue.isEmpty {
searchField.stringValue = CLEmptyString
searchField.stringValue = UserDefaultKeys.emptyString
guard let latitude = dataObject.latitude, let longitude = dataObject.longitude else {
assertionFailure("Data was unexpectedly nil")
@ -736,7 +736,7 @@ extension PreferencesViewController {
private func cleanupAfterInstallingTimezone() {
let data = TimezoneData()
data.setLabel(CLEmptyString)
data.setLabel(UserDefaultKeys.emptyString)
let currentSelection = searchResultsDataSource.retrieveSelectedTimezone(availableTimezoneTableView.selectedRow)
@ -751,8 +751,8 @@ extension PreferencesViewController {
searchResultsDataSource.cleanupFilterArray()
searchResultsDataSource.timezoneFilteredArray = []
placeholderLabel.placeholderString = CLEmptyString
searchField.stringValue = CLEmptyString
placeholderLabel.placeholderString = UserDefaultKeys.emptyString
searchField.stringValue = UserDefaultKeys.emptyString
reloadSearchResults()
refreshTimezoneTableView(true)
@ -788,8 +788,8 @@ extension PreferencesViewController {
@IBAction func closePanel(_: NSButton) {
searchResultsDataSource.cleanupFilterArray()
searchResultsDataSource.timezoneFilteredArray = []
searchField.stringValue = CLEmptyString
placeholderLabel.placeholderString = CLEmptyString
searchField.stringValue = UserDefaultKeys.emptyString
placeholderLabel.placeholderString = UserDefaultKeys.emptyString
searchField.placeholderString = NSLocalizedString("Search Field Placeholder",
comment: "Search Field Placeholder")

6
Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift

@ -73,13 +73,13 @@ class MenubarTitleProvider: NSObject {
}
internal func format(event: EKEvent) -> String {
guard let truncateLength = store.retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title, event.title.isEmpty == false else {
return CLEmptyString
guard let truncateLength = store.retrieve(key: UserDefaultKeys.truncateTextLength) as? NSNumber, let eventTitle = event.title, event.title.isEmpty == false else {
return UserDefaultKeys.emptyString
}
let seconds = event.startDate.timeIntervalSinceNow
var menubarText: String = CLEmptyString
var menubarText: String = UserDefaultKeys.emptyString
if eventTitle.count > truncateLength.intValue {
let truncateIndex = eventTitle.index(eventTitle.startIndex, offsetBy: truncateLength.intValue)

6
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -46,7 +46,7 @@ class StatusItemHandler: NSObject {
statusItem.button?.subviews = []
statusContainerView = nil
case .standardText:
statusItem.button?.title = CLEmptyString
statusItem.button?.title = UserDefaultKeys.emptyString
case .icon:
statusItem.button?.image = nil
}
@ -362,14 +362,14 @@ class StatusItemHandler: NSObject {
return
}
statusItem.button?.title = CLEmptyString
statusItem.button?.title = UserDefaultKeys.emptyString
statusItem.button?.image = NSImage(named: .menubarIcon)
statusItem.button?.imagePosition = .imageOnly
statusItem.button?.toolTip = "Clocker"
}
private func setupForStandardText() {
var menubarText = CLEmptyString
var menubarText = UserDefaultKeys.emptyString
if let menubarTitle = menubarTitleHandler.titleForMenubar() {
menubarText = menubarTitle

Loading…
Cancel
Save