Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/92/head
Abhishek 4 years ago
parent
commit
23fd562716
  1. 26
      Clocker/AppDelegate.swift
  2. 4
      Clocker/Clocker/zh-Hant.lproj/Localizable.strings
  3. 4
      Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift
  4. 3
      Clocker/Dependencies/iVersion/iVersion.m
  5. 20
      Clocker/Onboarding/OnboardingParentViewController.swift
  6. 26
      Clocker/Preferences/General/PreferencesViewController.swift
  7. 33
      Clocker/Preferences/General/SearchDataSource.swift

26
Clocker/AppDelegate.swift

@ -49,11 +49,11 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
// Required for migrating our model type to CoreModelKit // Required for migrating our model type to CoreModelKit
NSKeyedUnarchiver.setClass(CoreModelKit.TimezoneData.classForKeyedUnarchiver(), forClassName: "Clocker.TimezoneData") 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 // For users, still on the old timezones, only migrate timezonezes once setClass has been called
migrateOverridenTimezones() migrateOverridenTimezones()
AppDefaults.initialize()
// Check if we can show the onboarding flow! // Check if we can show the onboarding flow!
showOnboardingFlowIfEligible() showOnboardingFlowIfEligible()
@ -139,11 +139,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
// Install the menubar item! // Install the menubar item!
statusBarHandler = StatusItemHandler() statusBarHandler = StatusItemHandler()
if UserDefaults.standard.object(forKey: CLInstallHomeIndicatorObject) == nil {
fetchLocalTimezone()
UserDefaults.standard.set(1, forKey: CLInstallHomeIndicatorObject)
}
if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) { if ProcessInfo.processInfo.arguments.contains(CLUITestingLaunchArgument) {
RateController.setPreviewMode(true) RateController.setPreviewMode(true)
} }
@ -210,23 +205,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
alert.runModal() 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) { @IBAction func ping(_ sender: Any) {
togglePanel(sender) togglePanel(sender)
} }

4
Clocker/Clocker/zh-Hant.lproj/Localizable.strings

@ -108,8 +108,8 @@
"Display the time in seconds" = "顯示時間秒數"; "Display the time in seconds" = "顯示時間秒數";
"Larger Text" = "較大文字"; "Larger Text" = "較大文字";
"Future Slider Range" = "未來滑桿範圍"; "Future Slider Range" = "未來滑桿範圍";
"Include Date" = "包含期"; "Include Date" = "包含期";
"Include Day" = "包含期"; "Include Day" = "包含期";
"Include Place Name" = "包含位置名稱"; "Include Place Name" = "包含位置名稱";
"Menubar Display Options" = "選單列顯示選項"; "Menubar Display Options" = "選單列顯示選項";
"Menubar Mode" = "選單列模式"; "Menubar Mode" = "選單列模式";

4
Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

@ -59,8 +59,8 @@ public class TimezoneData: NSObject, NSCoding {
NSNumber(integerLiteral: 7): DateFormat.twelveHourWithZeroSeconds, NSNumber(integerLiteral: 7): DateFormat.twelveHourWithZeroSeconds,
// Suffix // Suffix
NSNumber(integerLiteral: 8): DateFormat.twelveHourWithoutSuffix, NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffix,
NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffixAndSeconds, NSNumber(integerLiteral: 10): DateFormat.twelveHourWithoutSuffixAndSeconds,
] ]
public var customLabel: String? public var customLabel: String?

3
Clocker/Dependencies/iVersion/iVersion.m

