From 2bc03f820b036bb3b70bd22f1ba5d4aa049d8291 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Tue, 19 Apr 2022 22:08:13 -0400 Subject: [PATCH 01/23] Make upcoming events source optional. --- Clocker/Panel/ParentPanelController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 05b8324..b2d621a 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -89,7 +89,7 @@ class ParentPanelController: NSWindowController { // Upcoming Events @IBOutlet var upcomingEventCollectionView: NSCollectionView! @IBOutlet var upcomingEventContainerView: NSView! - public var upcomingEventsDataSource: UpcomingEventsDataSource! + public var upcomingEventsDataSource: UpcomingEventsDataSource? var defaultPreferences: [Data] { return DataStore.shared().timezones() @@ -829,7 +829,7 @@ class ParentPanelController: NSWindowController { if self.upcomingEventCollectionView != nil, let upcomingEvents = eventCenter.upcomingEventsForDay(events) { - self.upcomingEventsDataSource.updateEventsDataSource(upcomingEvents) + self.upcomingEventsDataSource?.updateEventsDataSource(upcomingEvents) self.upcomingEventCollectionView.reloadData() return } @@ -840,7 +840,7 @@ class ParentPanelController: NSWindowController { } } else { if upcomingEventCollectionView != nil { - upcomingEventsDataSource.updateEventsDataSource([]) + upcomingEventsDataSource?.updateEventsDataSource([]) upcomingEventCollectionView.reloadData() return } From d5d8124a051def8cec7c07b99af21995d43c8235 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Tue, 19 Apr 2022 22:14:32 -0400 Subject: [PATCH 02/23] Optional Search Data Source. --- .../OnboardingSearchController.swift | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index d87dbac..3b52c0a 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -21,7 +21,7 @@ class OnboardingSearchController: NSViewController { @IBOutlet private var accessoryLabel: NSTextField! @IBOutlet var undoButton: NSButton! - private var searchResultsDataSource: SearchDataSource! + private var searchResultsDataSource: SearchDataSource? private var dataTask: URLSessionDataTask? = .none private var themeDidChangeNotification: NSObjectProtocol? @@ -81,17 +81,19 @@ class OnboardingSearchController: NSViewController { @objc func doubleClickAction(_ tableView: NSTableView) { [accessoryLabel].forEach { $0?.isHidden = false } - if tableView.selectedRow >= 0, tableView.selectedRow < searchResultsDataSource.resultsCount() { - let selectedType = searchResultsDataSource.placeForRow(resultsTableView.selectedRow) + if tableView.selectedRow >= 0, tableView.selectedRow < (searchResultsDataSource?.resultsCount() ?? 0) { + let selectedType = searchResultsDataSource?.placeForRow(resultsTableView.selectedRow) switch selectedType { case .city: - if let filteredGoogleResult = searchResultsDataSource.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) { + if let filteredGoogleResult = searchResultsDataSource?.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) { addTimezoneToDefaults(filteredGoogleResult) } return case .timezone: cleanupAfterInstallingTimezone() return + case .none: + return } } } @@ -100,28 +102,28 @@ class OnboardingSearchController: NSViewController { let data = TimezoneData() data.setLabel(CLEmptyString) - let currentSelection = searchResultsDataSource.retrieveSelectedTimezone(resultsTableView.selectedRow) - - let metaInfo = metadata(for: currentSelection) - data.timezoneID = metaInfo.0.name - data.formattedAddress = metaInfo.1.formattedName - data.selectionType = .timezone - data.isSystemTimezone = metaInfo.0.name == NSTimeZone.system.identifier + if let currentSelection = searchResultsDataSource?.retrieveSelectedTimezone(resultsTableView.selectedRow) { + let metaInfo = metadata(for: currentSelection) + data.timezoneID = metaInfo.0.name + data.formattedAddress = metaInfo.1.formattedName + data.selectionType = .timezone + data.isSystemTimezone = metaInfo.0.name == NSTimeZone.system.identifier - let operationObject = TimezoneDataOperations(with: data) - operationObject.saveObject() + let operationObject = TimezoneDataOperations(with: data) + operationObject.saveObject() - searchResultsDataSource.cleanupFilterArray() - searchResultsDataSource.timezoneFilteredArray = [] - searchResultsDataSource.calculateChangesets() - searchBar.stringValue = CLEmptyString + searchResultsDataSource?.cleanupFilterArray() + searchResultsDataSource?.timezoneFilteredArray = [] + searchResultsDataSource?.calculateChangesets() + searchBar.stringValue = CLEmptyString - accessoryLabel.stringValue = "Added \(metaInfo.1.formattedName)." - undoButton.isHidden = false - setupLabelHidingTimer() + accessoryLabel.stringValue = "Added \(metaInfo.1.formattedName)." + undoButton.isHidden = false + setupLabelHidingTimer() - resultsTableView.reloadData() - resultsTableView.isHidden = true + resultsTableView.reloadData() + resultsTableView.isHidden = true + } } private func metadata(for selection: TimezoneMetadata) -> (NSTimeZone, TimezoneMetadata) { @@ -194,7 +196,7 @@ class OnboardingSearchController: NSViewController { private func fetchTimezone(for latitude: Double, and longitude: Double, _ dataObject: TimezoneData) { if NetworkManager.isConnected() == false || ProcessInfo.processInfo.arguments.contains("mockTimezoneDown") { setInfoLabel(PreferencesConstants.noInternetConnectivityError) - searchResultsDataSource.cleanupFilterArray() + searchResultsDataSource?.cleanupFilterArray() resultsTableView.reloadData() return } @@ -215,7 +217,7 @@ class OnboardingSearchController: NSViewController { } if error == nil, let json = response, let response = json.decodeTimezone() { - if self.resultsTableView.selectedRow >= 0, self.resultsTableView.selectedRow < self.searchResultsDataSource.resultsCount() { + if self.resultsTableView.selectedRow >= 0, self.resultsTableView.selectedRow < (self.searchResultsDataSource?.resultsCount()) ?? 0 { var filteredAddress = "Error" if let address = dataObject.formattedAddress { @@ -312,7 +314,7 @@ class OnboardingSearchController: NSViewController { @objc func actualSearch() { func setupForError() { - searchResultsDataSource.calculateChangesets() + searchResultsDataSource?.calculateChangesets() resultsTableView.isHidden = true } @@ -345,12 +347,12 @@ class OnboardingSearchController: NSViewController { return } - self.searchResultsDataSource.cleanupFilterArray() - self.searchResultsDataSource.timezoneFilteredArray = [] + self.searchResultsDataSource?.cleanupFilterArray() + self.searchResultsDataSource?.timezoneFilteredArray = [] if let errorPresent = error { self.findLocalSearchResultsForTimezones() - if self.searchResultsDataSource.timezoneFilteredArray.count == 0 { + if self.searchResultsDataSource?.timezoneFilteredArray.count == 0 { self.presentErrorMessage(errorPresent.localizedDescription) setupForError() return @@ -391,12 +393,12 @@ class OnboardingSearchController: NSViewController { private func findLocalSearchResultsForTimezones() { let lowercasedSearchString = searchBar.stringValue.lowercased() - searchResultsDataSource.searchTimezones(lowercasedSearchString) + searchResultsDataSource?.searchTimezones(lowercasedSearchString) } private func prepareUIForPresentingResults() { setInfoLabel(CLEmptyString) - if searchResultsDataSource.calculateChangesets() { + if let dataSource = searchResultsDataSource, dataSource.calculateChangesets() { resultsTableView.isHidden = false resultsTableView.reloadData() } @@ -421,13 +423,13 @@ class OnboardingSearchController: NSViewController { return TimezoneData(with: totalPackage) } - searchResultsDataSource.setFilteredArrayValue(finalTimezones) + searchResultsDataSource?.setFilteredArrayValue(finalTimezones) } private func resetSearchView() { - searchResultsDataSource.cleanupFilterArray() - searchResultsDataSource.timezoneFilteredArray = [] - searchResultsDataSource.calculateChangesets() + searchResultsDataSource?.cleanupFilterArray() + searchResultsDataSource?.timezoneFilteredArray = [] + searchResultsDataSource?.calculateChangesets() resultsTableView.reloadData() searchBar.stringValue = CLEmptyString searchBar.placeholderString = "Press Enter to Search" @@ -441,15 +443,15 @@ class OnboardingSearchController: NSViewController { extension OnboardingSearchController: NSTableViewDataSource { func numberOfRows(in _: NSTableView) -> Int { - return searchResultsDataSource != nil ? searchResultsDataSource.resultsCount() : 0 + return searchResultsDataSource?.resultsCount() ?? 0 } func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? { if let result = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "resultCellView"), owner: self) as? ResultTableViewCell, row >= 0, - row < searchResultsDataSource.resultsCount() + row < (searchResultsDataSource?.resultsCount() ?? 0) { - let currentSelection = searchResultsDataSource.retrieveResult(row) + let currentSelection = searchResultsDataSource?.retrieveResult(row) if let timezone = currentSelection as? TimezoneMetadata { result.result.stringValue = " \(timezone.formattedName)" } else if let location = currentSelection as? TimezoneData { @@ -466,7 +468,7 @@ extension OnboardingSearchController: NSTableViewDataSource { extension OnboardingSearchController: NSTableViewDelegate { func tableView(_: NSTableView, heightOfRow row: Int) -> CGFloat { - if row == 0, searchResultsDataSource.resultsCount() == 0 { + if row == 0, searchResultsDataSource?.resultsCount() == 0 { return 30 } @@ -474,7 +476,7 @@ extension OnboardingSearchController: NSTableViewDelegate { } func tableView(_: NSTableView, shouldSelectRow row: Int) -> Bool { - return searchResultsDataSource.resultsCount() == 0 ? row != 0 : true + return searchResultsDataSource?.resultsCount() == 0 ? row != 0 : true } func tableView(_: NSTableView, rowViewForRow _: Int) -> NSTableRowView? { From e30273335557452a18600d156528d8b773aff0fc Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 07:09:16 -0400 Subject: [PATCH 03/23] Use wipe(). --- Clocker/AppDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 778248f..446f405 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -73,9 +73,9 @@ open class AppDelegate: NSObject, NSApplicationDelegate { } @objc private func openPreferencesWindow() { - let displayMode = UserDefaults.standard.integer(forKey: CLShowAppInForeground) + let displayMode = DataStore.shared().shouldDisplay(.showAppInForeground) - if displayMode == 1 { + if displayMode { let floatingWindow = FloatingWindowController.shared() floatingWindow.openPreferences(NSButton()) } else { From 2201b1cda5e879c140a5c9e66d552154dd2c75a6 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 07:09:36 -0400 Subject: [PATCH 04/23] Remove unused method. --- Clocker/Overall App/AppDefaults.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Clocker/Overall App/AppDefaults.swift b/Clocker/Overall App/AppDefaults.swift index a81c6e5..3f1d502 100644 --- a/Clocker/Overall App/AppDefaults.swift +++ b/Clocker/Overall App/AppDefaults.swift @@ -8,16 +8,6 @@ class AppDefaults { initializeDefaults() } - private class func deleteOldUserDefaults() { - let userDefaults = UserDefaults.standard - - // Now delete the old preferences - if let bundleID = Bundle.main.bundleIdentifier, userDefaults.object(forKey: "PreferencesHaveBeenWiped") == nil { - userDefaults.removePersistentDomain(forName: bundleID) - userDefaults.set(true, forKey: "PreferencesHaveBeenWiped") - } - } - private class func initializeDefaults() { let userDefaults = UserDefaults.standard let dataStore = DataStore.shared() @@ -84,9 +74,9 @@ extension UserDefaults { } func wipeIfNeccesary() { - if let bundleID = Bundle.main.bundleIdentifier, object(forKey: "PreferencesHaveBeenWiped") == nil { + if object(forKey: "PreferencesHaveBeenWiped") == nil { Logger.info("Wiping all user defaults") - removePersistentDomain(forName: bundleID) + wipe() set(true, forKey: "PreferencesHaveBeenWiped") } } From b9022fcab60194a529982c3e4edb356a80bb2499 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 08:56:04 -0400 Subject: [PATCH 05/23] Quick UT. --- .../ClockerUnitTests/ClockerUnitTests.swift | 11 ++++++++ Clocker/Overall App/AppDefaults.swift | 25 ++++--------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index f433f0a..ad596c2 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -430,4 +430,15 @@ class ClockerUnitTests: XCTestCase { XCTAssertEqual(subject.subviews.count, 2) // Two textfields XCTAssertEqual(subject.subviews.first?.layer?.animationKeys(), ["notimezone.emoji"]) } + + func testDefaultsWiping() { + let defaultsDict: [String: Any] = ["test1" : "testString", "test2": 24] + let domainName = "com.test.clocker" + let defaults = UserDefaults(suiteName: domainName) + defaults?.setPersistentDomain(defaultsDict, forName: domainName) + defaults?.wipe(for: domainName) + XCTAssertNil(defaults?.object(forKey: "test1")) + XCTAssertNil(defaults?.object(forKey: "test2")) + } + } diff --git a/Clocker/Overall App/AppDefaults.swift b/Clocker/Overall App/AppDefaults.swift index 3f1d502..33dc0b0 100644 --- a/Clocker/Overall App/AppDefaults.swift +++ b/Clocker/Overall App/AppDefaults.swift @@ -15,9 +15,6 @@ class AppDefaults { let timezones = dataStore.timezones() let selectedCalendars = userDefaults.object(forKey: CLSelectedCalendars) - // Now delete the old preferences - userDefaults.wipeIfNeccesary() - // Register the usual suspects userDefaults.register(defaults: defaultsDictionary()) @@ -25,13 +22,11 @@ class AppDefaults { userDefaults.set(selectedCalendars, forKey: CLSelectedCalendars) // Set the theme default as Light! - setDefaultTheme() + setDefaultTheme(userDefaults) } - private class func setDefaultTheme() { - let defaults = UserDefaults.standard - - if defaults.object(forKey: CLThemeKey) == nil { + private class func setDefaultTheme(_ userDefaults: UserDefaults) { + if userDefaults.object(forKey: CLThemeKey) == nil { Themer.shared().set(theme: 0) } } @@ -67,17 +62,7 @@ extension String { extension UserDefaults { // Use this with caution. Exposing this for debugging purposes only. - func wipe() { - if let bundleID = Bundle.main.bundleIdentifier { - removePersistentDomain(forName: bundleID) - } - } - - func wipeIfNeccesary() { - if object(forKey: "PreferencesHaveBeenWiped") == nil { - Logger.info("Wiping all user defaults") - wipe() - set(true, forKey: "PreferencesHaveBeenWiped") - } + func wipe(for bundleID: String) { + removePersistentDomain(forName: bundleID) } } From a788f9080ddf319f353ded75891807a4a82e51e9 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:03:54 -0400 Subject: [PATCH 06/23] Use constants. --- .../Preferences/App Feedback/AppFeedbackWindowController.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift index a351edc..05ef776 100644 --- a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift +++ b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift @@ -18,7 +18,6 @@ extension NSNib.Name { } enum AppFeedbackConstants { - static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow" static let CLAppFeedbackNoResponseString = "Not Provided" static let CLAppFeedbackNameProperty = "name" static let CLAppFeedbackEmailProperty = "email" @@ -256,7 +255,7 @@ class AppFeedbackWindowController: NSWindowController { isActivityInProgress = false let alert = NSAlert() - alert.messageText = "Thank you for helping make Clocker even better!" + alert.messageText = AppFeedbackConstants.CLFeedbackAlertTitle alert.informativeText = AppFeedbackConstants.CLFeedbackAlertInformativeText alert.addButton(withTitle: AppFeedbackConstants.CLFeedbackAlertButtonTitle) alert.beginSheetModal(for: feedbackWindow) { _ in From 7dbd2cb659ff1444b6a5cd9dd6b4ae2b03765214 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:12:49 -0400 Subject: [PATCH 07/23] Remove extra newlines from log statements. --- Clocker/Events and Reminders/EventCenter.swift | 2 +- Clocker/Panel/PanelController.swift | 2 +- Clocker/Preferences/Menu Bar/StatusItemHandler.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Clocker/Events and Reminders/EventCenter.swift b/Clocker/Events and Reminders/EventCenter.swift index 5d6e5ee..9c3b8d2 100644 --- a/Clocker/Events and Reminders/EventCenter.swift +++ b/Clocker/Events and Reminders/EventCenter.swift @@ -42,7 +42,7 @@ class EventCenter: NSObject { } private func refetchAll() { - Logger.info("\nRefetching events from the store") + Logger.info("Refetching events from the store") eventsForDate = [:] filteredEvents = [:] diff --git a/Clocker/Panel/PanelController.swift b/Clocker/Panel/PanelController.swift index 89519f3..9232224 100644 --- a/Clocker/Panel/PanelController.swift +++ b/Clocker/Panel/PanelController.swift @@ -268,7 +268,7 @@ class PanelController: ParentPanelController { if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) { if let delegate = NSApplication.shared.delegate as? AppDelegate { - Logger.info("\nWe will be invalidating the menubar timer as we want the parent timer to take care of both panel and menubar ") + Logger.info("We will be invalidating the menubar timer as we want the parent timer to take care of both panel and menubar ") delegate.invalidateMenubarTimer(false) } diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index 7d6be19..67040d5 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -61,7 +61,7 @@ class StatusItemHandler: NSObject { setClockerIcon() } - Logger.info("\nStatus Bar Current State changed: \(currentState)\n") + Logger.info("Status Bar Current State changed: \(currentState)\n") } } From f6032a8439e2dba9dd7c1085f6d93b3b3caab61d Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:33:13 -0400 Subject: [PATCH 08/23] Inject Data Store + Defaults in AppDefaults.swift --- Clocker/Overall App/AppDefaults.swift | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Clocker/Overall App/AppDefaults.swift b/Clocker/Overall App/AppDefaults.swift index 33dc0b0..7224c48 100644 --- a/Clocker/Overall App/AppDefaults.swift +++ b/Clocker/Overall App/AppDefaults.swift @@ -4,25 +4,22 @@ import Cocoa import CoreLoggerKit class AppDefaults { - class func initialize() { - initializeDefaults() + class func initialize(with store: DataStore, defaults: UserDefaults) { + initializeDefaults(with: store, defaults: defaults) } - private class func initializeDefaults() { - let userDefaults = UserDefaults.standard - let dataStore = DataStore.shared() - - let timezones = dataStore.timezones() - let selectedCalendars = userDefaults.object(forKey: CLSelectedCalendars) + private class func initializeDefaults(with store: DataStore, defaults: UserDefaults) { + let timezones = store.timezones() + let selectedCalendars = defaults.object(forKey: CLSelectedCalendars) // Register the usual suspects - userDefaults.register(defaults: defaultsDictionary()) + defaults.register(defaults: defaultsDictionary()) - dataStore.setTimezones(timezones) - userDefaults.set(selectedCalendars, forKey: CLSelectedCalendars) + store.setTimezones(timezones) + defaults.set(selectedCalendars, forKey: CLSelectedCalendars) // Set the theme default as Light! - setDefaultTheme(userDefaults) + setDefaultTheme(defaults) } private class func setDefaultTheme(_ userDefaults: UserDefaults) { From dce7c81767a721db0ebaba4c687e69f3902e2213 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:33:17 -0400 Subject: [PATCH 09/23] Update AppDelegate.swift --- Clocker/AppDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 446f405..261a666 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -43,7 +43,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { // Required for migrating our model type to CoreModelKit NSKeyedUnarchiver.setClass(CoreModelKit.TimezoneData.classForKeyedUnarchiver(), forClassName: "Clocker.TimezoneData") - AppDefaults.initialize() + AppDefaults.initialize(with: DataStore.shared(), defaults: UserDefaults.standard) // Check if we can show the onboarding flow! showOnboardingFlowIfEligible() @@ -53,7 +53,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { #if RELEASE FirebaseApp.configure() - checkIfRunFromApplicationsFolder() +// checkIfRunFromApplicationsFolder() #endif } From 179f91b65b1ec0f5970c9101c48296ad93533102 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:33:23 -0400 Subject: [PATCH 10/23] Update AppDelegate.swift --- Clocker/AppDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 261a666..a2b2a0d 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -53,7 +53,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { #if RELEASE FirebaseApp.configure() -// checkIfRunFromApplicationsFolder() + checkIfRunFromApplicationsFolder() #endif } From 668a242654b1ec8a3707d8f7ff0b8cc4b1abe411 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:50:25 -0400 Subject: [PATCH 11/23] Move string extension method to the right place. --- Clocker/ClockerUnitTests/ClockerUnitTests.swift | 5 ++--- Clocker/Overall App/AppDefaults.swift | 6 ------ Clocker/Overall App/String + Additions.swift | 4 ++++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index ad596c2..21cca39 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -430,9 +430,9 @@ class ClockerUnitTests: XCTestCase { XCTAssertEqual(subject.subviews.count, 2) // Two textfields XCTAssertEqual(subject.subviews.first?.layer?.animationKeys(), ["notimezone.emoji"]) } - + func testDefaultsWiping() { - let defaultsDict: [String: Any] = ["test1" : "testString", "test2": 24] + let defaultsDict: [String: Any] = ["test1": "testString", "test2": 24] let domainName = "com.test.clocker" let defaults = UserDefaults(suiteName: domainName) defaults?.setPersistentDomain(defaultsDict, forName: domainName) @@ -440,5 +440,4 @@ class ClockerUnitTests: XCTestCase { XCTAssertNil(defaults?.object(forKey: "test1")) XCTAssertNil(defaults?.object(forKey: "test2")) } - } diff --git a/Clocker/Overall App/AppDefaults.swift b/Clocker/Overall App/AppDefaults.swift index 7224c48..558ed05 100644 --- a/Clocker/Overall App/AppDefaults.swift +++ b/Clocker/Overall App/AppDefaults.swift @@ -51,12 +51,6 @@ class AppDefaults { } } -extension String { - func localized() -> String { - return NSLocalizedString(self, comment: "Title for \(self)") - } -} - extension UserDefaults { // Use this with caution. Exposing this for debugging purposes only. func wipe(for bundleID: String) { diff --git a/Clocker/Overall App/String + Additions.swift b/Clocker/Overall App/String + Additions.swift index 9095ba6..c28c0c3 100644 --- a/Clocker/Overall App/String + Additions.swift +++ b/Clocker/Overall App/String + Additions.swift @@ -14,4 +14,8 @@ extension String { return filteredAddress } + + func localized() -> String { + return NSLocalizedString(self, comment: "Title for \(self)") + } } From dc6e3ccb549fcf862a86f2768a1696a373103702 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 09:52:38 -0400 Subject: [PATCH 12/23] Update AppDefaults.swift --- Clocker/Overall App/AppDefaults.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Clocker/Overall App/AppDefaults.swift b/Clocker/Overall App/AppDefaults.swift index 558ed05..e99ba51 100644 --- a/Clocker/Overall App/AppDefaults.swift +++ b/Clocker/Overall App/AppDefaults.swift @@ -17,15 +17,6 @@ class AppDefaults { store.setTimezones(timezones) defaults.set(selectedCalendars, forKey: CLSelectedCalendars) - - // Set the theme default as Light! - setDefaultTheme(defaults) - } - - private class func setDefaultTheme(_ userDefaults: UserDefaults) { - if userDefaults.object(forKey: CLThemeKey) == nil { - Themer.shared().set(theme: 0) - } } private class func defaultsDictionary() -> [String: Any] { From f38c733d380169cbed45d913f6dfb1cd59c6740b Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:09:52 -0400 Subject: [PATCH 13/23] DI Pref and Time Data Source. --- .../Panel/Data Layer/TimezoneDataOperations.swift | 3 ++- Clocker/Panel/ParentPanelController.swift | 5 +++-- Clocker/Panel/UI/TimezoneDataSource.swift | 13 ++++++++----- .../Preferences/General/PreferencesDataSource.swift | 12 +++++++----- .../General/PreferencesViewController.swift | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 0db1170..3914e16 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -6,7 +6,7 @@ import CoreLoggerKit import CoreModelKit class TimezoneDataOperations: NSObject { - private var dataObject: TimezoneData! + private var dataObject: TimezoneData private lazy var nsCalendar = Calendar.autoupdatingCurrent private static var gregorianCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian) private static var swiftyCalendar = Calendar(identifier: .gregorian) @@ -14,6 +14,7 @@ class TimezoneDataOperations: NSObject { init(with timezone: TimezoneData) { dataObject = timezone + super.init() } } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index b2d621a..9ce1654 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -509,12 +509,13 @@ class ParentPanelController: NSWindowController { updatePanelColor() - let defaults = DataStore.shared().timezones() + let store = DataStore.shared() + let defaults = store.timezones() let convertedTimezones = defaults.map { data -> TimezoneData in TimezoneData.customObject(from: data)! } - datasource = TimezoneDataSource(items: convertedTimezones) + datasource = TimezoneDataSource(items: convertedTimezones, store: store) mainTableView.dataSource = datasource mainTableView.delegate = datasource mainTableView.panelDelegate = datasource diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index be15e45..8e1e12e 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -6,10 +6,13 @@ import CoreModelKit class TimezoneDataSource: NSObject { var timezones: [TimezoneData] = [] var sliderValue: Int = 0 + var dataStore: DataStore - init(items: [TimezoneData]) { + init(items: [TimezoneData], store: DataStore) { sliderValue = 0 timezones = Array(items) + dataStore = store + super.init() } } @@ -85,12 +88,12 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { return 100 } - if let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber, + if let userFontSize = dataStore.retrieve(key: CLUserFontSizePreference) as? NSNumber, timezones.count > row, - let relativeDisplay = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber + let relativeDisplay = dataStore.retrieve(key: CLRelativeDateKey) as? NSNumber { let model = timezones[row] - let shouldShowSunrise = DataStore.shared().shouldDisplay(.sunrise) + let shouldShowSunrise = dataStore.shouldDisplay(.sunrise) var rowHeight: Int = userFontSize == 4 ? 60 : 65 @@ -140,7 +143,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { tableView.removeRows(at: indexSet, withAnimation: NSTableView.AnimationOptions()) - if DataStore.shared().shouldDisplay(ViewType.showAppInForeground) { + if self.dataStore.shouldDisplay(ViewType.showAppInForeground) { windowController.deleteTimezone(at: row) } else { guard let panelController = PanelController.panel() else { return } diff --git a/Clocker/Preferences/General/PreferencesDataSource.swift b/Clocker/Preferences/General/PreferencesDataSource.swift index 63d464d..eb6672e 100644 --- a/Clocker/Preferences/General/PreferencesDataSource.swift +++ b/Clocker/Preferences/General/PreferencesDataSource.swift @@ -22,12 +22,14 @@ protocol PreferenceSelectionUpdates: AnyObject { class PreferencesDataSource: NSObject { private weak var updateDelegate: PreferenceSelectionUpdates? + private let store: DataStore var selectedTimezones: [Data] { - return DataStore.shared().timezones() + return store.timezones() } - init(callbackDelegate delegate: PreferenceSelectionUpdates) { - updateDelegate = delegate + init(with store: DataStore, callbackDelegate delegate: PreferenceSelectionUpdates) { + self.store = store + self.updateDelegate = delegate super.init() } } @@ -75,7 +77,7 @@ extension PreferencesDataSource: NSTableViewDelegate { newOrder.insert(currentObject, at: destination) - DataStore.shared().setTimezones(newOrder) + store.setTimezones(newOrder) tableView.reloadData() @@ -185,7 +187,7 @@ extension PreferencesDataSource: NSTableViewDataSource { let encodedObject = NSKeyedArchiver.archivedData(withRootObject: timezone) var newDefaults = selectedTimezones newDefaults[index] = encodedObject - DataStore.shared().setTimezones(newDefaults) + store.setTimezones(newDefaults) } private func updateMenubarTitles() { diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 4226215..d413e72 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -116,7 +116,7 @@ class PreferencesViewController: ParentViewController { searchField.placeholderString = "Enter city, state, country or timezone name" - selectionsDataSource = PreferencesDataSource(callbackDelegate: self) + selectionsDataSource = PreferencesDataSource(with: DataStore.shared(), callbackDelegate: self) timezoneTableView.dataSource = selectionsDataSource timezoneTableView.delegate = selectionsDataSource From 2a4746d5b3e99545ee4d9ef39c2e7a90edee39bb Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:11:34 -0400 Subject: [PATCH 14/23] dataObject shouldn't be mutable. --- Clocker/Panel/Data Layer/TimezoneDataOperations.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 3914e16..5ec980f 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -6,7 +6,7 @@ import CoreLoggerKit import CoreModelKit class TimezoneDataOperations: NSObject { - private var dataObject: TimezoneData + private let dataObject: TimezoneData private lazy var nsCalendar = Calendar.autoupdatingCurrent private static var gregorianCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian) private static var swiftyCalendar = Calendar(identifier: .gregorian) From 92e416789ca07cd30cf9336f3354f44ef8ba2ea0 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:22:24 -0400 Subject: [PATCH 15/23] DI into TimezoneDataOperations. --- .../ClockerUnitTests/ClockerUnitTests.swift | 24 +++++++------- .../OnboardingParentViewController.swift | 2 +- .../OnboardingSearchController.swift | 2 +- .../Data Layer/TimezoneDataOperations.swift | 32 ++++++++++--------- Clocker/Panel/ParentPanelController.swift | 12 +++---- Clocker/Panel/UI/TimezoneDataSource.swift | 10 +++--- .../Appearance/AppearanceViewController.swift | 2 +- .../General/PreferencesViewController.swift | 4 +-- .../Menu Bar/MenubarTitleProvider.swift | 2 +- .../Menu Bar/StatusContainerView.swift | 4 +-- .../Preferences/Menu Bar/StatusItemView.swift | 2 +- 11 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index 21cca39..efc3a60 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -53,23 +53,23 @@ class ClockerUnitTests: XCTestCase { "longitude": "-95.9345034"] private var operations: TimezoneDataOperations { - return TimezoneDataOperations(with: TimezoneData(with: mumbai)) + return TimezoneDataOperations(with: TimezoneData(with: mumbai), store: DataStore.shared()) } private var californiaOperations: TimezoneDataOperations { - return TimezoneDataOperations(with: TimezoneData(with: california)) + return TimezoneDataOperations(with: TimezoneData(with: california), store: DataStore.shared()) } private var floridaOperations: TimezoneDataOperations { - return TimezoneDataOperations(with: TimezoneData(with: florida)) + return TimezoneDataOperations(with: TimezoneData(with: florida), store: DataStore.shared()) } private var aucklandOperations: TimezoneDataOperations { - return TimezoneDataOperations(with: TimezoneData(with: auckland)) + return TimezoneDataOperations(with: TimezoneData(with: auckland), store: DataStore.shared()) } private var omahaOperations: TimezoneDataOperations { - return TimezoneDataOperations(with: TimezoneData(with: omaha)) + return TimezoneDataOperations(with: TimezoneData(with: omaha), store: DataStore.shared()) } func testOverridingSecondsComponent_shouldHideSeconds() { @@ -81,7 +81,7 @@ class ClockerUnitTests: XCTestCase { TimezoneData(with: california)] timezoneObjects.forEach { - let operationsObject = TimezoneDataOperations(with: $0) + let operationsObject = TimezoneDataOperations(with: $0, store: DataStore.shared()) let currentTime = operationsObject.time(with: 0) XCTAssert(currentTime.count == 8) // 8 includes 2 colons @@ -97,7 +97,7 @@ class ClockerUnitTests: XCTestCase { let currentFavourites = DataStore.shared().timezones() let oldCount = currentFavourites.count - let operationsObject = TimezoneDataOperations(with: timezoneData) + let operationsObject = TimezoneDataOperations(with: timezoneData, store: DataStore.shared()) operationsObject.saveObject() let newDefaults = DataStore.shared().timezones() @@ -151,7 +151,7 @@ class ClockerUnitTests: XCTestCase { // California is absent. Add it! if filteredCount.count == 0 { let timezoneData = TimezoneData(with: california) - let operationsObject = TimezoneDataOperations(with: timezoneData) + let operationsObject = TimezoneDataOperations(with: timezoneData, store: DataStore.shared()) operationsObject.saveObject() } @@ -179,7 +179,7 @@ class ClockerUnitTests: XCTestCase { func testSunriseSunset() { let dataObject = TimezoneData(with: mumbai) - let operations = TimezoneDataOperations(with: dataObject) + let operations = TimezoneDataOperations(with: dataObject, store: DataStore.shared()) XCTAssertNotNil(operations.formattedSunriseTime(with: 0)) XCTAssertNotNil(dataObject.sunriseTime) @@ -187,7 +187,7 @@ class ClockerUnitTests: XCTestCase { let timezoneObject = TimezoneData(with: onlyTimezone) timezoneObject.selectionType = .timezone - let timezoneOperations = TimezoneDataOperations(with: timezoneObject) + let timezoneOperations = TimezoneDataOperations(with: timezoneObject, store: DataStore.shared()) XCTAssertTrue(timezoneOperations.formattedSunriseTime(with: 0) == "") XCTAssertNil(timezoneObject.sunriseTime) @@ -196,7 +196,7 @@ class ClockerUnitTests: XCTestCase { func testDateWithSliderValue() { let dataObject = TimezoneData(with: mumbai) - let operations = TimezoneDataOperations(with: dataObject) + let operations = TimezoneDataOperations(with: dataObject, store: DataStore.shared()) XCTAssertNotNil(operations.date(with: 0, displayType: .menu)) } @@ -359,7 +359,7 @@ class ClockerUnitTests: XCTestCase { func testWithAllLocales() { let dataObject1 = TimezoneData(with: mumbai) - let operations = TimezoneDataOperations(with: dataObject1) + let operations = TimezoneDataOperations(with: dataObject1, store: DataStore.shared()) for locale in Locale.availableIdentifiers { let currentLocale = Locale(identifier: locale) diff --git a/Clocker/Onboarding/OnboardingParentViewController.swift b/Clocker/Onboarding/OnboardingParentViewController.swift index 1772011..80d7c68 100644 --- a/Clocker/Onboarding/OnboardingParentViewController.swift +++ b/Clocker/Onboarding/OnboardingParentViewController.swift @@ -189,7 +189,7 @@ class OnboardingParentViewController: NSViewController { currentTimezone.isSystemTimezone = true currentTimezone.placeID = "Home" - let operations = TimezoneDataOperations(with: currentTimezone) + let operations = TimezoneDataOperations(with: currentTimezone, store: DataStore.shared()) operations.saveObject(at: 0) } diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index 3b52c0a..cfded45 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -109,7 +109,7 @@ class OnboardingSearchController: NSViewController { data.selectionType = .timezone data.isSystemTimezone = metaInfo.0.name == NSTimeZone.system.identifier - let operationObject = TimezoneDataOperations(with: data) + let operationObject = TimezoneDataOperations(with: data, store: DataStore.shared()) operationObject.saveObject() searchResultsDataSource?.cleanupFilterArray() diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 5ec980f..8d436a8 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -7,13 +7,15 @@ import CoreModelKit class TimezoneDataOperations: NSObject { private let dataObject: TimezoneData + private let store: DataStore private lazy var nsCalendar = Calendar.autoupdatingCurrent private static var gregorianCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian) private static var swiftyCalendar = Calendar(identifier: .gregorian) private static let currentLocale = Locale.current.identifier - init(with timezone: TimezoneData) { - dataObject = timezone + init(with timezone: TimezoneData, store: DataStore) { + self.dataObject = timezone + self.store = store super.init() } } @@ -29,7 +31,7 @@ extension TimezoneDataOperations { return CLEmptyString } - if dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == DateFormat.epochTime { + if dataObject.timezoneFormat(store.timezoneFormat()) == DateFormat.epochTime { let timezone = TimeZone(identifier: dataObject.timezone()) let offset = timezone?.secondsFromGMT(for: newDate) ?? 0 let value = Int(Date().timeIntervalSince1970 + Double(offset)) @@ -37,7 +39,7 @@ extension TimezoneDataOperations { } let dateFormatter = DateFormatterManager.dateFormatterWithFormat(with: .none, - format: dataObject.timezoneFormat(DataStore.shared().timezoneFormat()), + format: dataObject.timezoneFormat(store.timezoneFormat()), timezoneIdentifier: dataObject.timezone(), locale: Locale.autoupdatingCurrent) @@ -81,15 +83,15 @@ extension TimezoneDataOperations { func compactMenuTitle() -> String { var subtitle = CLEmptyString - let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() - let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar) + let shouldDayBeShown = store.shouldShowDayInMenubar() + let shouldLabelBeShownAlongWithTime = !store.shouldDisplay(.placeInMenubar) if shouldDayBeShown, shouldLabelBeShownAlongWithTime { let substring = date(with: 0, displayType: .menu) subtitle.append(substring) } - let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar() + let shouldDateBeShown = store.shouldShowDateInMenubar() if shouldDateBeShown, shouldLabelBeShownAlongWithTime { let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone()) subtitle.isEmpty ? subtitle.append("\(date)") : subtitle.append(" \(date)") @@ -101,15 +103,15 @@ extension TimezoneDataOperations { func compactMenuSubtitle() -> String { var subtitle = CLEmptyString - let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() - let shouldLabelsNotBeShownAlongWithTime = DataStore.shared().shouldDisplay(.placeInMenubar) + let shouldDayBeShown = store.shouldShowDayInMenubar() + let shouldLabelsNotBeShownAlongWithTime = store.shouldDisplay(.placeInMenubar) if shouldDayBeShown, shouldLabelsNotBeShownAlongWithTime { let substring = date(with: 0, displayType: .menu) subtitle.append(substring) } - let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar() + let shouldDateBeShown = store.shouldShowDateInMenubar() if shouldDateBeShown, shouldLabelsNotBeShownAlongWithTime { let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone()) subtitle.isEmpty ? subtitle.append("\(date)") : subtitle.append(" \(date)") @@ -123,7 +125,7 @@ extension TimezoneDataOperations { func menuTitle() -> String { var menuTitle = CLEmptyString - let dataStore = DataStore.shared() + let dataStore = store let shouldCityBeShown = dataStore.shouldDisplay(.placeInMenubar) let shouldDayBeShown = dataStore.shouldShowDayInMenubar() @@ -200,7 +202,7 @@ extension TimezoneDataOperations { } func date(with sliderValue: Int, displayType: TimezoneData.DateDisplayType) -> String { - guard let relativeDayPreference = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber else { + guard let relativeDayPreference = store.retrieve(key: CLRelativeDateKey) as? NSNumber else { assertionFailure("Data was unexpectedly nil") return CLEmptyString } @@ -389,7 +391,7 @@ extension TimezoneDataOperations { let dateFormatter = DateFormatter() dateFormatter.locale = Locale(identifier: "en_US") dateFormatter.timeZone = TimeZone(identifier: dataObject.timezone()) - dateFormatter.dateFormat = dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) + dateFormatter.dateFormat = dataObject.timezoneFormat(store.timezoneFormat()) return dateFormatter.string(from: correct) } @@ -418,10 +420,10 @@ extension TimezoneDataOperations { } func saveObject(at index: Int = -1) { - var defaults = DataStore.shared().timezones() + var defaults = store.timezones() let encodedObject = NSKeyedArchiver.archivedData(withRootObject: dataObject as Any) index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index) - DataStore.shared().setTimezones(defaults) + store.setTimezones(defaults) } } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 9ce1654..4644e92 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -426,7 +426,7 @@ class ParentPanelController: NSWindowController { if let note = object?.note, note.isEmpty == false { newHeight += 20 } else if let obj = object, - TimezoneDataOperations(with: obj).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) != nil + TimezoneDataOperations(with: obj, store: DataStore.shared()).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) != nil { newHeight += 20 } @@ -436,7 +436,7 @@ class ParentPanelController: NSWindowController { // Set it to 90 expicity in case the row height is calculated be higher. newHeight = 88.0 - if let note = object?.note, note.isEmpty, let obj = object, TimezoneDataOperations(with: obj).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) == nil { + if let note = object?.note, note.isEmpty, let obj = object, TimezoneDataOperations(with: obj, store: DataStore.shared()).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) == nil { newHeight -= 20.0 } } @@ -624,7 +624,7 @@ class ParentPanelController: NSWindowController { if modernContainerView != nil, modernSlider.isHidden == false, modernContainerView.currentlyInFocus { return } - let dataOperation = TimezoneDataOperations(with: model) + let dataOperation = TimezoneDataOperations(with: model, store: DataStore.shared()) cellView.time.stringValue = dataOperation.time(with: futureSliderValue) cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue) cellView.sunriseSetTime.lineBreakMode = .byClipping @@ -636,7 +636,7 @@ class ParentPanelController: NSWindowController { } if let note = model.note, !note.isEmpty { cellView.noteLabel.stringValue = note - } else if let value = TimezoneDataOperations(with: model).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) { + } else if let value = TimezoneDataOperations(with: model, store: DataStore.shared()).nextDaylightSavingsTransitionIfAvailable(with: futureSliderValue) { cellView.noteLabel.stringValue = value } else { cellView.noteLabel.stringValue = CLEmptyString @@ -1125,7 +1125,7 @@ extension ParentPanelController: NSSharingServicePickerDelegate { return clipboardCopy } - let timezoneOperations = TimezoneDataOperations(with: earliestTimezone) + let timezoneOperations = TimezoneDataOperations(with: earliestTimezone, store: DataStore.shared()) var sectionTitle = timezoneOperations.todaysDate(with: 0) // TODO: Take slider value into consideration clipboardCopy.append("\(sectionTitle)\n") @@ -1133,7 +1133,7 @@ extension ParentPanelController: NSSharingServicePickerDelegate { if $0 < sortedByTime.count, let dataModel = TimezoneData.customObject(from: sortedByTime[$0]) { - let dataOperations = TimezoneDataOperations(with: dataModel) + let dataOperations = TimezoneDataOperations(with: dataModel, store: DataStore.shared()) let date = dataOperations.todaysDate(with: 0) let time = dataOperations.time(with: 0) if date != sectionTitle { diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index 8e1e12e..cc248ef 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -54,7 +54,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { } let currentModel = timezones[row] - let operation = TimezoneDataOperations(with: currentModel) + let operation = TimezoneDataOperations(with: currentModel, store: dataStore) cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: sliderValue) cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() @@ -107,7 +107,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { if let note = model.note, !note.isEmpty { rowHeight += userFontSize.intValue + 15 - } else if TimezoneDataOperations(with: model).nextDaylightSavingsTransitionIfAvailable(with: sliderValue) != nil { + } else if TimezoneDataOperations(with: model, store: dataStore).nextDaylightSavingsTransitionIfAvailable(with: sliderValue) != nil { rowHeight += userFontSize.intValue + 15 } @@ -176,12 +176,14 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { let response = alert.runModal() if response.rawValue == 1000 { - OperationQueue.main.addOperation { + OperationQueue.main.addOperation { [weak self] in + guard let sSelf = self else { return } + let indexSet = IndexSet(integer: row) tableView.removeRows(at: indexSet, withAnimation: NSTableView.AnimationOptions.slideUp) - if DataStore.shared().shouldDisplay(ViewType.showAppInForeground) { + if sSelf.dataStore.shouldDisplay(ViewType.showAppInForeground) { let windowController = FloatingWindowController.shared() windowController.deleteTimezone(at: row) } else { diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 679fb54..695175f 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -381,7 +381,7 @@ extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate { } let currentModel = previewTimezones[row] - let operation = TimezoneDataOperations(with: currentModel) + let operation = TimezoneDataOperations(with: currentModel, store: DataStore.shared()) cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: 0) cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index d413e72..6c8c6ad 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -612,7 +612,7 @@ extension PreferencesViewController { // Mark if the timezone is same as local timezone let timezoneObject = TimezoneData(with: newTimeZone) - let operationsObject = TimezoneDataOperations(with: timezoneObject) + let operationsObject = TimezoneDataOperations(with: timezoneObject, store: DataStore.shared()) operationsObject.saveObject() Logger.log(object: ["PlaceName": filteredAddress, "Timezone": timezone.timeZoneId], for: "Filtered Address") @@ -746,7 +746,7 @@ extension PreferencesViewController { data.selectionType = .timezone data.isSystemTimezone = metaInfo.0.name == NSTimeZone.system.identifier - let operationObject = TimezoneDataOperations(with: data) + let operationObject = TimezoneDataOperations(with: data, store: DataStore.shared()) operationObject.saveObject() searchResultsDataSource.cleanupFilterArray() diff --git a/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift b/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift index d4305e3..1a36310 100644 --- a/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift +++ b/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift @@ -34,7 +34,7 @@ class MenubarTitleProvider: NSObject { if menubarTitles.isEmpty == false { let titles = menubarTitles.map { data -> String? in let timezone = TimezoneData.customObject(from: data) - let operationsObject = TimezoneDataOperations(with: timezone!) + let operationsObject = TimezoneDataOperations(with: timezone!, store: store) return "\(operationsObject.menuTitle().trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines))" } diff --git a/Clocker/Preferences/Menu Bar/StatusContainerView.swift b/Clocker/Preferences/Menu Bar/StatusContainerView.swift index 6de08d5..e50ad6a 100644 --- a/Clocker/Preferences/Menu Bar/StatusContainerView.swift +++ b/Clocker/Preferences/Menu Bar/StatusContainerView.swift @@ -96,7 +96,7 @@ class StatusContainerView: NSView { if let timezoneObject = TimezoneData.customObject(from: timezone) { let precalculatedWidth = Double(compactWidth(for: timezoneObject, with: store)) - let operationObject = TimezoneDataOperations(with: timezoneObject) + let operationObject = TimezoneDataOperations(with: timezoneObject, store: store) let calculatedSubtitleSize = compactModeTimeFont.size(for: operationObject.compactMenuSubtitle(), width: precalculatedWidth, attributes: timeBasedAttributes) @@ -158,7 +158,7 @@ class StatusContainerView: NSView { NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, ] - let operation = TimezoneDataOperations(with: timezone) + let operation = TimezoneDataOperations(with: timezone, store: store) let bestSize = compactModeTimeFont.size(for: operation.compactMenuSubtitle(), width: Double(compactWidth(for: timezone, with: store)), attributes: timeBasedAttributes) diff --git a/Clocker/Preferences/Menu Bar/StatusItemView.swift b/Clocker/Preferences/Menu Bar/StatusItemView.swift index a2b871b..ea61d36 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemView.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemView.swift @@ -40,7 +40,7 @@ class StatusItemView: NSView { private let locationView = NSTextField(labelWithString: "Hello") private let timeView = NSTextField(labelWithString: "Mon 19:14 PM") private var operationsObject: TimezoneDataOperations { - return TimezoneDataOperations(with: dataObject) + return TimezoneDataOperations(with: dataObject, store: DataStore.shared()) } private var timeAttributes: [NSAttributedString.Key: AnyObject] { From 0e1848afb265470d75aa78289d81a9210e795524 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:50:14 -0400 Subject: [PATCH 16/23] Fix premature optimization. --- Clocker/AppDelegate.swift | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index a2b2a0d..2f3a1cd 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -88,16 +88,20 @@ open class AppDelegate: NSObject, NSApplicationDelegate { NSApp.setActivationPolicy(.accessory) } - private lazy var controller: OnboardingController? = { - let onboardingStoryboard = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) - return onboardingStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController - }() - + private var controller: OnboardingController? + private func showOnboardingFlowIfEligible() { - let shouldLaunchOnboarding = (DataStore.shared().retrieve(key: CLShowOnboardingFlow) == nil && DataStore.shared().timezones().isEmpty) - || ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) - - shouldLaunchOnboarding ? controller?.launch() : continueUsually() + let shouldLaunchOnboarding = (DataStore.shared().retrieve(key: CLShowOnboardingFlow) == nil + && DataStore.shared().timezones().isEmpty) + || ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) + + if (shouldLaunchOnboarding) { + let onboardingStoryboard = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) + controller = onboardingStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController + controller?.launch() + } else { + continueUsually() + } } func continueUsually() { From c1236b3faddb00893647bfc38bafc18be77c2c09 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 12:55:02 -0400 Subject: [PATCH 17/23] Formatting. --- Clocker/AppDelegate.swift | 12 +++++++----- .../Panel/Data Layer/TimezoneDataOperations.swift | 2 +- Clocker/Panel/UI/TimezoneDataSource.swift | 4 ++-- .../Preferences/General/PreferencesDataSource.swift | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 2f3a1cd..6f265da 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -89,13 +89,15 @@ open class AppDelegate: NSObject, NSApplicationDelegate { } private var controller: OnboardingController? - + private func showOnboardingFlowIfEligible() { - let shouldLaunchOnboarding = (DataStore.shared().retrieve(key: CLShowOnboardingFlow) == nil - && DataStore.shared().timezones().isEmpty) - || ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) + let isTestInProgress = ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) + let shouldLaunchOnboarding = + (DataStore.shared().retrieve(key: CLShowOnboardingFlow) == nil + && DataStore.shared().timezones().isEmpty) + || isTestInProgress - if (shouldLaunchOnboarding) { + if shouldLaunchOnboarding { let onboardingStoryboard = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) controller = onboardingStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController controller?.launch() diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 8d436a8..f62e648 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -14,7 +14,7 @@ class TimezoneDataOperations: NSObject { private static let currentLocale = Locale.current.identifier init(with timezone: TimezoneData, store: DataStore) { - self.dataObject = timezone + dataObject = timezone self.store = store super.init() } diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index cc248ef..1d74463 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -143,7 +143,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { tableView.removeRows(at: indexSet, withAnimation: NSTableView.AnimationOptions()) - if self.dataStore.shouldDisplay(ViewType.showAppInForeground) { + if self.dataStore.shouldDisplay(ViewType.showAppInForeground) { windowController.deleteTimezone(at: row) } else { guard let panelController = PanelController.panel() else { return } @@ -178,7 +178,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { if response.rawValue == 1000 { OperationQueue.main.addOperation { [weak self] in guard let sSelf = self else { return } - + let indexSet = IndexSet(integer: row) tableView.removeRows(at: indexSet, withAnimation: NSTableView.AnimationOptions.slideUp) diff --git a/Clocker/Preferences/General/PreferencesDataSource.swift b/Clocker/Preferences/General/PreferencesDataSource.swift index eb6672e..aafef6c 100644 --- a/Clocker/Preferences/General/PreferencesDataSource.swift +++ b/Clocker/Preferences/General/PreferencesDataSource.swift @@ -29,7 +29,7 @@ class PreferencesDataSource: NSObject { init(with store: DataStore, callbackDelegate delegate: PreferenceSelectionUpdates) { self.store = store - self.updateDelegate = delegate + updateDelegate = delegate super.init() } } From 24bb9014009a854bc64b35a5f3cc36245a9e6db4 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Wed, 20 Apr 2022 14:05:32 -0400 Subject: [PATCH 18/23] Use Logger instead of print. --- Clocker/Overall App/ConfigExport.swift | 5 +++-- Clocker/Overall App/DataStore.swift | 2 +- Clocker/Panel/Rate Controller/UpcomingEventView.swift | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Clocker/Overall App/ConfigExport.swift b/Clocker/Overall App/ConfigExport.swift index 482ec5f..f96e5bc 100644 --- a/Clocker/Overall App/ConfigExport.swift +++ b/Clocker/Overall App/ConfigExport.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import CoreModelKit +import CoreLoggerKit import Foundation struct ConfigExport { @@ -34,7 +35,7 @@ struct ConfigExport { var clockerPrefs: [String: Any] = [:] for (key, value) in dictionaryRep { if selectedKeys.contains(key) { - print("Key is \(key) and value is \(value)") + Logger.info("Config Export: Key is \(key) and value is \(value)") clockerPrefs[key] = value } } @@ -73,7 +74,7 @@ struct ConfigExport { let json = try JSONSerialization.data(withJSONObject: clockerPrefs, options: .prettyPrinted) print(json) } catch { - print("Failure Observed \(error.localizedDescription)") + Logger.info("Failure Observed \(error.localizedDescription)") } } } diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 2cdb2eb..5668610 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -66,7 +66,7 @@ class DataStore: NSObject { @objc func ubiquitousKeyValueStoreChanged(_ notification: Notification) { let userInfo = notification.userInfo ?? [:] let ubiquitousStore = notification.object as? NSUbiquitousKeyValueStore - print("--- User Info is \(userInfo)") + Logger.info("Ubiquitous Store Changed: User Info is \(userInfo)") let currentTimezones = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data] let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date() diff --git a/Clocker/Panel/Rate Controller/UpcomingEventView.swift b/Clocker/Panel/Rate Controller/UpcomingEventView.swift index 7bd1026..152c9c6 100644 --- a/Clocker/Panel/Rate Controller/UpcomingEventView.swift +++ b/Clocker/Panel/Rate Controller/UpcomingEventView.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import Cocoa +import CoreLoggerKit class ModernSliderContainerView: NSView { private var trackingArea: NSTrackingArea? @@ -67,7 +68,7 @@ class DraggableClipView: NSClipView { clickPoint = nil gestureInProgress = false default: - print("Default case is happening \(event.type)") + Logger.info("Default mouse event occurred for \(event.type)") } } } From 375eb471b9a42a5a8838987dd7d60d4196d9db0d Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Fri, 6 May 2022 08:49:18 +0530 Subject: [PATCH 19/23] Add docs. --- Clocker/Preferences/Menu Bar/StatusContainerView.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Clocker/Preferences/Menu Bar/StatusContainerView.swift b/Clocker/Preferences/Menu Bar/StatusContainerView.swift index e50ad6a..a3105af 100644 --- a/Clocker/Preferences/Menu Bar/StatusContainerView.swift +++ b/Clocker/Preferences/Menu Bar/StatusContainerView.swift @@ -47,6 +47,12 @@ protocol StatusItemViewConforming { func statusItemViewIdentifier() -> String } +/// Observe for User Default changes for timezones in App Delegate and reconstruct the Status View if neccesary +/// We'll inject the menubar timezones into Status Container View which'll pass it to StatusItemView +/// The benefit of doing so is reducing time-spent calculating menubar timezones and deserialization through `TimezoneData.customObject` +/// Also inject, `shouldDisplaySecondsInMenubar` +/// + class StatusContainerView: NSView { private var previousX: Int = 0 private let store: DataStore From ab9147058e3ec7f4c51a04400fd455c929e63acf Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sat, 7 May 2022 21:18:38 +0530 Subject: [PATCH 20/23] Match System Font. --- Clocker/Preferences/Menu Bar/StatusItemHandler.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index 67040d5..f4b40ad 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -365,9 +365,10 @@ class StatusItemHandler: NSObject { setClockerIcon() return } - - statusItem.button?.title = menubarText - statusItem.button?.font = NSFont.monospacedDigitSystemFont(ofSize: 14.0, weight: NSFont.Weight.regular) + + let attributes = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular), + NSAttributedString.Key.baselineOffset : 0.1] as [NSAttributedString.Key : Any] + statusItem.button?.attributedTitle = NSAttributedString(string: menubarText, attributes: attributes) statusItem.button?.image = nil statusItem.button?.imagePosition = .imageLeft } From 4e1a56f834cf37eb5656d654fe55b0b80fbc098a Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sat, 7 May 2022 21:23:12 +0530 Subject: [PATCH 21/23] Match system clock font. --- Clocker/Panel/ParentPanelController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 4644e92..8745d30 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -586,6 +586,9 @@ class ParentPanelController: NSWindowController { } private lazy var menubarTitleHandler = MenubarTitleProvider(with: DataStore.shared(), eventStore: EventCenter.sharedCenter()) + + static private let attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font: NSFont.monospacedDigitSystemFont(ofSize: 13.0, weight: NSFont.Weight.regular), + NSAttributedString.Key.baselineOffset : 0.1] @objc func updateTime() { let store = DataStore.shared() @@ -597,7 +600,8 @@ class ParentPanelController: NSWindowController { if store.shouldDisplay(.menubarCompactMode) { status.updateCompactMenubar() } else { - status.statusItem.title = menubarTitleHandler.titleForMenubar() + status.statusItem.button?.attributedTitle = NSAttributedString(string: menubarTitleHandler.titleForMenubar() ?? "", + attributes: ParentPanelController.attributes) } } } From fd5ce9ed2f63ff701cb57dba462c7afeab03f669 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sat, 7 May 2022 21:34:36 +0530 Subject: [PATCH 22/23] Mins => m. --- .../Data Layer/TimezoneDataOperations.swift | 2 +- Clocker/Preferences/Preferences.storyboard | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index f62e648..e6a6dda 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -335,7 +335,7 @@ extension TimezoneDataOperations { let minuteDifference = calculateTimeDifference(with: local as NSDate, timezoneDate: timezoneDate as NSDate) - minuteDifference == 0 ? replaceAgo.append("behind") : replaceAgo.append("\(minuteDifference) mins behind") + minuteDifference == 0 ? replaceAgo.append("behind") : replaceAgo.append("\(minuteDifference)m behind") return replaceAgo.lowercased() } diff --git a/Clocker/Preferences/Preferences.storyboard b/Clocker/Preferences/Preferences.storyboard index 8bffd78..9648eed 100644 --- a/Clocker/Preferences/Preferences.storyboard +++ b/Clocker/Preferences/Preferences.storyboard @@ -283,7 +283,7 @@ - When selected, your upcoming meeting title will appear in the menubar 30 mins before it starts. All Day Events won't be shown in the menubar! + When selected, your upcoming meeting title will appear in the menubar 30m before it starts. All Day Events won't be shown in the menubar! @@ -411,7 +411,7 @@ - + @@ -434,7 +434,7 @@ - + - + - + - + @@ -1666,14 +1666,14 @@ DQ - + - + From 326bb6b289c52d4717c74d971cf5bc796b6147b3 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 8 May 2022 14:49:26 +0530 Subject: [PATCH 23/23] Revert back to non-cached reading of menubar display options. --- Clocker/Overall App/DataStore.swift | 30 +++++++++---------- .../Appearance/AppearanceViewController.swift | 2 -- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 5668610..8ed0f6a 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -41,8 +41,6 @@ class DataStore: NSObject { init(with defaults: UserDefaults) { super.init() userDefaults = defaults - shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) - shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) setupSyncNotification() } @@ -113,20 +111,14 @@ class DataStore: NSObject { } } - func updateDayPreference() { - shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) - } - - func updateDateInPreference() { - shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) + // MARK: Date (May 8th) in Compact Menubar + func shouldShowDateInMenubar() -> Bool { + return shouldDisplay(.dateInMenubar) } - + + // MARK: Day (Sun, Mon etc.) in Compact Menubar func shouldShowDayInMenubar() -> Bool { - return shouldDisplayDayInMenubar - } - - func shouldShowDateInMenubar() -> Bool { - return shouldDisplayDateInMenubar + return shouldDisplay(.dayInMenubar) } func retrieve(key: String) -> Any? { @@ -189,11 +181,11 @@ class DataStore: NSObject { } return value.isEqual(to: NSNumber(value: 1)) case .dateInMenubar: - return shouldDisplayHelper(CLShowDateInMenu) + return shouldDisplayNonObjectHelper(CLShowDateInMenu) case .placeInMenubar: return shouldDisplayHelper(CLShowPlaceInMenu) case .dayInMenubar: - return shouldDisplayHelper(CLShowDayInMenu) + return shouldDisplayNonObjectHelper(CLShowDayInMenu) case .appDisplayOptions: return shouldDisplayHelper(CLAppDisplayOptions) case .menubarCompactMode: @@ -215,6 +207,12 @@ class DataStore: NSObject { } return value.isEqual(to: NSNumber(value: 0)) } + + // MARK: Some values are stored as plain integers; objectForKey: will return nil, so using integerForKey: + private func shouldDisplayNonObjectHelper(_ key: String) -> Bool { + let value = userDefaults.integer(forKey: key) + return value == 0 + } } extension DataStore { diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 695175f..002c6be 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -316,12 +316,10 @@ class AppearanceViewController: ParentViewController { } @IBAction func displayDayInMenubarAction(_: Any) { - DataStore.shared().updateDayPreference() updateStatusItem() } @IBAction func displayDateInMenubarAction(_: Any) { - DataStore.shared().updateDateInPreference() updateStatusItem() }