You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
6.3 KiB

// Copyright © 2015 Abhishek Banthia
import Cocoa
import CoreLoggerKit
struct AboutUsConstants {
static let AboutUsNibIdentifier = "CLAboutWindows"
static let GitHubURL = "https://github.com/abhishekbanthia/Clocker/?ref=ClockerApp"
static let PayPalURL = "https://paypal.me/abhishekbanthia1712"
static let TwitterLink = "https://twitter.com/clocker_support/?ref=ClockerApp"
static let PersonalWebsite = "http://abhishekbanthia.com/?ref=ClockerApp"
static let AppStoreLink = "macappstore://itunes.apple.com/us/app/clocker/id1056643111?action=write-review"
static let CrowdInLocalizationLink = "https://crwd.in/clocker"
}
class AboutViewController: ParentViewController {
@IBOutlet var quickCommentAction: UnderlinedButton!
@IBOutlet var privateFeedback: UnderlinedButton!
@IBOutlet var supportClocker: UnderlinedButton!
@IBOutlet var openSourceButton: UnderlinedButton!
@IBOutlet var versionField: NSTextField!
6 years ago
private var themeDidChangeNotification: NSObjectProtocol?
private lazy var feedbackWindow = AppFeedbackWindowController.shared()
override func viewDidLoad() {
super.viewDidLoad()
privateFeedback.setAccessibilityIdentifier("ClockerPrivateFeedback")
let appDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") ?? "Clocker"
let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") ?? "N/A"
let longVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") ?? "N/A"
versionField.stringValue = "\(appDisplayName) \(shortVersion) (\(longVersion))"
6 years ago
setup()
6 years ago
6 years ago
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
self.setup()
}
}
6 years ago
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func underlineTextForActionButton() {
let rangesInOrder = [NSRange(location: 3, length: 8),
6 years ago
NSRange(location: 7, length: privateFeedback.attributedTitle.length - 7),
NSRange(location: 27, length: 33),
NSRange(location: 42, length: 14)]
let buttonsInOrder = [quickCommentAction,
6 years ago
privateFeedback,
supportClocker,
openSourceButton]
6 years ago
let localizedKeys = ["1. @n0shake on Twitter for quick comments",
"2. For Private Feedback",
"You can support Clocker by leaving a review on the App Store! :)",
"Help localize Clocker in your language by clicking here!"]
6 years ago
zip(buttonsInOrder, localizedKeys).forEach { arg in
let (button, title) = arg
button?.title = title
}
zip(rangesInOrder, buttonsInOrder).forEach { arg in
let (range, button) = arg
setUnderline(for: button, range: range)
}
}
private func setUnderline(for button: UnderlinedButton?, range: NSRange) {
guard let underlinedButton = button else { return }
6 years ago
let mutableParaghStyle = NSMutableParagraphStyle()
mutableParaghStyle.alignment = .center
let originalText = NSMutableAttributedString(string: underlinedButton.title)
originalText.addAttribute(NSAttributedString.Key.underlineStyle,
value: NSNumber(value: Int8(NSUnderlineStyle.single.rawValue)),
range: range)
originalText.addAttribute(NSAttributedString.Key.foregroundColor,
value: Themer.shared().mainTextColor(),
6 years ago
range: NSRange(location: 0, length: underlinedButton.attributedTitle.string.count))
originalText.addAttribute(NSAttributedString.Key.font,
6 years ago
value: (button?.font)!,
6 years ago
range: NSRange(location: 0, length: underlinedButton.attributedTitle.string.count))
originalText.addAttribute(NSAttributedString.Key.paragraphStyle,
6 years ago
value: mutableParaghStyle,
6 years ago
range: NSRange(location: 0, length: underlinedButton.attributedTitle.string.count))
underlinedButton.attributedTitle = originalText
}
@IBAction func openMyTwitter(_: Any) {
guard let twitterURL = URL(string: AboutUsConstants.TwitterLink),
let countryCode = Locale.autoupdatingCurrent.regionCode else { return }
NSWorkspace.shared.open(twitterURL)
// Log this
let custom: [String: Any] = ["Country": countryCode]
Logger.log(object: custom, for: "Opened Twitter")
}
@IBAction func viewSource(_: Any) {
guard let sourceURL = URL(string: AboutUsConstants.AppStoreLink),
let countryCode = Locale.autoupdatingCurrent.regionCode else { return }
NSWorkspace.shared.open(sourceURL)
// Log this
let custom: [String: Any] = ["Country": countryCode]
Logger.log(object: custom, for: "Open App Store to Review")
}
@IBAction func reportIssue(_: Any) {
feedbackWindow.showWindow(nil)
NSApp.activate(ignoringOtherApps: true)
view.window?.orderOut(nil)
if let countryCode = Locale.autoupdatingCurrent.regionCode {
let custom: [String: Any] = ["Country": countryCode]
Logger.log(object: custom, for: "Report Issue Opened")
}
}
@IBAction func openGitHub(_: Any) {
guard let localizationURL = URL(string: AboutUsConstants.CrowdInLocalizationLink),
let languageCode = Locale.preferredLanguages.first else { return }
NSWorkspace.shared.open(localizationURL)
// Log this
let custom: [String: Any] = ["Language": languageCode]
Logger.log(object: custom, for: "Opened Localization Link")
}
6 years ago
6 years ago
@IBOutlet var feedbackLabel: NSTextField!
6 years ago
private func setup() {
5 years ago
feedbackLabel.stringValue = "Feedback is always welcome:".localized()
feedbackLabel.textColor = Themer.shared().mainTextColor()
versionField.textColor = Themer.shared().mainTextColor()
underlineTextForActionButton()
}
}