@ -147,7 +147,7 @@ static NSString *mostRecentVersionInDict(NSDictionary *dictionary)
bundle = [NSBundle bundleWithPath:bundlePath] ?: [NSBundle mainBundle]; bundle = [NSBundle bundleWithPath:bundlePath] ?: [NSBundle mainBundle];
} }
defaultString = [bundle localizedStringForKey:key value:defaultString table:nil]; 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 - (iVersion *)init
@ -820,6 +820,7 @@ static NSString *mostRecentVersionInDict(NSDictionary *dictionary)
{ {
//clear reminder //clear reminder
self.lastReminded = nil; self.lastReminded = nil;
[self openAppPageInAppStore];
} }
else if (buttonIndex == ignoreButtonIndex) else if (buttonIndex == ignoreButtonIndex)
{ {

20
Clocker/Onboarding/OnboardingParentViewController.swift

@ -2,6 +2,7 @@
import Cocoa import Cocoa
import CoreLoggerKit import CoreLoggerKit
import CoreModelKit
import StartupKit import StartupKit
extension NSStoryboard.SceneIdentifier { 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() { 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 { guard let fromViewController = onboardingSearchVC, let toViewController = finalOnboardingVC else {
assertionFailure() assertionFailure()
return return

26
Clocker/Preferences/General/PreferencesViewController.swift

@ -412,15 +412,7 @@ extension PreferencesViewController {
} }
self.placeholderLabel.isHidden = false self.placeholderLabel.isHidden = false
/*
if NetworkManager.isConnected() == false {
self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
return
}*/
self.isActivityInProgress = true self.isActivityInProgress = true
self.placeholderLabel.placeholderString = "Searching for \(searchString)" self.placeholderLabel.placeholderString = "Searching for \(searchString)"
Logger.info(self.placeholderLabel.placeholderString ?? "") Logger.info(self.placeholderLabel.placeholderString ?? "")
@ -466,16 +458,8 @@ extension PreferencesViewController {
} }
private func findLocalSearchResultsForTimezones() { private func findLocalSearchResultsForTimezones() {
searchResultsDataSource.timezoneFilteredArray = []
let lowercasedSearchString = searchField.stringValue.lowercased() let lowercasedSearchString = searchField.stringValue.lowercased()
searchResultsDataSource.searchTimezones(lowercasedSearchString)
searchResultsDataSource.timezoneFilteredArray = searchResultsDataSource.timezoneArray.filter { (timezoneMetadata) -> Bool in
let tags = timezoneMetadata.tags
for tag in tags where tag.contains(lowercasedSearchString) {
return true
}
return false
}
Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription) Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription)
} }
@ -613,7 +597,7 @@ extension PreferencesViewController {
} }
private func installTimezone(_ timezone: Timezone) { 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") assertionFailure("Data was unexpectedly nil")
return return
} }
@ -763,7 +747,7 @@ extension PreferencesViewController {
} }
private func cleanupAfterInstallingCity() { 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") assertionFailure("Data was unexpectedly nil")
return return
} }
@ -784,8 +768,8 @@ extension PreferencesViewController {
let data = TimezoneData() let data = TimezoneData()
data.setLabel(CLEmptyString) data.setLabel(CLEmptyString)
let currentSelection = searchField.stringValue.isEmpty == false ? searchResultsDataSource.timezoneFilteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.timezoneFilteredArray.count] : let currentSelection = searchResultsDataSource.retrieveSelectedTimezone(searchField.stringValue,
searchResultsDataSource.timezoneArray[availableTimezoneTableView.selectedRow - 1] availableTimezoneTableView.selectedRow)
let metaInfo = metadata(for: currentSelection) let metaInfo = metadata(for: currentSelection)
data.timezoneID = metaInfo.0.name data.timezoneID = metaInfo.0.name

33
Clocker/Preferences/General/SearchDataSource.swift

@ -29,8 +29,8 @@ class SearchDataSource: NSObject {
"EST": ["florida", "new york"], "EST": ["florida", "new york"],
"EDT": ["florida", "new york"]] "EDT": ["florida", "new york"]]
var filteredArray: [Any] = [] private var filteredArray: [TimezoneData] = []
var timezoneArray: [TimezoneMetadata] = [] private var timezoneArray: [TimezoneMetadata] = []
var timezoneFilteredArray: [TimezoneMetadata] = [] var timezoneFilteredArray: [TimezoneMetadata] = []
init(with searchField: NSSearchField) { init(with searchField: NSSearchField) {
@ -44,7 +44,7 @@ class SearchDataSource: NSObject {
filteredArray = [] filteredArray = []
} }
func setFilteredArrayValue(_ newArray: [Any]) { func setFilteredArrayValue(_ newArray: [TimezoneData]) {
filteredArray = newArray filteredArray = newArray
} }
@ -52,6 +52,10 @@ class SearchDataSource: NSObject {
return finalArray[row] return finalArray[row]
} }
func retrieveFilteredResult(_ index: Int) -> TimezoneData? {
return filteredArray[index % filteredArray.count]
}
private func setupTimezoneDatasource() { private func setupTimezoneDatasource() {
timezoneArray = [] timezoneArray = []
@ -123,6 +127,23 @@ class SearchDataSource: NSObject {
return false 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 { extension SearchDataSource: NSTableViewDataSource {
@ -178,11 +199,7 @@ extension SearchDataSource {
private func cityCell(_ tableView: NSTableView, _: RowType, _ row: Int) -> NSView? { private func cityCell(_ tableView: NSTableView, _: RowType, _ row: Int) -> NSView? {
if let cityCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "resultCell"), owner: self) as? SearchResultTableViewCell { if let cityCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "resultCell"), owner: self) as? SearchResultTableViewCell {
guard let timezoneData = filteredArray[row % filteredArray.count] as? TimezoneData else { let timezoneData = filteredArray[row % filteredArray.count]
assertionFailure()
return nil
}
cityCell.sourceName.stringValue = timezoneData.formattedAddress ?? "Error" cityCell.sourceName.stringValue = timezoneData.formattedAddress ?? "Error"
return cityCell return cityCell
} }

Loading…
Cancel
Save