From 46e0e8b248863251e783c9a634c46f6f1f443ba8 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 2 Feb 2021 10:48:33 -0600 Subject: [PATCH 01/10] Spacing. --- Clocker/AppDelegate.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 95bd590..8ce9819 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -48,9 +48,9 @@ open class AppDelegate: NSObject, NSApplicationDelegate { // Required for migrating our model type to CoreModelKit NSKeyedUnarchiver.setClass(CoreModelKit.TimezoneData.classForKeyedUnarchiver(), forClassName: "Clocker.TimezoneData") - - // For users, still on the old timezones, only migrate timezonezes once setClass has been called - migrateOverridenTimezones() + + // For users, still on the old timezones, only migrate timezonezes once setClass has been called + migrateOverridenTimezones() AppDefaults.initialize() From 64ce22e4456e4acc0cae40715a25bd1e297085c5 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 2 Feb 2021 21:56:50 -0600 Subject: [PATCH 02/10] Fix incorrect key values. --- Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift b/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift index 8259629..649384b 100644 --- a/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift +++ b/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift @@ -59,8 +59,8 @@ public class TimezoneData: NSObject, NSCoding { NSNumber(integerLiteral: 7): DateFormat.twelveHourWithZeroSeconds, // Suffix - NSNumber(integerLiteral: 8): DateFormat.twelveHourWithoutSuffix, - NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffixAndSeconds, + NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffix, + NSNumber(integerLiteral: 10): DateFormat.twelveHourWithoutSuffixAndSeconds, ] public var customLabel: String? From 2947588f29b6bd93e56b632489147111c44a1c59 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Tue, 2 Feb 2021 22:37:37 -0600 Subject: [PATCH 03/10] Fix incorrect date/day preference. --- Clocker/AppDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 8ce9819..806752a 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -49,11 +49,11 @@ open class AppDelegate: NSObject, NSApplicationDelegate { // Required for migrating our model type to CoreModelKit NSKeyedUnarchiver.setClass(CoreModelKit.TimezoneData.classForKeyedUnarchiver(), forClassName: "Clocker.TimezoneData") + AppDefaults.initialize() + // For users, still on the old timezones, only migrate timezonezes once setClass has been called migrateOverridenTimezones() - AppDefaults.initialize() - // Check if we can show the onboarding flow! showOnboardingFlowIfEligible() From 7902fa60e0aa21cfa290abedfea466ea731c868b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 5 Feb 2021 11:10:15 -0600 Subject: [PATCH 04/10] Update Chinese Traditional translations + Open App Store on tapping iVersion download button. --- Clocker/Clocker/zh-Hant.lproj/Localizable.strings | 4 ++-- Clocker/Dependencies/iVersion/iVersion.m | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Clocker/Clocker/zh-Hant.lproj/Localizable.strings b/Clocker/Clocker/zh-Hant.lproj/Localizable.strings index 26206a5..5874828 100644 --- a/Clocker/Clocker/zh-Hant.lproj/Localizable.strings +++ b/Clocker/Clocker/zh-Hant.lproj/Localizable.strings @@ -108,8 +108,8 @@ "Display the time in seconds" = "顯示時間秒數"; "Larger Text" = "較大文字"; "Future Slider Range" = "未來滑桿範圍"; -"Include Date" = "包含星期"; -"Include Day" = "包含日期"; +"Include Date" = "包含日期"; +"Include Day" = "包含星期"; "Include Place Name" = "包含位置名稱"; "Menubar Display Options" = "選單列顯示選項"; "Menubar Mode" = "選單列模式"; diff --git a/Clocker/Dependencies/iVersion/iVersion.m b/Clocker/Dependencies/iVersion/iVersion.m index 28814f7..bb998a0 100755 --- a/Clocker/Dependencies/iVersion/iVersion.m +++ b/Clocker/Dependencies/iVersion/iVersion.m @@ -820,6 +820,7 @@ static NSString *mostRecentVersionInDict(NSDictionary *dictionary) { //clear reminder self.lastReminded = nil; + [self openAppPageInAppStore]; } else if (buttonIndex == ignoreButtonIndex) { From 217bcff5a72e16b78bf74aaede388834e0c0ad9c Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 16:02:41 -0600 Subject: [PATCH 05/10] Update iVersion.m --- Clocker/Dependencies/iVersion/iVersion.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Clocker/Dependencies/iVersion/iVersion.m b/Clocker/Dependencies/iVersion/iVersion.m index bb998a0..eab6a41 100755 --- a/Clocker/Dependencies/iVersion/iVersion.m +++ b/Clocker/Dependencies/iVersion/iVersion.m @@ -147,7 +147,7 @@ static NSString *mostRecentVersionInDict(NSDictionary *dictionary) bundle = [NSBundle bundleWithPath:bundlePath] ?: [NSBundle mainBundle]; } defaultString = [bundle localizedStringForKey:key value:defaultString table:nil]; - return [[NSBundle mainBundle] localizedStringForKey:key value:defaultString table:nil]; + return defaultString ?: [[NSBundle mainBundle] localizedStringForKey:key value:defaultString table:nil]; } - (iVersion *)init From cc08fb3c44a086f31969b82e2cf56763409e20e9 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 17:38:57 -0600 Subject: [PATCH 06/10] Abstracting away some unneccesary public deets from SearchDataSource. --- .../General/SearchDataSource.swift | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index 52bf17a..ed8d6d9 100644 --- a/Clocker/Preferences/General/SearchDataSource.swift +++ b/Clocker/Preferences/General/SearchDataSource.swift @@ -29,8 +29,8 @@ class SearchDataSource: NSObject { "EST": ["florida", "new york"], "EDT": ["florida", "new york"]] - var filteredArray: [Any] = [] - var timezoneArray: [TimezoneMetadata] = [] + private var filteredArray: [Any] = [] + private var timezoneArray: [TimezoneMetadata] = [] var timezoneFilteredArray: [TimezoneMetadata] = [] init(with searchField: NSSearchField) { @@ -52,6 +52,15 @@ class SearchDataSource: NSObject { return finalArray[row] } + func retrieveFilteredResult(_ index: Int) -> TimezoneData? { + guard let dataObject = filteredArray[index % filteredArray.count] as? TimezoneData else { + assertionFailure("Data was unexpectedly nil") + return nil + } + + return dataObject + } + private func setupTimezoneDatasource() { timezoneArray = [] @@ -123,6 +132,23 @@ class SearchDataSource: NSObject { return false } + + func searchTimezones(_ searchString: String) { + timezoneFilteredArray = [] + + timezoneFilteredArray = timezoneArray.filter { (timezoneMetadata) -> Bool in + let tags = timezoneMetadata.tags + for tag in tags where tag.contains(searchString) { + return true + } + return false + } + } + + func retrieveSelectedTimezone(_ searchString: String, _ selectedIndex: Int) -> TimezoneMetadata { + return searchString.isEmpty == false ? timezoneFilteredArray[selectedIndex % timezoneFilteredArray.count] : + timezoneArray[selectedIndex - 1] + } } extension SearchDataSource: NSTableViewDataSource { From 95df24857d36e9637735fec3ec019d33775e3977 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 17:39:06 -0600 Subject: [PATCH 07/10] Update PreferencesViewController.swift --- .../General/PreferencesViewController.swift | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index e8dd92e..abcb8af 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -466,16 +466,8 @@ extension PreferencesViewController { } private func findLocalSearchResultsForTimezones() { - searchResultsDataSource.timezoneFilteredArray = [] let lowercasedSearchString = searchField.stringValue.lowercased() - - searchResultsDataSource.timezoneFilteredArray = searchResultsDataSource.timezoneArray.filter { (timezoneMetadata) -> Bool in - let tags = timezoneMetadata.tags - for tag in tags where tag.contains(lowercasedSearchString) { - return true - } - return false - } + searchResultsDataSource.searchTimezones(lowercasedSearchString) Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription) } @@ -613,7 +605,7 @@ extension PreferencesViewController { } private func installTimezone(_ timezone: Timezone) { - guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { + guard let dataObject = searchResultsDataSource.retrieveFilteredResult(availableTimezoneTableView.selectedRow) else { assertionFailure("Data was unexpectedly nil") return } @@ -763,7 +755,7 @@ extension PreferencesViewController { } private func cleanupAfterInstallingCity() { - guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { + guard let dataObject = searchResultsDataSource.retrieveFilteredResult(availableTimezoneTableView.selectedRow) else { assertionFailure("Data was unexpectedly nil") return } @@ -784,8 +776,8 @@ extension PreferencesViewController { let data = TimezoneData() data.setLabel(CLEmptyString) - let currentSelection = searchField.stringValue.isEmpty == false ? searchResultsDataSource.timezoneFilteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.timezoneFilteredArray.count] : - searchResultsDataSource.timezoneArray[availableTimezoneTableView.selectedRow - 1] + let currentSelection = searchResultsDataSource.retrieveSelectedTimezone(searchField.stringValue, + availableTimezoneTableView.selectedRow) let metaInfo = metadata(for: currentSelection) data.timezoneID = metaInfo.0.name From 3c216f60bb2342c780bd838f07ef29458906cec8 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 17:40:14 -0600 Subject: [PATCH 08/10] Update PreferencesViewController.swift --- .../Preferences/General/PreferencesViewController.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index abcb8af..4c0735e 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -412,15 +412,7 @@ extension PreferencesViewController { } self.placeholderLabel.isHidden = false - - /* - if NetworkManager.isConnected() == false { - self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError - return - }*/ - self.isActivityInProgress = true - self.placeholderLabel.placeholderString = "Searching for \(searchString)" Logger.info(self.placeholderLabel.placeholderString ?? "") From 12d7684ec925f4269e3c7515e2af1f176092b747 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 18:00:36 -0600 Subject: [PATCH 09/10] Only add a home timezone if user added nothing! --- Clocker/AppDelegate.swift | 22 ------------------- .../OnboardingParentViewController.swift | 20 +++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 806752a..5a850ae 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -139,11 +139,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate { // Install the menubar item! statusBarHandler = StatusItemHandler() - if UserDefaults.standard.object(forKey: CLInstallHomeIndicatorObject) == nil { - fetchLocalTimezone() - UserDefaults.standard.set(1, forKey: CLInstallHomeIndicatorObject) - } - if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) { RateController.setPreviewMode(true) } @@ -210,23 +205,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate { alert.runModal() } - private func fetchLocalTimezone() { - let identifier = TimeZone.autoupdatingCurrent.identifier - - let currentTimezone = TimezoneData() - currentTimezone.timezoneID = identifier - currentTimezone.setLabel(identifier) - currentTimezone.formattedAddress = identifier - currentTimezone.isSystemTimezone = true - currentTimezone.placeID = "Home" - - let operations = TimezoneDataOperations(with: currentTimezone) - operations.saveObject(at: 0) - - // Retrieve Location - // retrieveLatestLocation() - } - @IBAction func ping(_ sender: Any) { togglePanel(sender) } diff --git a/Clocker/Onboarding/OnboardingParentViewController.swift b/Clocker/Onboarding/OnboardingParentViewController.swift index 105f269..73e557c 100644 --- a/Clocker/Onboarding/OnboardingParentViewController.swift +++ b/Clocker/Onboarding/OnboardingParentViewController.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit import StartupKit extension NSStoryboard.SceneIdentifier { @@ -178,7 +179,26 @@ class OnboardingParentViewController: NSViewController { } } + private func fetchLocalTimezone() { + let identifier = TimeZone.autoupdatingCurrent.identifier + + let currentTimezone = TimezoneData() + currentTimezone.timezoneID = identifier + currentTimezone.setLabel(identifier) + currentTimezone.formattedAddress = identifier + currentTimezone.isSystemTimezone = true + currentTimezone.placeID = "Home" + + let operations = TimezoneDataOperations(with: currentTimezone) + operations.saveObject(at: 0) + } + private func navigateToFinalStage() { + if UserDefaults.standard.object(forKey: CLInstallHomeIndicatorObject) == nil, DataStore.shared().timezones().isEmpty { + fetchLocalTimezone() + UserDefaults.standard.set(1, forKey: CLInstallHomeIndicatorObject) + } + guard let fromViewController = onboardingSearchVC, let toViewController = finalOnboardingVC else { assertionFailure() return From b9d6782c5336a54b38bf08725436d61c71ba9447 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 18:13:22 -0600 Subject: [PATCH 10/10] Type strict! --- .../Preferences/General/SearchDataSource.swift | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index ed8d6d9..28b37eb 100644 --- a/Clocker/Preferences/General/SearchDataSource.swift +++ b/Clocker/Preferences/General/SearchDataSource.swift @@ -29,7 +29,7 @@ class SearchDataSource: NSObject { "EST": ["florida", "new york"], "EDT": ["florida", "new york"]] - private var filteredArray: [Any] = [] + private var filteredArray: [TimezoneData] = [] private var timezoneArray: [TimezoneMetadata] = [] var timezoneFilteredArray: [TimezoneMetadata] = [] @@ -44,7 +44,7 @@ class SearchDataSource: NSObject { filteredArray = [] } - func setFilteredArrayValue(_ newArray: [Any]) { + func setFilteredArrayValue(_ newArray: [TimezoneData]) { filteredArray = newArray } @@ -53,12 +53,7 @@ class SearchDataSource: NSObject { } func retrieveFilteredResult(_ index: Int) -> TimezoneData? { - guard let dataObject = filteredArray[index % filteredArray.count] as? TimezoneData else { - assertionFailure("Data was unexpectedly nil") - return nil - } - - return dataObject + return filteredArray[index % filteredArray.count] } private func setupTimezoneDatasource() { @@ -204,11 +199,7 @@ extension SearchDataSource { private func cityCell(_ tableView: NSTableView, _: RowType, _ row: Int) -> NSView? { if let cityCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "resultCell"), owner: self) as? SearchResultTableViewCell { - guard let timezoneData = filteredArray[row % filteredArray.count] as? TimezoneData else { - assertionFailure() - return nil - } - + let timezoneData = filteredArray[row % filteredArray.count] cityCell.sourceName.stringValue = timezoneData.formattedAddress ?? "Error" return cityCell }