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. 15
      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)
}
open func setupFloatingWindow() {
showFloatingWindow()
}
open func closeFloatingWindow() {
floatingWindow.window?.close()
open func setupFloatingWindow(_ hide: Bool) {
hide ? floatingWindow.window?.close() : showFloatingWindow()
}
func statusItemForPanel() -> StatusItemHandler {

12
Clocker/ClockerUITests/CopyToClipboardTests.swift

@ -35,19 +35,21 @@ class CopyToClipboardTests: XCTestCase {
// Test full copy
let cellCount = app.tables["FloatingTableView"].cells.count
var clipboardValue = String()
var clipboardValue: [String] = []
for cellIndex in 0 ..< cellCount {
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"
clipboardValue.append(contentsOf: "\(customLabel) - \(time)\n")
clipboardValue.append("\(time)")
}
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()
let clipboard = NSPasteboard.general.string(forType: .string)
XCTAssert(clipboardValue == clipboard)
if let clipboard = NSPasteboard.general.string(forType: .string) {
for item in clipboardValue {
XCTAssertTrue(clipboard.contains(item))
}
}
}
func testModernSlider() {

15
Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift

@ -2,10 +2,17 @@
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 let results: [Result]
public let status: String
public let errorMessage: String?
public struct Result: Codable {
public let addressComponents: [AddressComponent]
public let formattedAddress: String
@ -48,6 +55,12 @@ public struct SearchResult: Codable {
case types
}
}
private enum CodingKeys: String, CodingKey {
case results = "results"
case status = "status"
case errorMessage = "error_message"
}
}
public struct Timezone: Codable {

4
Clocker/Onboarding/OnboardingSearchController.swift

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

8
Clocker/Panel/PanelController.swift

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

19
Clocker/Panel/ParentPanelController.swift

@ -33,7 +33,7 @@ class ParentPanelController: NSWindowController {
var previousPopoverRow: Int = -1
var morePopover: NSPopover?
var additionalOptionsPopover: NSPopover?
var datasource: TimezoneDataSource?
@ -366,7 +366,7 @@ class ParentPanelController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
morePopover = NSPopover()
additionalOptionsPopover = NSPopover()
}
func screenHeight() -> CGFloat {
@ -640,7 +640,7 @@ class ParentPanelController: NSWindowController {
func showNotesPopover(forRow row: Int, relativeTo _: NSRect, andButton target: NSButton!) -> Bool {
let defaults = DataStore.shared().timezones()
guard let popover = morePopover else {
guard let popover = additionalOptionsPopover else {
assertionFailure("Data was unexpectedly nil")
return false
}
@ -773,9 +773,9 @@ class ParentPanelController: NSWindowController {
close()
if inverseSelection.isEqual(to: NSNumber(value: 1)) {
sharedDelegate.setupFloatingWindow()
sharedDelegate.setupFloatingWindow(false)
} else {
sharedDelegate.closeFloatingWindow()
sharedDelegate.setupFloatingWindow(true)
sharedDelegate.setPanelDefaults()
}
@ -834,7 +834,7 @@ class ParentPanelController: NSWindowController {
if notePopover != nil, let isShown = notePopover?.popover?.isShown, isShown {
notePopover?.popover?.close()
}
morePopover = nil
additionalOptionsPopover = nil
}
// MARK: Review
@ -987,6 +987,12 @@ class ParentPanelController: NSWindowController {
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) {
let menuItem = NSMenu(title: "More Options")
@ -1010,6 +1016,7 @@ class ParentPanelController: NSWindowController {
clockerVersionInfo.isEnabled = false
menuItem.addItem(openPreferences)
menuItem.addItem(rateClocker)
menuItem.addItem(withTitle: "FAQs", action: #selector(openFAQs), keyEquivalent: "")
menuItem.addItem(sendFeedback)
menuItem.addItem(localizeClocker)
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 AppStoreLink = "macappstore://itunes.apple.com/us/app/clocker/id1056643111?action=write-review"
static let CrowdInLocalizationLink = "https://crwd.in/clocker"
static let FAQsLink = "https://abhishekbanthia.com/clocker/faq"
}
class AboutViewController: ParentViewController {

134
Clocker/Preferences/General/PreferencesViewController.swift

@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = "values.globalPing"
}
class TableHeaderViewCell: NSTableHeaderCell {
var backgroundColour: NSColor = NSColor.black {
didSet {
backgroundColor = backgroundColour
}
}
class PreferencesViewController: ParentViewController {
override init(textCell: String) {
super.init(textCell: textCell)
let attributedParagraphStyle = NSMutableParagraphStyle()
attributedParagraphStyle.alignment = .left
attributedStringValue = NSAttributedString(string: textCell,
attributes: [.foregroundColor: Themer.shared().mainTextColor(),
.font: NSFont(name: "Avenir", size: 14)!,
.paragraphStyle: attributedParagraphStyle])
backgroundColor = Themer.shared().textBackgroundColor()
}
@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!
required init(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@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!
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) {
super.draw(withFrame: cellFrame, in: controlView)
if !controlView.isHidden {
backgroundColor?.setFill()
cellFrame.fill()
drawInterior(withFrame: cellFrame, in: controlView)
}
}
@IBOutlet private var searchField: NSSearchField!
@IBOutlet private var messageLabel: NSTextField!
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
if !controlView.isHidden {
if let avenirFont = NSFont(name: "Avenir", size: 14) {
font = avenirFont
}
textColor = NSColor.white
let rect = titleRect(forBounds: cellFrame)
attributedStringValue.draw(in: rect)
}
}
}
@IBOutlet private var tableview: NSView!
@IBOutlet private var additionalSortOptions: NSView!
@IBOutlet var startAtLoginLabel: NSTextField!
class PreferencesViewController: ParentViewController {
@IBOutlet var startupCheckbox: NSButton!
// Sorting
private var arePlacesSortedInAscendingOrder = false
private var arePlacesSortedInAscendingTimezoneOrder = false
private var isTimezoneSortOptionSelected = false
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
private var isActivityInProgress = false {
didSet {
OperationQueue.main.addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
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 var dataTask: URLSessionDataTask? = .none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
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() {
super.viewDidLoad()
@ -481,22 +439,30 @@ extension PreferencesViewController {
return
}
guard let data = response else {
guard let data = response, let searchResults = data.decode() else {
assertionFailure("Data was unexpectedly nil")
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.placeholderLabel.placeholderString = self.searchResultsDataSource.timezoneFilteredArray.isEmpty ? "No results! 😔 Try entering the exact name." : CLEmptyString
self.reloadSearchResults()
self.isActivityInProgress = false
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.prepareUIForPresentingResults()
}
@ -522,12 +488,7 @@ extension PreferencesViewController {
}
private func presentError(_ errorMessage: String) {
if errorMessage == PreferencesConstants.offlineErrorMessage {
placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
} else {
placeholderLabel.placeholderString = PreferencesConstants.tryAgainMessage
}
placeholderLabel.placeholderString = errorMessage == PreferencesConstants.offlineErrorMessage ? PreferencesConstants.noInternetConnectivityError : PreferencesConstants.tryAgainMessage
isActivityInProgress = false
}
@ -642,7 +603,6 @@ extension PreferencesViewController {
// Mark if the timezone is same as local timezone
let timezoneObject = TimezoneData(with: newTimeZone)
timezoneObject.isSystemTimezone = timezoneObject.timezone() == NSTimeZone.system.identifier
let operationsObject = TimezoneDataOperations(with: timezoneObject)
operationsObject.saveObject()
@ -670,7 +630,7 @@ extension PreferencesViewController {
return false
}
if let status = unwrapped["status"] as? String, status == "ZERO_RESULTS" {
if let status = unwrapped["status"] as? String, status == ResultStatus.zeroResults {
setErrorPlaceholders()
return true
}

Loading…
Cancel
Save