Browse Source

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

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
41d4aae708
  1. 8
      Clocker/AppDelegate.swift
  2. 12
      Clocker/ClockerUITests/CopyToClipboardTests.swift
  3. 13
      Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift
  4. 4
      Clocker/Onboarding/OnboardingSearchController.swift
  5. 2
      Clocker/Panel/FloatingWindowController.swift
  6. 8
      Clocker/Panel/PanelController.swift
  7. 19
      Clocker/Panel/ParentPanelController.swift
  8. 1
      Clocker/Preferences/About/AboutViewController.swift
  9. 134
      Clocker/Preferences/General/PreferencesViewController.swift

8
Clocker/AppDelegate.swift

@ -279,12 +279,8 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
} }
open func setupFloatingWindow() { open func setupFloatingWindow(_ hide: Bool) {
showFloatingWindow() hide ? floatingWindow.window?.close() : showFloatingWindow()
}
open func closeFloatingWindow() {
floatingWindow.window?.close()
} }
func statusItemForPanel() -> StatusItemHandler { func statusItemForPanel() -> StatusItemHandler {

12
Clocker/ClockerUITests/CopyToClipboardTests.swift

@ -35,19 +35,21 @@ class CopyToClipboardTests: XCTestCase {
// Test full copy // Test full copy
let cellCount = app.tables["FloatingTableView"].cells.count let cellCount = app.tables["FloatingTableView"].cells.count
var clipboardValue = String() var clipboardValue: [String] = []
for cellIndex in 0 ..< cellCount { for cellIndex in 0 ..< cellCount {
let cell = app.tables["FloatingTableView"].cells.element(boundBy: cellIndex) let cell = app.tables["FloatingTableView"].cells.element(boundBy: cellIndex)
let customLabel = cell.staticTexts["CustomNameLabelForCell"].value ?? "Nil Custom Label"
let time = cell.staticTexts["ActualTime"].value ?? "Nil Value" let time = cell.staticTexts["ActualTime"].value ?? "Nil Value"
clipboardValue.append(contentsOf: "\(customLabel) - \(time)\n") clipboardValue.append("\(time)")
} }
app.buttons["Share"].click() app.buttons["Share"].click()
app/*@START_MENU_TOKEN@*/ .menuItems["Copy All Times"]/*[[".dialogs[\"Clocker Panel\"]",".buttons[\"Share\"]",".menus.menuItems[\"Copy All Times\"]",".menuItems[\"Copy All Times\"]"],[[[-1,3],[-1,2],[-1,1,2],[-1,0,1]],[[-1,3],[-1,2],[-1,1,2]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/ .click() app/*@START_MENU_TOKEN@*/ .menuItems["Copy All Times"]/*[[".dialogs[\"Clocker Panel\"]",".buttons[\"Share\"]",".menus.menuItems[\"Copy All Times\"]",".menuItems[\"Copy All Times\"]"],[[[-1,3],[-1,2],[-1,1,2],[-1,0,1]],[[-1,3],[-1,2],[-1,1,2]],[[-1,3],[-1,2]]],[0]]@END_MENU_TOKEN@*/ .click()
let clipboard = NSPasteboard.general.string(forType: .string) if let clipboard = NSPasteboard.general.string(forType: .string) {
XCTAssert(clipboardValue == clipboard) for item in clipboardValue {
XCTAssertTrue(clipboard.contains(item))
}
}
} }
func testModernSlider() { func testModernSlider() {

13
Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift

@ -2,9 +2,16 @@
import Cocoa import Cocoa
public struct ResultStatus {
public static let okay = "OK"
public static let zeroResults = "ZERO_RESULTS"
public static let requestDenied = "REQUEST_DENIED"
}
public struct SearchResult: Codable { public struct SearchResult: Codable {
public let results: [Result] public let results: [Result]
public let status: String public let status: String
public let errorMessage: String?
public struct Result: Codable { public struct Result: Codable {
public let addressComponents: [AddressComponent] public let addressComponents: [AddressComponent]
@ -48,6 +55,12 @@ public struct SearchResult: Codable {
case types case types
} }
} }
private enum CodingKeys: String, CodingKey {
case results = "results"
case status = "status"
case errorMessage = "error_message"
}
} }
public struct Timezone: Codable { public struct Timezone: Codable {

4
Clocker/Onboarding/OnboardingSearchController.swift

@ -182,7 +182,7 @@ class OnboardingSearchController: NSViewController {
return true return true
} }
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" { if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders() setErrorPlaceholders()
return true return true
} }
@ -365,7 +365,7 @@ class OnboardingSearchController: NSViewController {
let searchResults = data.decode() let searchResults = data.decode()
if searchResults?.status == "ZERO_RESULTS" { if searchResults?.status == ResultStatus.zeroResults {
self.setInfoLabel("No results! 😔 Try entering the exact name.") self.setInfoLabel("No results! 😔 Try entering the exact name.")
setupForError() setupForError()
return return

2
Clocker/Panel/FloatingWindowController.swift

@ -49,7 +49,7 @@ class FloatingWindowController: ParentPanelController {
} }
override func showNotesPopover(forRow row: Int, relativeTo positioningRect: NSRect, andButton target: NSButton!) -> Bool { override func showNotesPopover(forRow row: Int, relativeTo positioningRect: NSRect, andButton target: NSButton!) -> Bool {
guard let popover = morePopover else { guard let popover = additionalOptionsPopover else {
return false return false
} }

8
Clocker/Panel/PanelController.swift

@ -302,7 +302,7 @@ class PanelController: ParentPanelController {
NSAnimationContext.beginGrouping() NSAnimationContext.beginGrouping()
NSAnimationContext.current.duration = 0.1 NSAnimationContext.current.duration = 0.1
window?.animator().alphaValue = 0 window?.animator().alphaValue = 0
morePopover?.close() additionalOptionsPopover?.close()
NSAnimationContext.endGrouping() NSAnimationContext.endGrouping()
window?.orderOut(nil) window?.orderOut(nil)
@ -329,11 +329,11 @@ class PanelController: ParentPanelController {
} }
override func showNotesPopover(forRow row: Int, relativeTo positioningRect: NSRect, andButton target: NSButton!) -> Bool { override func showNotesPopover(forRow row: Int, relativeTo positioningRect: NSRect, andButton target: NSButton!) -> Bool {
if morePopover == nil { if additionalOptionsPopover == nil {
morePopover = NSPopover() additionalOptionsPopover = NSPopover()
} }
guard let popover = morePopover else { guard let popover = additionalOptionsPopover else {
return false return false
} }

19
Clocker/Panel/ParentPanelController.swift

@ -33,7 +33,7 @@ class ParentPanelController: NSWindowController {
var previousPopoverRow: Int = -1 var previousPopoverRow: Int = -1
var morePopover: NSPopover? var additionalOptionsPopover: NSPopover?
var datasource: TimezoneDataSource? var datasource: TimezoneDataSource?
@ -366,7 +366,7 @@ class ParentPanelController: NSWindowController {
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
morePopover = NSPopover() additionalOptionsPopover = NSPopover()
} }
func screenHeight() -> CGFloat { func screenHeight() -> CGFloat {
@ -640,7 +640,7 @@ class ParentPanelController: NSWindowController {
func showNotesPopover(forRow row: Int, relativeTo _: NSRect, andButton target: NSButton!) -> Bool { func showNotesPopover(forRow row: Int, relativeTo _: NSRect, andButton target: NSButton!) -> Bool {
let defaults = DataStore.shared().timezones() let defaults = DataStore.shared().timezones()
guard let popover = morePopover else { guard let popover = additionalOptionsPopover else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
return false return false
} }
@ -773,9 +773,9 @@ class ParentPanelController: NSWindowController {
close() close()
if inverseSelection.isEqual(to: NSNumber(value: 1)) { if inverseSelection.isEqual(to: NSNumber(value: 1)) {
sharedDelegate.setupFloatingWindow() sharedDelegate.setupFloatingWindow(false)
} else { } else {
sharedDelegate.closeFloatingWindow() sharedDelegate.setupFloatingWindow(true)
sharedDelegate.setPanelDefaults() sharedDelegate.setPanelDefaults()
} }
@ -834,7 +834,7 @@ class ParentPanelController: NSWindowController {
if notePopover != nil, let isShown = notePopover?.popover?.isShown, isShown { if notePopover != nil, let isShown = notePopover?.popover?.isShown, isShown {
notePopover?.popover?.close() notePopover?.popover?.close()
} }
morePopover = nil additionalOptionsPopover = nil
} }
// MARK: Review // MARK: Review
@ -988,6 +988,12 @@ class ParentPanelController: NSWindowController {
NSWorkspace.shared.open(sourceURL) NSWorkspace.shared.open(sourceURL)
} }
@objc func openFAQs() {
guard let sourceURL = URL(string: AboutUsConstants.FAQsLink) else { return }
NSWorkspace.shared.open(sourceURL)
}
@IBAction func showMoreOptions(_ sender: NSButton) { @IBAction func showMoreOptions(_ sender: NSButton) {
let menuItem = NSMenu(title: "More Options") let menuItem = NSMenu(title: "More Options")
let terminateOption = NSMenuItem(title: "Quit Clocker", let terminateOption = NSMenuItem(title: "Quit Clocker",
@ -1010,6 +1016,7 @@ class ParentPanelController: NSWindowController {
clockerVersionInfo.isEnabled = false clockerVersionInfo.isEnabled = false
menuItem.addItem(openPreferences) menuItem.addItem(openPreferences)
menuItem.addItem(rateClocker) menuItem.addItem(rateClocker)
menuItem.addItem(withTitle: "FAQs", action: #selector(openFAQs), keyEquivalent: "")
menuItem.addItem(sendFeedback) menuItem.addItem(sendFeedback)
menuItem.addItem(localizeClocker) menuItem.addItem(localizeClocker)
menuItem.addItem(NSMenuItem.separator()) menuItem.addItem(NSMenuItem.separator())

1
Clocker/Preferences/About/AboutViewController.swift

@ -11,6 +11,7 @@ struct AboutUsConstants {
static let TwitterFollowIntentLink = "https://twitter.com/intent/follow?screen_name=clocker_support" static let TwitterFollowIntentLink = "https://twitter.com/intent/follow?screen_name=clocker_support"
static let AppStoreLink = "macappstore://itunes.apple.com/us/app/clocker/id1056643111?action=write-review" static let AppStoreLink = "macappstore://itunes.apple.com/us/app/clocker/id1056643111?action=write-review"
static let CrowdInLocalizationLink = "https://crwd.in/clocker" static let CrowdInLocalizationLink = "https://crwd.in/clocker"
static let FAQsLink = "https://abhishekbanthia.com/clocker/faq"
} }
class AboutViewController: ParentViewController { class AboutViewController: ParentViewController {

134
Clocker/Preferences/General/PreferencesViewController.swift

@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = "values.globalPing" static let hotKeyPathIdentifier = "values.globalPing"
} }
class TableHeaderViewCell: NSTableHeaderCell { class PreferencesViewController: ParentViewController {
var backgroundColour: NSColor = NSColor.black {
didSet {
backgroundColor = backgroundColour
}
}
override init(textCell: String) { @IBOutlet private var placeholderLabel: NSTextField!
super.init(textCell: textCell) @IBOutlet private var timezoneTableView: NSTableView!
let attributedParagraphStyle = NSMutableParagraphStyle() @IBOutlet private var availableTimezoneTableView: NSTableView!
attributedParagraphStyle.alignment = .left @IBOutlet private var timezonePanel: Panelr!
attributedStringValue = NSAttributedString(string: textCell, @IBOutlet private var progressIndicator: NSProgressIndicator!
attributes: [.foregroundColor: Themer.shared().mainTextColor(), @IBOutlet private var addButton: NSButton!
.font: NSFont(name: "Avenir", size: 14)!, @IBOutlet private var recorderControl: SRRecorderControl!
.paragraphStyle: attributedParagraphStyle]) @IBOutlet private var closeButton: NSButton!
backgroundColor = Themer.shared().textBackgroundColor()
}
required init(coder _: NSCoder) { @IBOutlet private var timezoneSortButton: NSButton!
fatalError("init(coder:) has not been implemented") @IBOutlet private var timezoneNameSortButton: NSButton!
} @IBOutlet private var labelSortButton: NSButton!
@IBOutlet private var deleteButton: NSButton!
@IBOutlet private var addTimezoneButton: NSButton!
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { @IBOutlet private var searchField: NSSearchField!
super.draw(withFrame: cellFrame, in: controlView) @IBOutlet private var messageLabel: NSTextField!
if !controlView.isHidden {
backgroundColor?.setFill()
cellFrame.fill()
drawInterior(withFrame: cellFrame, in: controlView)
}
}
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { @IBOutlet private var tableview: NSView!
if !controlView.isHidden { @IBOutlet private var additionalSortOptions: NSView!
if let avenirFont = NSFont(name: "Avenir", size: 14) { @IBOutlet var startAtLoginLabel: NSTextField!
font = avenirFont
} @IBOutlet var startupCheckbox: NSButton!
textColor = NSColor.white
let rect = titleRect(forBounds: cellFrame) // Sorting
attributedStringValue.draw(in: rect) private var arePlacesSortedInAscendingOrder = false
} private var arePlacesSortedInAscendingTimezoneOrder = false
} private var isTimezoneSortOptionSelected = false
} private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
class PreferencesViewController: ParentViewController {
private var isActivityInProgress = false { private var isActivityInProgress = false {
didSet { didSet {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
return DataStore.shared().timezones() return DataStore.shared().timezones()
} }
private var themeDidChangeNotification: NSObjectProtocol?
// Selected Timezones Data Source
private var selectionsDataSource: PreferencesDataSource!
// Search Results Data Source Handler
private var searchResultsDataSource: SearchDataSource!
private lazy var startupManager = StartupManager() private lazy var startupManager = StartupManager()
private var dataTask: URLSessionDataTask? = .none private var dataTask: URLSessionDataTask? = .none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
return apiKey return apiKey
}() }()
// Sorting
private var arePlacesSortedInAscendingOrder = false
private var arePlacesSortedInAscendingTimezoneOrder = false
private var isTimezoneSortOptionSelected = false
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
@IBOutlet private var placeholderLabel: NSTextField!
@IBOutlet private var timezoneTableView: NSTableView!
@IBOutlet private var availableTimezoneTableView: NSTableView!
@IBOutlet private var timezonePanel: Panelr!
@IBOutlet private var progressIndicator: NSProgressIndicator!
@IBOutlet private var addButton: NSButton!
@IBOutlet private var recorderControl: SRRecorderControl!
@IBOutlet private var closeButton: NSButton!
@IBOutlet private var timezoneSortButton: NSButton!
@IBOutlet private var timezoneNameSortButton: NSButton!
@IBOutlet private var labelSortButton: NSButton!
@IBOutlet private var deleteButton: NSButton!
@IBOutlet private var addTimezoneButton: NSButton!
@IBOutlet private var searchField: NSSearchField!
@IBOutlet private var messageLabel: NSTextField!
@IBOutlet private var tableview: NSView!
@IBOutlet private var additionalSortOptions: NSView!
@IBOutlet var startAtLoginLabel: NSTextField!
@IBOutlet var startupCheckbox: NSButton!
private var themeDidChangeNotification: NSObjectProtocol?
// Selected Timezones Data Source
private var selectionsDataSource: PreferencesDataSource!
// Search Results Data Source Handler
private var searchResultsDataSource: SearchDataSource!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -481,22 +439,30 @@ extension PreferencesViewController {
return return
} }
guard let data = response else { guard let data = response, let searchResults = data.decode() else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
return return
} }
let searchResults = data.decode() // let searchResults = data.decode()
if searchResults?.status == "ZERO_RESULTS" { if searchResults.status == ResultStatus.zeroResults {
Logger.info("Zero Results returned")
self.findLocalSearchResultsForTimezones() self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : CLEmptyString self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : CLEmptyString
self.reloadSearchResults() self.reloadSearchResults()
self.isActivityInProgress = false self.isActivityInProgress = false
return return
} else if searchResults.status == ResultStatus.requestDenied && searchResults.results.isEmpty {
Logger.info("Request denied!")
self.findLocalSearchResultsForTimezones()
self.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "Update Clocker to get a faster experience 😃" : CLEmptyString
self.reloadSearchResults()
self.isActivityInProgress = false
return
} }
self.appendResultsToFilteredArray(searchResults!.results) self.appendResultsToFilteredArray(searchResults.results)
self.findLocalSearchResultsForTimezones() self.findLocalSearchResultsForTimezones()
self.prepareUIForPresentingResults() self.prepareUIForPresentingResults()
} }
@ -522,12 +488,7 @@ extension PreferencesViewController {
} }
private func presentError(_ errorMessage: String) { private func presentError(_ errorMessage: String) {
if errorMessage == PreferencesConstants.offlineErrorMessage { placeholderLabel.placeholderString = errorMessage == PreferencesConstants.offlineErrorMessage ? PreferencesConstants.noInternetConnectivityError : PreferencesConstants.tryAgainMessage
placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
} else {
placeholderLabel.placeholderString = PreferencesConstants.tryAgainMessage
}
isActivityInProgress = false isActivityInProgress = false
} }
@ -642,7 +603,6 @@ extension PreferencesViewController {
// Mark if the timezone is same as local timezone // Mark if the timezone is same as local timezone
let timezoneObject = TimezoneData(with: newTimeZone) let timezoneObject = TimezoneData(with: newTimeZone)
timezoneObject.isSystemTimezone = timezoneObject.timezone() == NSTimeZone.system.identifier
let operationsObject = TimezoneDataOperations(with: timezoneObject) let operationsObject = TimezoneDataOperations(with: timezoneObject)
operationsObject.saveObject() operationsObject.saveObject()
@ -670,7 +630,7 @@ extension PreferencesViewController {
return false return false
} }
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" { if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders() setErrorPlaceholders()
return true return true
} }

Loading…
Cancel
Save