diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 8ce9819..5a850ae 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() @@ -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/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/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? diff --git a/Clocker/Dependencies/iVersion/iVersion.m b/Clocker/Dependencies/iVersion/iVersion.m index 28814f7..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 @@ -820,6 +820,7 @@ static NSString *mostRecentVersionInDict(NSDictionary *dictionary) { //clear reminder self.lastReminded = nil; + [self openAppPageInAppStore]; } else if (buttonIndex == ignoreButtonIndex) { 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 diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index e8dd92e..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 ?? "") @@ -466,16 +458,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 +597,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 +747,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 +768,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 diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index 52bf17a..28b37eb 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: [TimezoneData] = [] + private var timezoneArray: [TimezoneMetadata] = [] var timezoneFilteredArray: [TimezoneMetadata] = [] init(with searchField: NSSearchField) { @@ -44,7 +44,7 @@ class SearchDataSource: NSObject { filteredArray = [] } - func setFilteredArrayValue(_ newArray: [Any]) { + func setFilteredArrayValue(_ newArray: [TimezoneData]) { filteredArray = newArray } @@ -52,6 +52,10 @@ class SearchDataSource: NSObject { return finalArray[row] } + func retrieveFilteredResult(_ index: Int) -> TimezoneData? { + return filteredArray[index % filteredArray.count] + } + private func setupTimezoneDatasource() { timezoneArray = [] @@ -123,6 +127,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 { @@ -178,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 }