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
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)
}

4
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" = "選單列模式";

4
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?

3
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)
{

20
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

26
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

33
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
}

Loading…
Cancel
Save