From 13eba45efa7b0d70194431894142670078cba738 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Mon, 5 Jul 2021 17:21:31 -0400 Subject: [PATCH] Formatting! --- Clocker/Panel/UI/TimezoneCellView.swift | 13 +-- Clocker/Panel/UI/TimezoneDataSource.swift | 2 +- Clocker/Panel/UI/Toasty.swift | 90 ++++++++++--------- .../About/AboutViewController.swift | 6 +- .../AppFeedbackWindowController.swift | 12 +-- .../Appearance/AppearanceViewController.swift | 5 +- .../Calendar/CalendarViewController.swift | 6 +- 7 files changed, 74 insertions(+), 60 deletions(-) diff --git a/Clocker/Panel/UI/TimezoneCellView.swift b/Clocker/Panel/UI/TimezoneCellView.swift index f315bb8..7e042ea 100644 --- a/Clocker/Panel/UI/TimezoneCellView.swift +++ b/Clocker/Panel/UI/TimezoneCellView.swift @@ -39,7 +39,7 @@ class TimezoneCellView: NSTableCellView { func setupLayout() { guard let relativeFont = relativeDate.font, - let sunriseFont = sunriseSetTime.font + let sunriseFont = sunriseSetTime.font else { assertionFailure("Unable to convert to NSString") return @@ -128,7 +128,8 @@ class TimezoneCellView: NSTableCellView { } guard let customFont = customName.font, - let timeFont = time.font else { + let timeFont = time.font + else { assertionFailure("User Font Size is in unexpectedly nil") return } @@ -164,7 +165,7 @@ class TimezoneCellView: NSTableCellView { } guard let panelTableView = searchView as? PanelTableView, - let enclosingScroller = panelTableView.enclosingScrollView + let enclosingScroller = panelTableView.enclosingScrollView else { // We might be coming from the preview tableview! return @@ -203,9 +204,9 @@ class TimezoneCellView: NSTableCellView { let pasteboard = NSPasteboard.general pasteboard.declareTypes([.string], owner: nil) pasteboard.setString(clipboardCopy, forType: .string) - - self.window?.contentView?.makeToast("Copied to Clipboard".localized()) - + + window?.contentView?.makeToast("Copied to Clipboard".localized()) + window?.endEditing(for: nil) } diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index ac42523..c518c34 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -145,7 +145,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate { panelController.deleteTimezone(at: row) } - }) + }) if #available(OSX 11.0, *) { swipeToDelete.image = Themer.shared().symbolImage(for: "trash.fill") diff --git a/Clocker/Panel/UI/Toasty.swift b/Clocker/Panel/UI/Toasty.swift index 86455fe..852fbe0 100644 --- a/Clocker/Panel/UI/Toasty.swift +++ b/Clocker/Panel/UI/Toasty.swift @@ -1,13 +1,14 @@ // Copyright © 2015 Abhishek Banthia -import Foundation import AppKit +import Foundation extension CGRect { static func center(of layer: CALayer) -> CGPoint { let parentSize = layer.frame.size return CGPoint(x: parentSize.width / 2, y: parentSize.height / 2) } + static func center(of parent: NSView) -> CGPoint { let parentSize = parent.frame.size 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? fileprivate init(view: NSView) { self.view = view } + fileprivate static func delegate(forView NSView: NSView) -> CAAnimationDelegate { return HideAnimationDelegate(view: NSView) } - fileprivate func animationDidStart(_ anim: CAAnimation) { + + fileprivate func animationDidStart(_: CAAnimation) { view?.layer?.opacity = 0.0 } - func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { + + func animationDidStop(_: CAAnimation, finished _: Bool) { view?.removeFromSuperview() view = nil } @@ -55,46 +59,48 @@ func hideAnimation(view: NSView, style: Style) { } public protocol Style { - var fontSize: CGFloat {get} - var horizontalMargin: CGFloat {get} - var verticalMargin: CGFloat {get} - var cornerRadius: CGFloat {get} - var font: NSFont {get} - var backgroundColor: NSColor {get} - var foregroundColor: NSColor {get} - var fadeInOutDuration: CGFloat {get} - var fadeInOutDelay: CGFloat {get} - var labelOriginWithMargin: CGPoint {get} - var activitySize: CGSize {get} + var fontSize: CGFloat { get } + var horizontalMargin: CGFloat { get } + var verticalMargin: CGFloat { get } + var cornerRadius: CGFloat { get } + var font: NSFont { get } + var backgroundColor: NSColor { get } + var foregroundColor: NSColor { get } + var fadeInOutDuration: CGFloat { get } + var fadeInOutDelay: CGFloat { get } + var labelOriginWithMargin: CGPoint { get } + var activitySize: CGSize { get } } -extension Style { - public var labelOriginWithMargin: CGPoint { +public extension Style { + var labelOriginWithMargin: CGPoint { 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) { return avenirFont } return NSFont.systemFont(ofSize: fontSize) } - public var horizontalMargin: CGFloat {return 10} - public var verticalMargin: CGFloat {return 5} - public var cornerRadius: CGFloat {return 8} - public var backgroundColor: NSColor {return .black} - public var foregroundColor: NSColor {return .white} - public var activitySize: CGSize {return CGSize(width: 100, height: 100)} - public var fadeInOutDuration: CGFloat {return 1.0} - public var fadeInOutDelay: CGFloat {return 1.0} + + var horizontalMargin: CGFloat { return 10 } + var verticalMargin: CGFloat { return 5 } + var cornerRadius: CGFloat { return 8 } + var backgroundColor: NSColor { return .black } + var foregroundColor: NSColor { return .white } + var activitySize: CGSize { return CGSize(width: 100, height: 100) } + var fadeInOutDuration: CGFloat { return 1.0 } + var fadeInOutDelay: CGFloat { return 1.0 } } public struct DefaultStyle: Style { public static let shared = DefaultStyle() } -private struct ToastKeys { - static var ActiveToast = "TSToastActiveToastKey" +private enum ToastKeys { + static var ActiveToast = "TSToastActiveToastKey" } class ToastView: NSView { @@ -103,31 +109,33 @@ class ToastView: NSView { private let style: Style init(message: String) { self.message = message - self.style = DefaultStyle() - self.labelSize = message.size(with: style.fontSize) + style = DefaultStyle() + labelSize = message.size(with: style.fontSize) let size = CGSize( - width: labelSize.width + style.horizontalMargin*2, - height: labelSize.height + style.verticalMargin*2 + width: labelSize.width + style.horizontalMargin * 2, + height: labelSize.height + style.verticalMargin * 2 ) let rect = CGRect(origin: .zero, size: size) super.init(frame: rect) wantsLayer = true } - required init?(coder aDecoder: NSCoder) { fatalError() } - + + @available(*, unavailable) + required init?(coder _: NSCoder) { fatalError() } + override func viewDidMoveToSuperview() { super.viewDidMoveToSuperview() if superview != nil { configure() } } - + private func configure() { frame = superview?.bounds ?? NSRect.zero let rect = CGRect(origin: style.labelOriginWithMargin, size: labelSize) let sizeWithMargin = CGSize( - width: rect.width + style.horizontalMargin*2, - height: rect.height + style.verticalMargin*2 + width: rect.width + style.horizontalMargin * 2, + height: rect.height + style.verticalMargin * 2 ) let rectWithMargin = CGRect( origin: .zero, // position is manipulated later anyways @@ -155,10 +163,10 @@ class ToastView: NSView { } } -extension NSView { - public func makeToast(_ message: String) { +public extension NSView { + func makeToast(_ message: String) { let toast = ToastView(message: message) - self.addSubview(toast) + addSubview(toast) hideAnimation(view: toast, style: DefaultStyle.shared) } } diff --git a/Clocker/Preferences/About/AboutViewController.swift b/Clocker/Preferences/About/AboutViewController.swift index a06a6b5..3f4f0d1 100644 --- a/Clocker/Preferences/About/AboutViewController.swift +++ b/Clocker/Preferences/About/AboutViewController.swift @@ -97,7 +97,7 @@ class AboutViewController: ParentViewController { @IBAction func openMyTwitter(_: Any) { 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) @@ -108,7 +108,7 @@ class AboutViewController: ParentViewController { @IBAction func viewSource(_: Any) { 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) @@ -130,7 +130,7 @@ class AboutViewController: ParentViewController { @IBAction func openGitHub(_: Any) { 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) diff --git a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift index abe1b8e..eb150d3 100644 --- a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift +++ b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift @@ -11,7 +11,7 @@ extension NSNib.Name { static let startAtLoginViewIdentifier = NSNib.Name("StartAtLoginView") } -struct AppFeedbackConstants { +enum AppFeedbackConstants { static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow" static let CLAppFeedbackNoResponseString = "Not Provided" 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() { super.windowDidLoad() @@ -100,6 +100,7 @@ class AppFeedbackWindowController: NSWindowController { } } + @available(*, unavailable) required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -132,7 +133,7 @@ class AppFeedbackWindowController: NSWindowController { repeats: false, block: { _ in self.resetInformativeLabel() - }) + }) isActivityInProgress = false @@ -144,7 +145,8 @@ class AppFeedbackWindowController: NSWindowController { private func retrieveDataForSending() -> [String: 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 [:] } @@ -248,7 +250,7 @@ class AppFeedbackWindowController: NSWindowController { @IBAction func navigateToSupportTwitter(_: Any) { 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) diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 9fb408b..b8c522d 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -183,7 +183,8 @@ class AppearanceViewController: ParentViewController { refresh(panel: true, floating: true) if let selectedFormat = sender.selectedItem?.title, - selectedFormat.contains("ss") { + selectedFormat.contains("ss") + { print("Seconds are contained") guard let panelController = PanelController.panel() else { return } panelController.pauseTimer() @@ -193,7 +194,7 @@ class AppearanceViewController: ParentViewController { previewPanelTableView.reloadData() } - private var previousBackgroundColor: NSColor = NSColor.white + private var previousBackgroundColor = NSColor.white @IBAction func themeChanged(_ sender: NSSegmentedControl) { previousBackgroundColor = Themer.shared().mainBackgroundColor() diff --git a/Clocker/Preferences/Calendar/CalendarViewController.swift b/Clocker/Preferences/Calendar/CalendarViewController.swift index 726f154..5a9bf40 100644 --- a/Clocker/Preferences/Calendar/CalendarViewController.swift +++ b/Clocker/Preferences/Calendar/CalendarViewController.swift @@ -239,13 +239,15 @@ extension CalendarViewController: NSTableViewDelegate { func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? { 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 return message } 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.calendarSelected.state = currentSource.selected ? NSControl.StateValue.on : NSControl.StateValue.off calendarCell.calendarSelected.target = self