Browse Source

Formatting!

pull/101/head
Abhishek Banthia 3 years ago
parent
commit
13eba45efa
  1. 13
      Clocker/Panel/UI/TimezoneCellView.swift
  2. 2
      Clocker/Panel/UI/TimezoneDataSource.swift
  3. 90
      Clocker/Panel/UI/Toasty.swift
  4. 6
      Clocker/Preferences/About/AboutViewController.swift
  5. 12
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
  6. 5
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  7. 6
      Clocker/Preferences/Calendar/CalendarViewController.swift

13
Clocker/Panel/UI/TimezoneCellView.swift

@ -39,7 +39,7 @@ class TimezoneCellView: NSTableCellView {
func setupLayout() { func setupLayout() {
guard let relativeFont = relativeDate.font, guard let relativeFont = relativeDate.font,
let sunriseFont = sunriseSetTime.font let sunriseFont = sunriseSetTime.font
else { else {
assertionFailure("Unable to convert to NSString") assertionFailure("Unable to convert to NSString")
return return
@ -128,7 +128,8 @@ class TimezoneCellView: NSTableCellView {
} }
guard let customFont = customName.font, guard let customFont = customName.font,
let timeFont = time.font else { let timeFont = time.font
else {
assertionFailure("User Font Size is in unexpectedly nil") assertionFailure("User Font Size is in unexpectedly nil")
return return
} }
@ -164,7 +165,7 @@ class TimezoneCellView: NSTableCellView {
} }
guard let panelTableView = searchView as? PanelTableView, guard let panelTableView = searchView as? PanelTableView,
let enclosingScroller = panelTableView.enclosingScrollView let enclosingScroller = panelTableView.enclosingScrollView
else { else {
// We might be coming from the preview tableview! // We might be coming from the preview tableview!
return return
@ -203,9 +204,9 @@ class TimezoneCellView: NSTableCellView {
let pasteboard = NSPasteboard.general let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.string], owner: nil) pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString(clipboardCopy, forType: .string) pasteboard.setString(clipboardCopy, forType: .string)
self.window?.contentView?.makeToast("Copied to Clipboard".localized()) window?.contentView?.makeToast("Copied to Clipboard".localized())
window?.endEditing(for: nil) window?.endEditing(for: nil)
} }

2
Clocker/Panel/UI/TimezoneDataSource.swift

@ -145,7 +145,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
panelController.deleteTimezone(at: row) panelController.deleteTimezone(at: row)
} }
}) })
if #available(OSX 11.0, *) { if #available(OSX 11.0, *) {
swipeToDelete.image = Themer.shared().symbolImage(for: "trash.fill") swipeToDelete.image = Themer.shared().symbolImage(for: "trash.fill")

90
Clocker/Panel/UI/Toasty.swift

