From 4e67028b78327c31eb28ec02fa4a96b5c41c55d7 Mon Sep 17 00:00:00 2001
From: Abhishek
Date: Tue, 15 Feb 2022 19:50:33 -0500
Subject: [PATCH 01/10] Quick updates.
---
Clocker/Overall App/Themer.swift | 6 +++++-
Clocker/Preferences/General/PreferencesViewController.swift | 4 ++--
Clocker/Preferences/Menu Bar/StatusItemHandler.swift | 2 +-
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Clocker/Overall App/Themer.swift b/Clocker/Overall App/Themer.swift
index e28bb1c..81e8def 100644
--- a/Clocker/Overall App/Themer.swift
+++ b/Clocker/Overall App/Themer.swift
@@ -191,7 +191,7 @@ extension Themer {
}
func preferenceImage() -> NSImage {
- if let symbolImageForPreference = symbolImage(for: "gear") {
+ if let symbolImageForPreference = symbolImage(for: "plus") {
return symbolImageForPreference
}
@@ -389,6 +389,10 @@ extension Themer {
}
func addImage() -> NSImage {
+ if let symbolImageForPreference = symbolImage(for: "plus") {
+ return symbolImageForPreference
+ }
+
if #available(macOS 10.14, *) {
switch themeIndex {
case .light, .solarizedLight:
diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift
index e3a7137..4656fb5 100644
--- a/Clocker/Preferences/General/PreferencesViewController.swift
+++ b/Clocker/Preferences/General/PreferencesViewController.swift
@@ -172,8 +172,8 @@ class PreferencesViewController: ParentViewController {
private func darkModeChanges() {
if #available(macOS 10.14, *) {
- addTimezoneButton.image = NSImage(named: .addDynamicIcon)
- deleteButton.image = NSImage(named: NSImage.Name("Remove Dynamic"))!
+ addTimezoneButton.image = Themer.shared().addImage()
+ deleteButton.image = Themer.shared().removeImage()
}
}
diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift
index e44f657..ca9dbf8 100644
--- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift
+++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift
@@ -123,7 +123,7 @@ class StatusItemHandler: NSObject {
self.menubarTimer?.invalidate()
}
- NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: OperationQueue.main) { notification in
+ NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: OperationQueue.main) { notification in
self.setupStatusItem()
}
}
From f65b1ea6c1a37551325fa246aab72acd3b8ddaa3 Mon Sep 17 00:00:00 2001
From: Abhishek
Date: Tue, 15 Feb 2022 20:07:14 -0500
Subject: [PATCH 02/10] Remove shared()
---
.../AppFeedbackWindowController.swift | 11 ++--
Clocker/Preferences/OneWindowController.swift | 9 +---
Clocker/Preferences/Preferences.storyboard | 52 +++++++++----------
3 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
index a32b23a..ea12d94 100644
--- a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
+++ b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
@@ -309,8 +309,13 @@ extension AppFeedbackWindowController: NSWindowDelegate {
}
func bringPreferencesWindowToFront() {
- let oneWindowController = OneWindowController.shared()
- oneWindowController.window?.makeKeyAndOrderFront(self)
- NSApp.activate(ignoringOtherApps: true)
+ let windows = NSApplication.shared.windows
+ let prefWindow = windows.first(where: { window in
+ return window.identifier == NSUserInterfaceItemIdentifier("Preferences")
+ })
+ if let prefW = prefWindow {
+ prefW.makeKeyAndOrderFront(self)
+ NSApp.activate(ignoringOtherApps: true)
+ }
}
}
diff --git a/Clocker/Preferences/OneWindowController.swift b/Clocker/Preferences/OneWindowController.swift
index bed5c59..b778943 100644
--- a/Clocker/Preferences/OneWindowController.swift
+++ b/Clocker/Preferences/OneWindowController.swift
@@ -49,14 +49,7 @@ class OneWindowController: NSWindowController {
private func setupWindow() {
window?.titlebarAppearsTransparent = true
window?.backgroundColor = Themer.shared().mainBackgroundColor()
- }
-
- class func shared() -> OneWindowController {
- if sharedWindow == nil {
- let prefStoryboard = NSStoryboard(name: "Preferences", bundle: nil)
- sharedWindow = prefStoryboard.instantiateInitialController() as? OneWindowController
- }
- return sharedWindow
+ window?.identifier = NSUserInterfaceItemIdentifier("Preferences")
}
func openPermissions() {
diff --git a/Clocker/Preferences/Preferences.storyboard b/Clocker/Preferences/Preferences.storyboard
index 3031c19..49a3e55 100644
--- a/Clocker/Preferences/Preferences.storyboard
+++ b/Clocker/Preferences/Preferences.storyboard
@@ -801,7 +801,7 @@
-
+
@@ -814,7 +814,7 @@
-
+
@@ -834,7 +834,7 @@
-
+
@@ -844,7 +844,7 @@
-
+
@@ -865,7 +865,7 @@
-
+
@@ -878,7 +878,7 @@
-
+
@@ -896,7 +896,7 @@
-
+
@@ -909,7 +909,7 @@
-
+
@@ -925,7 +925,7 @@
-
+
@@ -938,7 +938,7 @@
-
+
@@ -954,7 +954,7 @@
-
+
@@ -967,7 +967,7 @@
-
+
@@ -979,11 +979,11 @@
-
+
-
+
@@ -1512,7 +1512,7 @@
-
+
@@ -1569,13 +1569,13 @@ DQ
-
+
-
+
-
+
@@ -1665,14 +1665,14 @@ DQ
-
+
-
+
@@ -1860,14 +1860,14 @@ DQ
-[![Twitter: @clocker_support](https://img.shields.io/badge/contact-@clocker_support-blue.svg?style=flat)](https://twitter.com/clocker_support) [![Crowdin](https://badges.crowdin.net/clocker/localized.svg)](https://crowdin.com/project/clocker)
**Clocker** is an macOS menubar utility designed to help you keep track of your friends in different time zones. It's written using ~~Objective-C~~ Swift 5 and is completely ad-free. If you'd like to help translate Clocker in your language, [here's the invite link](https://crwd.in/clocker).
@@ -23,10 +22,6 @@ If you'd like to donate, you can do so [here](https://www.paypal.me/AbhishekBant
brew install --cask clocker
```
-or
-
-[![Download on the App Store](https://github.com/n0shake/Clocker/blob/v1.2.1/Clocker/Images/MacAppStore.png)](https://itunes.apple.com/us/app/clocker-menubar-world-clock/id1056643111?mt=12)
-
# Contributing
**Clocker** is open for pull requests.
From bde5f1f86b98e0b502b29bc5e7375ca3edb6fea3 Mon Sep 17 00:00:00 2001
From: Abhishek
Date: Sat, 5 Mar 2022 15:33:09 -0500
Subject: [PATCH 09/10] Handle Request Denied case.
---
.../Sources/CoreModelKit/SearchResults.swift | 15 ++++++++++++++-
.../Onboarding/OnboardingSearchController.swift | 4 ++--
.../General/PreferencesViewController.swift | 16 +++++++++++-----
3 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift b/Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift
index 77ce6bc..64341d1 100644
--- a/Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift
+++ b/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 {
diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift
index e9b40a1..6ea7a72 100644
--- a/Clocker/Onboarding/OnboardingSearchController.swift
+++ b/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
diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift
index 4656fb5..ec44813 100644
--- a/Clocker/Preferences/General/PreferencesViewController.swift
+++ b/Clocker/Preferences/General/PreferencesViewController.swift
@@ -481,22 +481,28 @@ 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 {
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 {
+ 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()
}
@@ -670,7 +676,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
}
From bae747283b4fe23be69a81bdefcd0a46b017a64f Mon Sep 17 00:00:00 2001
From: Abhishek
Date: Sat, 5 Mar 2022 15:35:52 -0500
Subject: [PATCH 10/10] Update PreferencesViewController.swift
---
Clocker/Preferences/General/PreferencesViewController.swift | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift
index ec44813..8483332 100644
--- a/Clocker/Preferences/General/PreferencesViewController.swift
+++ b/Clocker/Preferences/General/PreferencesViewController.swift
@@ -489,12 +489,14 @@ extension PreferencesViewController {
// let searchResults = data.decode()
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()