Browse Source

Move constants to an enum.

master
Abhishek Banthia 9 months ago
parent
commit
efba5a7d8b
  1. 18
      Clocker/AppDelegate.swift
  2. 8
      Clocker/ClockerUnitTests/AppDelegateTests.swift
  3. 8
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  4. 2
      Clocker/ClockerUnitTests/SearchDataSourceTests.swift
  5. 6
      Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift
  6. 2
      Clocker/ClockerUnitTests/ThemerTests.swift
  7. 2
      Clocker/Dependencies/Date Additions/Date+TimeAgo.swift
  8. 14
      Clocker/Events and Reminders/CalendarHandler.swift
  9. 12
      Clocker/Onboarding/OnboardingParentViewController.swift
  10. 38
      Clocker/Onboarding/OnboardingSearchController.swift
  11. 40
      Clocker/Overall App/AppDefaults.swift
  12. 46
      Clocker/Overall App/ConfigExport.swift
  13. 52
      Clocker/Overall App/DataStore.swift
  14. 79
      Clocker/Overall App/Strings.swift
  15. 4
      Clocker/Overall App/Themer.swift

18
Clocker/AppDelegate.swift

@ -10,7 +10,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
private lazy var floatingWindow = FloatingWindowController.shared() private lazy var floatingWindow = FloatingWindowController.shared()
internal lazy var panelController = PanelController(windowNibName: .panel) internal lazy var panelController = PanelController(windowNibName: .panel)
private var statusBarHandler: StatusItemHandler! private var statusBarHandler: StatusItemHandler!
private let store: VersionUpdateHandler = VersionUpdateHandler(with: DataStore.shared()) private let versionUpdateHandler: VersionUpdateHandler = VersionUpdateHandler(with: DataStore.shared())
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) { override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) {
if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier { if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier {
@ -82,16 +82,16 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
} }
@objc func hideFromDock() { @objc func hideFromDock() {
UserDefaults.standard.set(0, forKey: CLAppDisplayOptions) UserDefaults.standard.set(0, forKey: UserDefaultKeys.appDisplayOptions)
NSApp.setActivationPolicy(.accessory) NSApp.setActivationPolicy(.accessory)
} }
private var controller: OnboardingController? private var controller: OnboardingController?
private func showOnboardingFlowIfEligible() { private func showOnboardingFlowIfEligible() {
let isTestInProgress = ProcessInfo.processInfo.arguments.contains(CLOnboardingTestsLaunchArgument) let isTestInProgress = ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.onboardingTestsLaunchArgument)
let shouldLaunchOnboarding = let shouldLaunchOnboarding =
(DataStore.shared().retrieve(key: CLShowOnboardingFlow) == nil (DataStore.shared().retrieve(key: UserDefaultKeys.showOnboardingFlow) == nil
&& DataStore.shared().timezones().isEmpty) && DataStore.shared().timezones().isEmpty)
|| isTestInProgress || isTestInProgress
@ -116,7 +116,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
// Install the menubar item! // Install the menubar item!
statusBarHandler = StatusItemHandler(with: DataStore.shared()) statusBarHandler = StatusItemHandler(with: DataStore.shared())
if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) { if ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.testingLaunchArgument) {
FirebaseApp.configure() FirebaseApp.configure()
ReviewController.setPreviewMode(true) ReviewController.setPreviewMode(true)
} }
@ -130,9 +130,9 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
setActivationPolicy() setActivationPolicy()
// Set the display mode default as panel! // Set the display mode default as panel!
if let displayMode = defaults.object(forKey: CLShowAppInForeground) as? NSNumber, displayMode.intValue == 1 { if let displayMode = defaults.object(forKey: UserDefaultKeys.showAppInForeground) as? NSNumber, displayMode.intValue == 1 {
showFloatingWindow() showFloatingWindow()
} else if let displayMode = defaults.object(forKey: CLShowAppInForeground) as? Int, displayMode == 1 { } else if let displayMode = defaults.object(forKey: UserDefaultKeys.showAppInForeground) as? Int, displayMode == 1 {
showFloatingWindow() showFloatingWindow()
} }
} }
@ -142,7 +142,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
let defaults = UserDefaults.standard let defaults = UserDefaults.standard
let currentActivationPolicy = NSRunningApplication.current.activationPolicy let currentActivationPolicy = NSRunningApplication.current.activationPolicy
let activationPolicy: NSApplication.ActivationPolicy = defaults.integer(forKey: CLAppDisplayOptions) == 0 ? .accessory : .regular let activationPolicy: NSApplication.ActivationPolicy = defaults.integer(forKey: UserDefaultKeys.appDisplayOptions) == 0 ? .accessory : .regular
if currentActivationPolicy != activationPolicy { if currentActivationPolicy != activationPolicy {
NSApp.setActivationPolicy(activationPolicy) NSApp.setActivationPolicy(activationPolicy)
@ -234,7 +234,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
@IBAction open func togglePanel(_ sender: NSButton) { @IBAction open func togglePanel(_ sender: NSButton) {
Logger.info("Toggle Panel called with sender state \(sender.state.rawValue)") Logger.info("Toggle Panel called with sender state \(sender.state.rawValue)")
let displayMode = UserDefaults.standard.integer(forKey: CLShowAppInForeground) let displayMode = UserDefaults.standard.integer(forKey: UserDefaultKeys.showAppInForeground)
if displayMode == 1 { if displayMode == 1 {
// No need to call NSApp.activate here since `showFloatingWindow` takes care of this // No need to call NSApp.activate here since `showFloatingWindow` takes care of this

8
Clocker/ClockerUnitTests/AppDelegateTests.swift

@ -71,7 +71,7 @@ class AppDelegateTests: XCTestCase {
func testActivationPolicy() { func testActivationPolicy() {
let subject = NSApplication.shared.delegate as? AppDelegate let subject = NSApplication.shared.delegate as? AppDelegate
let previousOption = UserDefaults.standard.integer(forKey: CLAppDisplayOptions) let previousOption = UserDefaults.standard.integer(forKey: UserDefaultKeys.appDisplayOptions)
if previousOption == 0 { if previousOption == 0 {
XCTAssertEqual(NSApp.activationPolicy(), .accessory) XCTAssertEqual(NSApp.activationPolicy(), .accessory)
} else { } else {
@ -87,7 +87,7 @@ class AppDelegateTests: XCTestCase {
subject?.invalidateMenubarTimer(true) subject?.invalidateMenubarTimer(true)
let statusItemHandler = subject?.statusItemForPanel() let statusItemHandler = subject?.statusItemForPanel()
XCTAssertEqual(statusItemHandler?.statusItem.button?.subviews, []) XCTAssertEqual(statusItemHandler?.statusItem.button?.subviews, [])
XCTAssertEqual(statusItemHandler?.statusItem.button?.title, CLEmptyString) XCTAssertEqual(statusItemHandler?.statusItem.button?.title, UserDefaultKeys.emptyString)
XCTAssertEqual(statusItemHandler?.statusItem.button?.image?.name(), "LightModeIcon") XCTAssertEqual(statusItemHandler?.statusItem.button?.image?.name(), "LightModeIcon")
XCTAssertEqual(statusItemHandler?.statusItem.button?.imagePosition, .imageOnly) XCTAssertEqual(statusItemHandler?.statusItem.button?.imagePosition, .imageOnly)
XCTAssertEqual(statusItemHandler?.statusItem.button?.toolTip, "Clocker") XCTAssertEqual(statusItemHandler?.statusItem.button?.toolTip, "Clocker")
@ -116,7 +116,7 @@ class AppDelegateTests: XCTestCase {
func testStandardModeMenubarSetup() { func testStandardModeMenubarSetup() {
let olderTimezones = DataStore.shared().timezones() let olderTimezones = DataStore.shared().timezones()
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode) // Set the menubar mode to standard UserDefaults.standard.set(1, forKey: UserDefaultKeys.menubarCompactMode) // Set the menubar mode to standard
let subject = NSApplication.shared.delegate as? AppDelegate let subject = NSApplication.shared.delegate as? AppDelegate
let statusItemHandler = subject?.statusItemForPanel() let statusItemHandler = subject?.statusItemForPanel()
@ -142,6 +142,6 @@ class AppDelegateTests: XCTestCase {
XCTAssertEqual(subject?.statusItemForPanel().statusItem.button?.subviews.isEmpty, true) // This will be nil for standard mode XCTAssertEqual(subject?.statusItemForPanel().statusItem.button?.subviews.isEmpty, true) // This will be nil for standard mode
UserDefaults.standard.set(0, forKey: CLMenubarCompactMode) // Set the menubar mode back to compact UserDefaults.standard.set(0, forKey: UserDefaultKeys.menubarCompactMode) // Set the menubar mode back to compact
} }
} }

8
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -74,7 +74,7 @@ class ClockerUnitTests: XCTestCase {
func testOverridingSecondsComponent_shouldHideSeconds() { func testOverridingSecondsComponent_shouldHideSeconds() {
let dummyDefaults = UserDefaults.standard let dummyDefaults = UserDefaults.standard
dummyDefaults.set(NSNumber(value: 4), forKey: CLSelectedTimeZoneFormatKey) // 4 is 12 hour with seconds dummyDefaults.set(NSNumber(value: 4), forKey: UserDefaultKeys.selectedTimeZoneFormatKey) // 4 is 12 hour with seconds
let timezoneObjects = [TimezoneData(with: mumbai), let timezoneObjects = [TimezoneData(with: mumbai),
TimezoneData(with: auckland), TimezoneData(with: auckland),
@ -207,7 +207,7 @@ class ClockerUnitTests: XCTestCase {
func testTimezoneFormat() { func testTimezoneFormat() {
let dataObject = TimezoneData(with: mumbai) let dataObject = TimezoneData(with: mumbai)
UserDefaults.standard.set(NSNumber(value: 0), forKey: CLSelectedTimeZoneFormatKey) // Set to 12 hour format UserDefaults.standard.set(NSNumber(value: 0), forKey: UserDefaultKeys.selectedTimeZoneFormatKey) // Set to 12 hour format
dataObject.setShouldOverrideGlobalTimeFormat(0) // Respect Global Preference dataObject.setShouldOverrideGlobalTimeFormat(0) // Respect Global Preference
XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm a") XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm a")
@ -246,7 +246,7 @@ class ClockerUnitTests: XCTestCase {
func testTimezoneFormatWithDefaultSetAs24HourFormat() { func testTimezoneFormatWithDefaultSetAs24HourFormat() {
let dataObject = TimezoneData(with: california) let dataObject = TimezoneData(with: california)
UserDefaults.standard.set(NSNumber(value: 1), forKey: CLSelectedTimeZoneFormatKey) // Set to 24-Hour Format UserDefaults.standard.set(NSNumber(value: 1), forKey: UserDefaultKeys.selectedTimeZoneFormatKey) // Set to 24-Hour Format
dataObject.setShouldOverrideGlobalTimeFormat(0) dataObject.setShouldOverrideGlobalTimeFormat(0)
XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm", XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm",
@ -285,7 +285,7 @@ class ClockerUnitTests: XCTestCase {
func testSecondsDisplayForOverridenTimezone() { func testSecondsDisplayForOverridenTimezone() {
let dataObject = TimezoneData(with: california) let dataObject = TimezoneData(with: california)
UserDefaults.standard.set(NSNumber(value: 1), forKey: CLSelectedTimeZoneFormatKey) // Set to 24-Hour Format UserDefaults.standard.set(NSNumber(value: 1), forKey: UserDefaultKeys.selectedTimeZoneFormatKey) // Set to 24-Hour Format
// Test default behaviour // Test default behaviour
let timezoneWithSecondsKeys = [4, 5, 8, 11] let timezoneWithSecondsKeys = [4, 5, 8, 11]

2
Clocker/ClockerUnitTests/SearchDataSourceTests.swift

@ -113,7 +113,7 @@ class SearchDataSourceTests: XCTestCase {
func testRetrieveSelectedTimezoneWithEmptySearchField() { func testRetrieveSelectedTimezoneWithEmptySearchField() {
// Setup subject with an empty search field // Setup subject with an empty search field
setupSubject(searchText: CLEmptyString) setupSubject(searchText: UserDefaultKeys.emptyString)
subject.searchTimezones("los") subject.searchTimezones("los")
XCTAssertFalse(subject.calculateChangesets()) XCTAssertFalse(subject.calculateChangesets())

6
Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift

@ -20,8 +20,8 @@ class StandardMenubarHandlerTests: XCTestCase {
private func makeMockStore(with menubarMode: Int = 1) -> DataStore { private func makeMockStore(with menubarMode: Int = 1) -> DataStore {
// Wipe all timezones from UserDefaults // Wipe all timezones from UserDefaults
let defaults = UserDefaults(suiteName: "com.abhishek.Clocker.StandardMenubarHandlerTests")! let defaults = UserDefaults(suiteName: "com.abhishek.Clocker.StandardMenubarHandlerTests")!
defaults.set(menubarMode, forKey: CLMenubarCompactMode) defaults.set(menubarMode, forKey: UserDefaultKeys.menubarCompactMode)
defaults.set(0, forKey: CLShowMeetingInMenubar) defaults.set(0, forKey: UserDefaultKeys.showMeetingInMenubar)
XCTAssertNotEqual(defaults, UserDefaults.standard) XCTAssertNotEqual(defaults, UserDefaults.standard)
return DataStore(with: defaults) return DataStore(with: defaults)
} }
@ -163,7 +163,7 @@ class StandardMenubarHandlerTests: XCTestCase {
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store, eventStore: EventCenter.sharedCenter()) let menubarHandler = MenubarTitleProvider(with: store, eventStore: EventCenter.sharedCenter())
XCTAssert(menubarHandler.format(event: mockEvent) == CLEmptyString, XCTAssert(menubarHandler.format(event: mockEvent) == UserDefaultKeys.emptyString,
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }

2
Clocker/ClockerUnitTests/ThemerTests.swift

@ -122,7 +122,7 @@ class ThemerTests: XCTestCase {
func testSystemTheme() throws { func testSystemTheme() throws {
let currentSystemTheme = let currentSystemTheme =
UserDefaults.standard.string(forKey: CLAppleInterfaceStyleKey)?.lowercased().contains("dark") ?? false ? Themer.Theme.dark : Themer.Theme.light UserDefaults.standard.string(forKey: UserDefaultKeys.appleInterfaceStyleKey)?.lowercased().contains("dark") ?? false ? Themer.Theme.dark : Themer.Theme.light
let subject = Themer(index: 2) // 2 is for system theme let subject = Themer(index: 2) // 2 is for system theme
let expectedSliderKnobColor = currentSystemTheme == .light ? NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9) : NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9) let expectedSliderKnobColor = currentSystemTheme == .light ? NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9) : NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
let expectedSliderRightColor = currentSystemTheme == .dark ? NSColor.white : NSColor.gray let expectedSliderRightColor = currentSystemTheme == .dark ? NSColor.white : NSColor.gray

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

@ -131,7 +131,7 @@ public extension Date {
// Instead of returning "Just now" or the equivalent localized version; let's return an empty string // Instead of returning "Just now" or the equivalent localized version; let's return an empty string
// Previously, we returned DateToolsLocalizedStrings("Just now") // Previously, we returned DateToolsLocalizedStrings("Just now")
return CLEmptyString return UserDefaultKeys.emptyString
} }
} }

14
Clocker/Events and Reminders/CalendarHandler.swift

@ -36,7 +36,7 @@ extension EventCenter {
setOfCalendars = Set(userCalendars) setOfCalendars = Set(userCalendars)
} }
var currentSourceTitle = CLEmptyString var currentSourceTitle = UserDefaultKeys.emptyString
for calendar in calendars { for calendar in calendars {
if !(calendar.source.title == currentSourceTitle) { if !(calendar.source.title == currentSourceTitle) {
@ -81,12 +81,12 @@ extension EventCenter {
Returns a tuple with 0 as the header string and 1 as the subtitle string Returns a tuple with 0 as the header string and 1 as the subtitle string
*/ */
func separateFormat(event: EKEvent) -> (String, String)? { func separateFormat(event: EKEvent) -> (String, String)? {
guard let truncateLength = DataStore.shared().retrieve(key: CLTruncateTextLength) as? NSNumber, let eventTitle = event.title else { guard let truncateLength = DataStore.shared().retrieve(key: UserDefaultKeys.truncateTextLength) as? NSNumber, let eventTitle = event.title else {
return nil return nil
} }
let seconds = event.startDate.timeIntervalSinceNow let seconds = event.startDate.timeIntervalSinceNow
var formattedTitle: String = CLEmptyString var formattedTitle: String = UserDefaultKeys.emptyString
if eventTitle.count > truncateLength.intValue { if eventTitle.count > truncateLength.intValue {
let truncateIndex = eventTitle.index(eventTitle.startIndex, offsetBy: truncateLength.intValue) let truncateIndex = eventTitle.index(eventTitle.startIndex, offsetBy: truncateLength.intValue)
@ -98,7 +98,7 @@ extension EventCenter {
formattedTitle.append(eventTitle) formattedTitle.append(eventTitle)
} }
var menubarText: String = CLEmptyString var menubarText: String = UserDefaultKeys.emptyString
let minutes = seconds / 60 let minutes = seconds / 60
if minutes > 2 { if minutes > 2 {
@ -224,7 +224,7 @@ extension EventCenter {
let allCalendars = self.retrieveAllCalendarIdentifiers() let allCalendars = self.retrieveAllCalendarIdentifiers()
if !allCalendars.isEmpty { if !allCalendars.isEmpty {
UserDefaults.standard.set(allCalendars, forKey: CLSelectedCalendars) UserDefaults.standard.set(allCalendars, forKey: UserDefaultKeys.selectedCalendars)
Logger.info("Finished saving all calendar identifiers in default") Logger.info("Finished saving all calendar identifiers in default")
self.filterEvents() self.filterEvents()
} }
@ -485,8 +485,8 @@ struct EventInfo {
return "started +\(event.startDate.shortTimeAgoSinceNow)." return "started +\(event.startDate.shortTimeAgoSinceNow)."
} else if event.startDate.isToday, timeIntervalSinceNowForMeeting > 0 { } else if event.startDate.isToday, timeIntervalSinceNowForMeeting > 0 {
let timeSince = Date().timeAgo(since: event.startDate).lowercased() let timeSince = Date().timeAgo(since: event.startDate).lowercased()
let withoutAn = timeSince.replacingOccurrences(of: "an", with: CLEmptyString) let withoutAn = timeSince.replacingOccurrences(of: "an", with: UserDefaultKeys.emptyString)
var withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) var withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: UserDefaultKeys.emptyString)
// If the user has not turned on seconds granularity for one of the timezones, // If the user has not turned on seconds granularity for one of the timezones,
// we return "in 12 seconds" which looks weird. // we return "in 12 seconds" which looks weird.

12
Clocker/Onboarding/OnboardingParentViewController.swift

@ -194,9 +194,9 @@ class OnboardingParentViewController: NSViewController {
} }
private func navigateToFinalStage() { private func navigateToFinalStage() {
if UserDefaults.standard.object(forKey: CLInstallHomeIndicatorObject) == nil, DataStore.shared().timezones().isEmpty { if UserDefaults.standard.object(forKey: UserDefaultKeys.installHomeIndicatorObject) == nil, DataStore.shared().timezones().isEmpty {
fetchLocalTimezone() fetchLocalTimezone()
UserDefaults.standard.set(1, forKey: CLInstallHomeIndicatorObject) UserDefaults.standard.set(1, forKey: UserDefaultKeys.installHomeIndicatorObject)
} }
guard let fromViewController = onboardingSearchVC, let toViewController = finalOnboardingVC else { guard let fromViewController = onboardingSearchVC, let toViewController = finalOnboardingVC else {
@ -220,8 +220,8 @@ class OnboardingParentViewController: NSViewController {
view.window?.close() view.window?.close()
if ProcessInfo.processInfo.arguments.contains(CLOnboardingTestsLaunchArgument) == false { if ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.onboardingTestsLaunchArgument) == false {
UserDefaults.standard.set(true, forKey: CLShowOnboardingFlow) UserDefaults.standard.set(true, forKey: UserDefaultKeys.showOnboardingFlow)
} }
// Install the menubar option! // Install the menubar option!
@ -317,11 +317,11 @@ class OnboardingParentViewController: NSViewController {
private func shouldStartAtLogin(_ shouldStart: Bool) { private func shouldStartAtLogin(_ shouldStart: Bool) {
// If tests are going on, we don't want to enable/disable launch at login! // If tests are going on, we don't want to enable/disable launch at login!
if ProcessInfo.processInfo.arguments.contains(CLOnboardingTestsLaunchArgument) { if ProcessInfo.processInfo.arguments.contains(UserDefaultKeys.onboardingTestsLaunchArgument) {
return return
} }
UserDefaults.standard.set(shouldStart ? 1 : 0, forKey: CLStartAtLogin) UserDefaults.standard.set(shouldStart ? 1 : 0, forKey: UserDefaultKeys.startAtLogin)
startupManager.toggleLogin(shouldStart) startupManager.toggleLogin(shouldStart)
shouldStart ? shouldStart ?
Logger.log(object: nil, for: "Enable Launch at Login while Onboarding") : Logger.log(object: nil, for: "Enable Launch at Login while Onboarding") :

38
Clocker/Onboarding/OnboardingSearchController.swift

@ -100,7 +100,7 @@ class OnboardingSearchController: NSViewController {
private func cleanupAfterInstallingTimezone() { private func cleanupAfterInstallingTimezone() {
let data = TimezoneData() let data = TimezoneData()
data.setLabel(CLEmptyString) data.setLabel(UserDefaultKeys.emptyString)
if let currentSelection = searchResultsDataSource?.retrieveSelectedTimezone(resultsTableView.selectedRow) { if let currentSelection = searchResultsDataSource?.retrieveSelectedTimezone(resultsTableView.selectedRow) {
let metaInfo = metadata(for: currentSelection) let metaInfo = metadata(for: currentSelection)
@ -115,7 +115,7 @@ class OnboardingSearchController: NSViewController {
searchResultsDataSource?.cleanupFilterArray() searchResultsDataSource?.cleanupFilterArray()
searchResultsDataSource?.timezoneFilteredArray = [] searchResultsDataSource?.timezoneFilteredArray = []
searchResultsDataSource?.calculateChangesets() searchResultsDataSource?.calculateChangesets()
searchBar.stringValue = CLEmptyString searchBar.stringValue = UserDefaultKeys.emptyString
accessoryLabel.stringValue = "Added \(metaInfo.1.formattedName)." accessoryLabel.stringValue = "Added \(metaInfo.1.formattedName)."
undoButton.isHidden = false undoButton.isHidden = false
@ -141,7 +141,7 @@ class OnboardingSearchController: NSViewController {
repeats: false) repeats: false)
{ _ in { _ in
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
self.setInfoLabel(CLEmptyString) self.setInfoLabel(UserDefaultKeys.emptyString)
} }
} }
} }
@ -225,13 +225,13 @@ class OnboardingSearchController: NSViewController {
} }
let newTimeZone = [ let newTimeZone = [
CLTimezoneID: response.timeZoneId, UserDefaultKeys.timezoneID: response.timeZoneId,
CLTimezoneName: filteredAddress, UserDefaultKeys.timezoneName: filteredAddress,
CLPlaceIdentifier: dataObject.placeID!, UserDefaultKeys.placeIdentifier: dataObject.placeID!,
"latitude": latitude, "latitude": latitude,
"longitude": longitude, "longitude": longitude,
"nextUpdate": CLEmptyString, "nextUpdate": UserDefaultKeys.emptyString,
CLCustomLabel: filteredAddress, UserDefaultKeys.customLabel: filteredAddress,
] as [String: Any] ] as [String: Any]
DataStore.shared().addTimezone(TimezoneData(with: newTimeZone)) DataStore.shared().addTimezone(TimezoneData(with: newTimeZone))
@ -271,7 +271,7 @@ class OnboardingSearchController: NSViewController {
private func setup() { private func setup() {
appName.stringValue = "Quick Add Locations".localized() appName.stringValue = "Quick Add Locations".localized()
onboardingTypeLabel.stringValue = "More search options in Clocker Preferences.".localized() onboardingTypeLabel.stringValue = "More search options in Clocker Preferences.".localized()
setInfoLabel(CLEmptyString) setInfoLabel(UserDefaultKeys.emptyString)
searchBar.bezelStyle = .roundedBezel searchBar.bezelStyle = .roundedBezel
searchBar.placeholderString = "Press Enter to Search!" searchBar.placeholderString = "Press Enter to Search!"
searchBar.delegate = self searchBar.delegate = self
@ -291,7 +291,7 @@ class OnboardingSearchController: NSViewController {
if searchString.isEmpty { if searchString.isEmpty {
resetSearchView() resetSearchView()
setInfoLabel(CLEmptyString) setInfoLabel(UserDefaultKeys.emptyString)
return return
} }
@ -308,7 +308,7 @@ class OnboardingSearchController: NSViewController {
fileprivate func resetIfNeccesary(_ searchString: String) { fileprivate func resetIfNeccesary(_ searchString: String) {
if searchString.isEmpty { if searchString.isEmpty {
resetSearchView() resetSearchView()
setInfoLabel(CLEmptyString) setInfoLabel(UserDefaultKeys.emptyString)
} }
} }
@ -324,7 +324,7 @@ class OnboardingSearchController: NSViewController {
let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines) let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines)
searchString = words.joined(separator: CLEmptyString) searchString = words.joined(separator: UserDefaultKeys.emptyString)
if searchString.count < 3 { if searchString.count < 3 {
resetIfNeccesary(searchString) resetIfNeccesary(searchString)
@ -343,7 +343,7 @@ class OnboardingSearchController: NSViewController {
let words = currentSearchBarValue.components(separatedBy: CharacterSet.whitespacesAndNewlines) let words = currentSearchBarValue.components(separatedBy: CharacterSet.whitespacesAndNewlines)
if words.joined(separator: CLEmptyString) != searchString { if words.joined(separator: UserDefaultKeys.emptyString) != searchString {
return return
} }
@ -397,7 +397,7 @@ class OnboardingSearchController: NSViewController {
} }
private func prepareUIForPresentingResults() { private func prepareUIForPresentingResults() {
setInfoLabel(CLEmptyString) setInfoLabel(UserDefaultKeys.emptyString)
if let dataSource = searchResultsDataSource, dataSource.calculateChangesets() { if let dataSource = searchResultsDataSource, dataSource.calculateChangesets() {
resultsTableView.isHidden = false resultsTableView.isHidden = false
resultsTableView.reloadData() resultsTableView.reloadData()
@ -414,10 +414,10 @@ class OnboardingSearchController: NSViewController {
let totalPackage = [ let totalPackage = [
"latitude": latitude, "latitude": latitude,
"longitude": longitude, "longitude": longitude,
CLTimezoneName: formattedAddress, UserDefaultKeys.timezoneName: formattedAddress,
CLCustomLabel: formattedAddress, UserDefaultKeys.customLabel: formattedAddress,
CLTimezoneID: CLEmptyString, UserDefaultKeys.timezoneID: UserDefaultKeys.emptyString,
CLPlaceIdentifier: result.placeId, UserDefaultKeys.placeIdentifier: result.placeId,
] as [String: Any] ] as [String: Any]
return TimezoneData(with: totalPackage) return TimezoneData(with: totalPackage)
@ -431,7 +431,7 @@ class OnboardingSearchController: NSViewController {
searchResultsDataSource?.timezoneFilteredArray = [] searchResultsDataSource?.timezoneFilteredArray = []
searchResultsDataSource?.calculateChangesets() searchResultsDataSource?.calculateChangesets()
resultsTableView.reloadData() resultsTableView.reloadData()
searchBar.stringValue = CLEmptyString searchBar.stringValue = UserDefaultKeys.emptyString
searchBar.placeholderString = "Press Enter to Search" searchBar.placeholderString = "Press Enter to Search"
} }

40
Clocker/Overall App/AppDefaults.swift

@ -16,30 +16,30 @@ class AppDefaults {
defaults.register(defaults: defaultsDictionary()) defaults.register(defaults: defaultsDictionary())
store.setTimezones(timezones) store.setTimezones(timezones)
defaults.set(selectedCalendars, forKey: CLSelectedCalendars) defaults.set(selectedCalendars, forKey: UserDefaultKeys.selectedCalendars)
} }
private class func defaultsDictionary() -> [String: Any] { private class func defaultsDictionary() -> [String: Any] {
let calendars: [String] = [] let calendars: [String] = []
return [CLThemeKey: 0, return [UserDefaultKeys.themeKey: 0,
CLDisplayFutureSliderKey: 0, UserDefaultKeys.displayFutureSliderKey: 0,
CLSelectedTimeZoneFormatKey: 0, // 12-hour format UserDefaultKeys.selectedTimeZoneFormatKey: 0, // 12-hour format
CLRelativeDateKey: 0, UserDefaultKeys.relativeDateKey: 0,
CLShowDayInMenu: 0, UserDefaultKeys.showDayInMenu: 0,
CLShowDateInMenu: 1, UserDefaultKeys.showDateInMenu: 1,
CLShowPlaceInMenu: 0, UserDefaultKeys.showPlaceInMenu: 0,
CLStartAtLogin: 0, UserDefaultKeys.startAtLogin: 0,
CLSunriseSunsetTime: 1, UserDefaultKeys.sunriseSunsetTime: 1,
CLUserFontSizePreference: 4, UserDefaultKeys.userFontSizePreference: 4,
CLShowUpcomingEventView: "YES", UserDefaultKeys.showUpcomingEventView: "YES",
CLShowAppInForeground: 0, UserDefaultKeys.showAppInForeground: 0,
CLFutureSliderRange: 0, UserDefaultKeys.futureSliderRange: 0,
CLShowAllDayEventsInUpcomingView: 1, UserDefaultKeys.showAllDayEventsInUpcomingView: 1,
CLShowMeetingInMenubar: 0, UserDefaultKeys.showMeetingInMenubar: 0,
CLTruncateTextLength: 30, UserDefaultKeys.truncateTextLength: 30,
CLSelectedCalendars: calendars, UserDefaultKeys.selectedCalendars: calendars,
CLAppDisplayOptions: 0, UserDefaultKeys.appDisplayOptions: 0,
CLMenubarCompactMode: 1] UserDefaultKeys.menubarCompactMode: 1]
} }
} }

46
Clocker/Overall App/ConfigExport.swift

@ -7,29 +7,29 @@ import Foundation
struct ConfigExport { struct ConfigExport {
private func generateJSON(from store: DataStore) { private func generateJSON(from store: DataStore) {
let selectedKeys: Set<String> = Set([ let selectedKeys: Set<String> = Set([
CLShowOnboardingFlow, UserDefaultKeys.showOnboardingFlow,
CLSelectedTimeZoneFormatKey, UserDefaultKeys.selectedTimeZoneFormatKey,
CLThemeKey, UserDefaultKeys.themeKey,
CLShowDayInMenu, UserDefaultKeys.showDayInMenu,
CLShowDateInMenu, UserDefaultKeys.showDateInMenu,
CLShowPlaceInMenu, UserDefaultKeys.showPlaceInMenu,
CLDisplayFutureSliderKey, UserDefaultKeys.displayFutureSliderKey,
CLStartAtLogin, UserDefaultKeys.startAtLogin,
CLShowAppInForeground, UserDefaultKeys.showAppInForeground,
CLSunriseSunsetTime, UserDefaultKeys.sunriseSunsetTime,
CLUserFontSizePreference, UserDefaultKeys.userFontSizePreference,
CLShowUpcomingEventView, UserDefaultKeys.showUpcomingEventView,
CLShowAllDayEventsInUpcomingView, UserDefaultKeys.showAllDayEventsInUpcomingView,
CLShowMeetingInMenubar, UserDefaultKeys.showMeetingInMenubar,
CLTruncateTextLength, UserDefaultKeys.truncateTextLength,
CLFutureSliderRange, UserDefaultKeys.futureSliderRange,
CLSelectedCalendars, UserDefaultKeys.selectedCalendars,
CLAppDisplayOptions, UserDefaultKeys.appDisplayOptions,
CLLongStatusBarWarningMessage, UserDefaultKeys.longStatusBarWarningMessage,
CLMenubarCompactMode, UserDefaultKeys.menubarCompactMode,
CLDefaultMenubarMode, UserDefaultKeys.defaultMenubarMode,
CLInstallHomeIndicatorObject, UserDefaultKeys.installHomeIndicatorObject,
CLSwitchToCompactModeAlert, UserDefaultKeys.switchToCompactModeAlert,
]) ])
let dictionaryRep = UserDefaults.standard.dictionaryRepresentation() let dictionaryRep = UserDefaults.standard.dictionaryRepresentation()
var clockerPrefs: [String: Any] = [:] var clockerPrefs: [String: Any] = [:]

52
Clocker/Overall App/DataStore.swift

@ -37,7 +37,7 @@ class DataStore: NSObject {
} }
init(with defaults: UserDefaults) { init(with defaults: UserDefaults) {
cachedTimezones = (defaults.object(forKey: CLDefaultPreferenceKey) as? [Data]) ?? [] cachedTimezones = (defaults.object(forKey: UserDefaultKeys.defaultPreferenceKey) as? [Data]) ?? []
cachedMenubarTimezones = cachedTimezones.filter { cachedMenubarTimezones = cachedTimezones.filter {
let customTimezone = TimezoneData.customObject(from: $0) let customTimezone = TimezoneData.customObject(from: $0)
return customTimezone?.isFavourite == 1 return customTimezone?.isFavourite == 1
@ -69,10 +69,10 @@ class DataStore: NSObject {
let userInfo = notification.userInfo ?? [:] let userInfo = notification.userInfo ?? [:]
let ubiquitousStore = notification.object as? NSUbiquitousKeyValueStore let ubiquitousStore = notification.object as? NSUbiquitousKeyValueStore
Logger.info("Ubiquitous Store Changed: User Info is \(userInfo)") Logger.info("Ubiquitous Store Changed: User Info is \(userInfo)")
let currentTimezones = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] let currentTimezones = userDefaults.object(forKey: UserDefaultKeys.defaultPreferenceKey) as? [Data]
let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data] let cloudTimezones = ubiquitousStore?.object(forKey: UserDefaultKeys.defaultPreferenceKey) as? [Data]
let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date() let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: UserDefaultKeys.ubiquitousStoreLastUpdateKey) as? Date) ?? Date()
let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: CLUserDefaultsLastUpdateKey) as? Date) ?? Date() let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: UserDefaultKeys.userDefaultsLastUpdateKey) as? Date) ?? Date()
if cloudTimezones == currentTimezones { if cloudTimezones == currentTimezones {
Logger.info("Ubiquitous Store timezones aren't equal to current timezones") Logger.info("Ubiquitous Store timezones aren't equal to current timezones")
@ -84,8 +84,8 @@ class DataStore: NSObject {
if cloudTimezones != currentTimezones, cloudLastUpdateDate.isLaterThanOrEqual(to: defaultsLastUpdateDate) { if cloudTimezones != currentTimezones, cloudLastUpdateDate.isLaterThanOrEqual(to: defaultsLastUpdateDate) {
Logger.info("Syncing local timezones with data from the ☁. ☁ last update timestamp is recent") Logger.info("Syncing local timezones with data from the ☁. ☁ last update timestamp is recent")
userDefaults.set(cloudTimezones, forKey: CLDefaultPreferenceKey) userDefaults.set(cloudTimezones, forKey: UserDefaultKeys.defaultPreferenceKey)
userDefaults.set(Date(), forKey: CLUserDefaultsLastUpdateKey) userDefaults.set(Date(), forKey: UserDefaultKeys.userDefaultsLastUpdateKey)
NotificationCenter.default.post(name: DataStore.didSyncFromExternalSourceNotification, NotificationCenter.default.post(name: DataStore.didSyncFromExternalSourceNotification,
object: self) object: self)
return return
@ -97,16 +97,16 @@ class DataStore: NSObject {
} }
func setTimezones(_ timezones: [Data]?) { func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey) userDefaults.set(timezones, forKey: UserDefaultKeys.defaultPreferenceKey)
userDefaults.set(Date(), forKey: CLUserDefaultsLastUpdateKey) userDefaults.set(Date(), forKey: UserDefaultKeys.userDefaultsLastUpdateKey)
cachedTimezones = timezones ?? [] cachedTimezones = timezones ?? []
cachedMenubarTimezones = cachedTimezones.filter { cachedMenubarTimezones = cachedTimezones.filter {
let customTimezone = TimezoneData.customObject(from: $0) let customTimezone = TimezoneData.customObject(from: $0)
return customTimezone?.isFavourite == 1 return customTimezone?.isFavourite == 1
} }
// iCloud sync // iCloud sync
ubiquitousStore?.set(timezones, forKey: CLDefaultPreferenceKey) ubiquitousStore?.set(timezones, forKey: UserDefaultKeys.defaultPreferenceKey)
ubiquitousStore?.set(Date(), forKey: CLUbiquitousStoreLastUpdateKey) ubiquitousStore?.set(Date(), forKey: UserDefaultKeys.ubiquitousStoreLastUpdateKey)
} }
func menubarTimezones() -> [Data]? { func menubarTimezones() -> [Data]? {
@ -114,7 +114,7 @@ class DataStore: NSObject {
} }
func selectedCalendars() -> [String]? { func selectedCalendars() -> [String]? {
return userDefaults.array(forKey: CLSelectedCalendars) as? [String] return userDefaults.array(forKey: UserDefaultKeys.selectedCalendars) as? [String]
} }
// MARK: Date (May 8th) in Compact Menubar // MARK: Date (May 8th) in Compact Menubar
@ -158,7 +158,7 @@ class DataStore: NSObject {
} }
func timezoneFormat() -> NSNumber { func timezoneFormat() -> NSNumber {
return userDefaults.object(forKey: CLSelectedTimeZoneFormatKey) as? NSNumber ?? NSNumber(integerLiteral: 0) return userDefaults.object(forKey: UserDefaultKeys.selectedTimeZoneFormatKey) as? NSNumber ?? NSNumber(integerLiteral: 0)
} }
func isBufferRequiredForTwelveHourFormats() -> Bool { func isBufferRequiredForTwelveHourFormats() -> Bool {
@ -168,44 +168,44 @@ class DataStore: NSObject {
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 { guard let value = retrieve(key: UserDefaultKeys.displayFutureSliderKey) as? NSNumber else {
return false return false
} }
return value != 1 // Display slider is 0 and Hide is 1. return value != 1 // Display slider is 0 and Hide is 1.
case .upcomingEventView: case .upcomingEventView:
guard let value = retrieve(key: CLShowUpcomingEventView) as? NSString else { guard let value = retrieve(key: UserDefaultKeys.showUpcomingEventView) as? NSString else {
return false return false
} }
return value == "YES" return value == "YES"
case .twelveHour: case .twelveHour:
return shouldDisplayHelper(CLSelectedTimeZoneFormatKey) return shouldDisplayHelper(UserDefaultKeys.selectedTimeZoneFormatKey)
case .showAllDayEventsInMenubar: case .showAllDayEventsInMenubar:
return shouldDisplayHelper(CLShowAllDayEventsInUpcomingView) return shouldDisplayHelper(UserDefaultKeys.showAllDayEventsInUpcomingView)
case .sunrise: case .sunrise:
return shouldDisplayHelper(CLSunriseSunsetTime) return shouldDisplayHelper(UserDefaultKeys.sunriseSunsetTime)
case .showMeetingInMenubar: case .showMeetingInMenubar:
return shouldDisplayHelper(CLShowMeetingInMenubar) return shouldDisplayHelper(UserDefaultKeys.showMeetingInMenubar)
case .showAppInForeground: case .showAppInForeground:
guard let value = retrieve(key: CLShowAppInForeground) as? NSNumber else { guard let value = retrieve(key: UserDefaultKeys.showAppInForeground) 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 shouldDisplayNonObjectHelper(CLShowDateInMenu) return shouldDisplayNonObjectHelper(UserDefaultKeys.showDateInMenu)
case .placeInMenubar: case .placeInMenubar:
return shouldDisplayHelper(CLShowPlaceInMenu) return shouldDisplayHelper(UserDefaultKeys.showPlaceInMenu)
case .dayInMenubar: case .dayInMenubar:
return shouldDisplayNonObjectHelper(CLShowDayInMenu) return shouldDisplayNonObjectHelper(UserDefaultKeys.showDayInMenu)
case .appDisplayOptions: case .appDisplayOptions:
return shouldDisplayHelper(CLAppDisplayOptions) return shouldDisplayHelper(UserDefaultKeys.appDisplayOptions)
case .menubarCompactMode: case .menubarCompactMode:
guard let value = retrieve(key: CLMenubarCompactMode) as? Int else { guard let value = retrieve(key: UserDefaultKeys.menubarCompactMode) as? Int else {
return false return false
} }
return value == 0 return value == 0
case .sync: case .sync:
return shouldDisplayHelper(CLEnableSyncKey) return shouldDisplayHelper(UserDefaultKeys.enableSyncKey)
} }
} }

79
Clocker/Overall App/Strings.swift

@ -2,42 +2,45 @@
import Cocoa import Cocoa
let CLEmptyString = "" public enum UserDefaultKeys {
let CLDefaultPreferenceKey = "defaultPreferences" static let emptyString = ""
let CLTimezoneName = "formattedAddress" static let defaultPreferenceKey = "defaultPreferences"
let CLCustomLabel = "customLabel" static let timezoneName = "formattedAddress"
let CLSelectedTimeZoneFormatKey = "is24HourFormatSelected" static let customLabel = "customLabel"
let CLDragSessionKey = "public.text" static let selectedTimeZoneFormatKey = "is24HourFormatSelected"
let CLTimezoneID = "timezoneID" static let dragSessionKey = "public.text"
let CLPlaceIdentifier = "place_id" static let timezoneID = "timezoneID"
let CLRelativeDateKey = "relativeDate" static let placeIdentifier = "place_id"
let CLThemeKey = "defaultTheme" static let relativeDateKey = "relativeDate"
let CLShowDayInMenu = "showDay" static let themeKey = "defaultTheme"
let CLShowDateInMenu = "showDate" static let showDayInMenu = "showDay"
let CLShowPlaceInMenu = "showPlaceName" static let showDateInMenu = "showDate"
let CLDisplayFutureSliderKey = "displayFutureSlider" static let showPlaceInMenu = "showPlaceName"
let CLStartAtLogin = "startAtLogin" static let displayFutureSliderKey = "displayFutureSlider"
let CLShowAppInForeground = "displayAppAsForegroundApp" static let startAtLogin = "startAtLogin"
let CLSunriseSunsetTime = "showSunriseSetTime" static let showAppInForeground = "displayAppAsForegroundApp"
let CLUserFontSizePreference = "userFontSize" static let sunriseSunsetTime = "showSunriseSetTime"
let CLShowUpcomingEventView = "ShowUpcomingEventView" static let userFontSizePreference = "userFontSize"
let CLShowAllDayEventsInUpcomingView = "showAllDayEventsInUpcomingView" static let showUpcomingEventView = "ShowUpcomingEventView"
let CLShowMeetingInMenubar = "showMeetingInfoInMenubar" static let showAllDayEventsInUpcomingView = "showAllDayEventsInUpcomingView"
let CLTruncateTextLength = "truncateTextLength" static let showMeetingInMenubar = "showMeetingInfoInMenubar"
let CLFutureSliderRange = "sliderDayRange" static let truncateTextLength = "truncateTextLength"
let CLSelectedCalendars = "SelectedCalendars" static let futureSliderRange = "sliderDayRange"
let CLShowOnboardingFlow = "com.abhishek.showOnboardingFlow" static let selectedCalendars = "SelectedCalendars"
let CLAppDisplayOptions = "com.abhishek.appDisplayOptions" static let showOnboardingFlow = "com.abhishek.showOnboardingFlow"
let CLLongStatusBarWarningMessage = "com.abhishek.longStatusBarWarning" static let appDisplayOptions = "com.abhishek.appDisplayOptions"
let CLUITestingLaunchArgument = "isUITesting" static let longStatusBarWarningMessage = "com.abhishek.longStatusBarWarning"
let CLOnboardingTestsLaunchArgument = "isTestingTheOnboardingFlow" static let testingLaunchArgument = "isUITesting"
let CLMenubarCompactMode = "com.abhishek.menubarCompactMode" static let onboardingTestsLaunchArgument = "isTestingTheOnboardingFlow"
let CLDefaultMenubarMode = "com.abhishek.shouldDefaultToCompactMode" static let menubarCompactMode = "com.abhishek.menubarCompactMode"
let CLInstallHomeIndicatorObject = "installHomeIndicatorObject" static let defaultMenubarMode = "com.abhishek.shouldDefaultToCompactMode"
let CLSwitchToCompactModeAlert = "com.abhishek.switchToCompactMode" static let installHomeIndicatorObject = "installHomeIndicatorObject"
let CLAppleInterfaceStyleKey = "AppleInterfaceStyle" static let switchToCompactModeAlert = "com.abhishek.switchToCompactMode"
static let appleInterfaceStyleKey = "AppleInterfaceStyle"
// Sync Keys
static let enableSyncKey = "com.abhishek.enableSync"
static let ubiquitousStoreLastUpdateKey = "com.abhishek.ubiquitousLastUpdateKey"
static let userDefaultsLastUpdateKey = "com.abhishek.defaultsLastUpdateKey"
}
// Sync Keys
let CLEnableSyncKey = "com.abhishek.enableSync"
let CLUbiquitousStoreLastUpdateKey = "com.abhishek.ubiquitousLastUpdateKey"
let CLUserDefaultsLastUpdateKey = "com.abhishek.defaultsLastUpdateKey"

4
Clocker/Overall App/Themer.swift

@ -16,7 +16,7 @@ class Themer: NSObject {
case solarizedDark case solarizedDark
} }
private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: CLThemeKey)) private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: UserDefaultKeys.themeKey))
private var effectiveApperanceObserver: NSKeyValueObservation? private var effectiveApperanceObserver: NSKeyValueObservation?
private var themeIndex: Theme { private var themeIndex: Theme {
didSet { didSet {
@ -447,7 +447,7 @@ extension Themer {
private func retrieveCurrentSystem() -> Theme { private func retrieveCurrentSystem() -> Theme {
if #available(OSX 10.14, *) { if #available(OSX 10.14, *) {
if let appleInterfaceStyle = UserDefaults.standard.object(forKey: CLAppleInterfaceStyleKey) as? String { if let appleInterfaceStyle = UserDefaults.standard.object(forKey: UserDefaultKeys.appleInterfaceStyleKey) as? String {
if appleInterfaceStyle.lowercased().contains("dark") { if appleInterfaceStyle.lowercased().contains("dark") {
return .dark return .dark
} }

Loading…
Cancel
Save