@ -1,13 +1,14 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import Foundation
import AppKit import AppKit
import Foundation
extension CGRect { extension CGRect {
static func center(of layer: CALayer) -> CGPoint { static func center(of layer: CALayer) -> CGPoint {
let parentSize = layer.frame.size let parentSize = layer.frame.size
return CGPoint(x: parentSize.width / 2, y: parentSize.height / 2) return CGPoint(x: parentSize.width / 2, y: parentSize.height / 2)
} }
static func center(of parent: NSView) -> CGPoint { static func center(of parent: NSView) -> CGPoint {
let parentSize = parent.frame.size let parentSize = parent.frame.size
return CGPoint(x: parentSize.width / 2, y: parentSize.height / 6) return CGPoint(x: parentSize.width / 2, y: parentSize.height / 6)
@ -22,18 +23,21 @@ extension String {
} }
} }
fileprivate class HideAnimationDelegate: NSObject, CAAnimationDelegate { private class HideAnimationDelegate: NSObject, CAAnimationDelegate {
private weak var view: NSView? private weak var view: NSView?
fileprivate init(view: NSView) { fileprivate init(view: NSView) {
self.view = view self.view = view
} }
fileprivate static func delegate(forView NSView: NSView) -> CAAnimationDelegate { fileprivate static func delegate(forView NSView: NSView) -> CAAnimationDelegate {
return HideAnimationDelegate(view: NSView) return HideAnimationDelegate(view: NSView)
} }
fileprivate func animationDidStart(_ anim: CAAnimation) {
fileprivate func animationDidStart(_: CAAnimation) {
view?.layer?.opacity = 0.0 view?.layer?.opacity = 0.0
} }
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
func animationDidStop(_: CAAnimation, finished _: Bool) {
view?.removeFromSuperview() view?.removeFromSuperview()
view = nil view = nil
} }
@ -55,46 +59,48 @@ func hideAnimation(view: NSView, style: Style) {
} }
public protocol Style { public protocol Style {
var fontSize: CGFloat {get} var fontSize: CGFloat { get }
var horizontalMargin: CGFloat {get} var horizontalMargin: CGFloat { get }
var verticalMargin: CGFloat {get} var verticalMargin: CGFloat { get }
var cornerRadius: CGFloat {get} var cornerRadius: CGFloat { get }
var font: NSFont {get} var font: NSFont { get }
var backgroundColor: NSColor {get} var backgroundColor: NSColor { get }
var foregroundColor: NSColor {get} var foregroundColor: NSColor { get }
var fadeInOutDuration: CGFloat {get} var fadeInOutDuration: CGFloat { get }
var fadeInOutDelay: CGFloat {get} var fadeInOutDelay: CGFloat { get }
var labelOriginWithMargin: CGPoint {get} var labelOriginWithMargin: CGPoint { get }
var activitySize: CGSize {get} var activitySize: CGSize { get }
} }
extension Style { public extension Style {
public var labelOriginWithMargin: CGPoint { var labelOriginWithMargin: CGPoint {
return CGPoint(x: horizontalMargin, y: verticalMargin) return CGPoint(x: horizontalMargin, y: verticalMargin)
} }
public var fontSize: CGFloat {return 12}
public var font: NSFont { var fontSize: CGFloat { return 12 }
var font: NSFont {
if let avenirFont = NSFont(name: "Avenir-Light", size: fontSize) { if let avenirFont = NSFont(name: "Avenir-Light", size: fontSize) {
return avenirFont return avenirFont
} }
return NSFont.systemFont(ofSize: fontSize) return NSFont.systemFont(ofSize: fontSize)
} }
public var horizontalMargin: CGFloat {return 10}
public var verticalMargin: CGFloat {return 5} var horizontalMargin: CGFloat { return 10 }
public var cornerRadius: CGFloat {return 8} var verticalMargin: CGFloat { return 5 }
public var backgroundColor: NSColor {return .black} var cornerRadius: CGFloat { return 8 }
public var foregroundColor: NSColor {return .white} var backgroundColor: NSColor { return .black }
public var activitySize: CGSize {return CGSize(width: 100, height: 100)} var foregroundColor: NSColor { return .white }
public var fadeInOutDuration: CGFloat {return 1.0} var activitySize: CGSize { return CGSize(width: 100, height: 100) }
public var fadeInOutDelay: CGFloat {return 1.0} var fadeInOutDuration: CGFloat { return 1.0 }
var fadeInOutDelay: CGFloat { return 1.0 }
} }
public struct DefaultStyle: Style { public struct DefaultStyle: Style {
public static let shared = DefaultStyle() public static let shared = DefaultStyle()
} }
private struct ToastKeys { private enum ToastKeys {
static var ActiveToast = "TSToastActiveToastKey" static var ActiveToast = "TSToastActiveToastKey"
} }
class ToastView: NSView { class ToastView: NSView {
@ -103,31 +109,33 @@ class ToastView: NSView {
private let style: Style private let style: Style
init(message: String) { init(message: String) {
self.message = message self.message = message
self.style = DefaultStyle() style = DefaultStyle()
self.labelSize = message.size(with: style.fontSize) labelSize = message.size(with: style.fontSize)
let size = CGSize( let size = CGSize(
width: labelSize.width + style.horizontalMargin*2, width: labelSize.width + style.horizontalMargin * 2,
height: labelSize.height + style.verticalMargin*2 height: labelSize.height + style.verticalMargin * 2
) )
let rect = CGRect(origin: .zero, size: size) let rect = CGRect(origin: .zero, size: size)
super.init(frame: rect) super.init(frame: rect)
wantsLayer = true wantsLayer = true
} }
required init?(coder aDecoder: NSCoder) { fatalError() }
@available(*, unavailable)
required init?(coder _: NSCoder) { fatalError() }
override func viewDidMoveToSuperview() { override func viewDidMoveToSuperview() {
super.viewDidMoveToSuperview() super.viewDidMoveToSuperview()
if superview != nil { if superview != nil {
configure() configure()
} }
} }
private func configure() { private func configure() {
frame = superview?.bounds ?? NSRect.zero frame = superview?.bounds ?? NSRect.zero
let rect = CGRect(origin: style.labelOriginWithMargin, size: labelSize) let rect = CGRect(origin: style.labelOriginWithMargin, size: labelSize)
let sizeWithMargin = CGSize( let sizeWithMargin = CGSize(
width: rect.width + style.horizontalMargin*2, width: rect.width + style.horizontalMargin * 2,
height: rect.height + style.verticalMargin*2 height: rect.height + style.verticalMargin * 2
) )
let rectWithMargin = CGRect( let rectWithMargin = CGRect(
origin: .zero, // position is manipulated later anyways origin: .zero, // position is manipulated later anyways
@ -155,10 +163,10 @@ class ToastView: NSView {
} }
} }
extension NSView { public extension NSView {
public func makeToast(_ message: String) { func makeToast(_ message: String) {
let toast = ToastView(message: message) let toast = ToastView(message: message)
self.addSubview(toast) addSubview(toast)
hideAnimation(view: toast, style: DefaultStyle.shared) hideAnimation(view: toast, style: DefaultStyle.shared)
} }
} }

6
Clocker/Preferences/About/AboutViewController.swift

@ -97,7 +97,7 @@ class AboutViewController: ParentViewController {
@IBAction func openMyTwitter(_: Any) { @IBAction func openMyTwitter(_: Any) {
guard let twitterURL = URL(string: AboutUsConstants.TwitterLink), guard let twitterURL = URL(string: AboutUsConstants.TwitterLink),
let countryCode = Locale.autoupdatingCurrent.regionCode else { return } let countryCode = Locale.autoupdatingCurrent.regionCode else { return }
NSWorkspace.shared.open(twitterURL) NSWorkspace.shared.open(twitterURL)
@ -108,7 +108,7 @@ class AboutViewController: ParentViewController {
@IBAction func viewSource(_: Any) { @IBAction func viewSource(_: Any) {
guard let sourceURL = URL(string: AboutUsConstants.AppStoreLink), guard let sourceURL = URL(string: AboutUsConstants.AppStoreLink),
let countryCode = Locale.autoupdatingCurrent.regionCode else { return } let countryCode = Locale.autoupdatingCurrent.regionCode else { return }
NSWorkspace.shared.open(sourceURL) NSWorkspace.shared.open(sourceURL)
@ -130,7 +130,7 @@ class AboutViewController: ParentViewController {
@IBAction func openGitHub(_: Any) { @IBAction func openGitHub(_: Any) {
guard let localizationURL = URL(string: AboutUsConstants.CrowdInLocalizationLink), guard let localizationURL = URL(string: AboutUsConstants.CrowdInLocalizationLink),
let languageCode = Locale.preferredLanguages.first else { return } let languageCode = Locale.preferredLanguages.first else { return }
NSWorkspace.shared.open(localizationURL) NSWorkspace.shared.open(localizationURL)

12
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -11,7 +11,7 @@ extension NSNib.Name {
static let startAtLoginViewIdentifier = NSNib.Name("StartAtLoginView") static let startAtLoginViewIdentifier = NSNib.Name("StartAtLoginView")
} }
struct AppFeedbackConstants { enum AppFeedbackConstants {
static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow" static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow"
static let CLAppFeedbackNoResponseString = "Not Provided" static let CLAppFeedbackNoResponseString = "Not Provided"
static let CLAppFeedbackNameProperty = "name" static let CLAppFeedbackNameProperty = "name"
@ -59,7 +59,7 @@ class AppFeedbackWindowController: NSWindowController {
} }
} }
static var sharedWindow: AppFeedbackWindowController = AppFeedbackWindowController(windowNibName: NSNib.Name.appFeedbackWindowIdentifier) static var sharedWindow = AppFeedbackWindowController(windowNibName: NSNib.Name.appFeedbackWindowIdentifier)
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
@ -100,6 +100,7 @@ class AppFeedbackWindowController: NSWindowController {
} }
} }
@available(*, unavailable)
required init?(coder _: NSCoder) { required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
@ -132,7 +133,7 @@ class AppFeedbackWindowController: NSWindowController {
repeats: false, repeats: false,
block: { _ in block: { _ in
self.resetInformativeLabel() self.resetInformativeLabel()
}) })
isActivityInProgress = false isActivityInProgress = false
@ -144,7 +145,8 @@ class AppFeedbackWindowController: NSWindowController {
private func retrieveDataForSending() -> [String: String] { private func retrieveDataForSending() -> [String: String] {
guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String, guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String,
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else { let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
else {
return [:] return [:]
} }
@ -248,7 +250,7 @@ class AppFeedbackWindowController: NSWindowController {
@IBAction func navigateToSupportTwitter(_: Any) { @IBAction func navigateToSupportTwitter(_: Any) {
guard let twitterURL = URL(string: AboutUsConstants.TwitterLink), guard let twitterURL = URL(string: AboutUsConstants.TwitterLink),
let countryCode = Locale.autoupdatingCurrent.regionCode else { return } let countryCode = Locale.autoupdatingCurrent.regionCode else { return }
NSWorkspace.shared.open(twitterURL) NSWorkspace.shared.open(twitterURL)

5
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -183,7 +183,8 @@ class AppearanceViewController: ParentViewController {
refresh(panel: true, floating: true) refresh(panel: true, floating: true)
if let selectedFormat = sender.selectedItem?.title, if let selectedFormat = sender.selectedItem?.title,
selectedFormat.contains("ss") { selectedFormat.contains("ss")
{
print("Seconds are contained") print("Seconds are contained")
guard let panelController = PanelController.panel() else { return } guard let panelController = PanelController.panel() else { return }
panelController.pauseTimer() panelController.pauseTimer()
@ -193,7 +194,7 @@ class AppearanceViewController: ParentViewController {
previewPanelTableView.reloadData() previewPanelTableView.reloadData()
} }
private var previousBackgroundColor: NSColor = NSColor.white private var previousBackgroundColor = NSColor.white
@IBAction func themeChanged(_ sender: NSSegmentedControl) { @IBAction func themeChanged(_ sender: NSSegmentedControl) {
previousBackgroundColor = Themer.shared().mainBackgroundColor() previousBackgroundColor = Themer.shared().mainBackgroundColor()

6
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -239,13 +239,15 @@ extension CalendarViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? { func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
if let currentSource = calendars[row] as? String, if let currentSource = calendars[row] as? String,
let message = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "sourceCellView"), owner: self) as? SourceTableViewCell { let message = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "sourceCellView"), owner: self) as? SourceTableViewCell
{
message.sourceName.stringValue = currentSource message.sourceName.stringValue = currentSource
return message return message
} }
if let currentSource = calendars[row] as? CalendarInfo, if let currentSource = calendars[row] as? CalendarInfo,
let calendarCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "calendarCellView"), owner: self) as? CalendarTableViewCell { let calendarCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "calendarCellView"), owner: self) as? CalendarTableViewCell
{
calendarCell.calendarName.stringValue = currentSource.calendar.title calendarCell.calendarName.stringValue = currentSource.calendar.title
calendarCell.calendarSelected.state = currentSource.selected ? NSControl.StateValue.on : NSControl.StateValue.off calendarCell.calendarSelected.state = currentSource.selected ? NSControl.StateValue.on : NSControl.StateValue.off
calendarCell.calendarSelected.target = self calendarCell.calendarSelected.target = self

Loading…
Cancel
Save