Browse Source

More linting.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
1553a6bd14
  1. 1
      .swiftlint.yml
  2. 10
      Clocker/Menu Bar/StatusItemHandler.swift
  3. 9
      Clocker/Onboarding/OnboardingSearchController.swift
  4. 9
      Clocker/Panel/ParentPanelController.swift
  5. 9
      Clocker/Preferences/About/AboutViewController.swift
  6. 11
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
  7. 10
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  8. 19
      Clocker/Preferences/Calendar/CalendarViewController.swift
  9. 10
      Clocker/Preferences/General/PreferencesViewController.swift
  10. 9
      Clocker/Preferences/OneWindowController.swift
  11. 10
      Clocker/Preferences/Permissions/PermissionsViewController.swift

1
.swiftlint.yml

@ -6,6 +6,7 @@ disabled_rules: # rule identifiers to exclude from running
- type_body_length
- file_length
- nesting
- function_body_length
opt_in_rules: # some rules are only opt-in
- empty_count
# included: # paths to include during linting. `--path` is ignored if present.

10
Clocker/Menu Bar/StatusItemHandler.swift

@ -28,6 +28,8 @@ class StatusItemHandler: NSObject {
private lazy var units: Set<Calendar.Component> = Set([.era, .year, .month, .day, .hour, .minute])
private var userNotificationsDidChangeNotif: NSObjectProtocol?
// Current State is set twice when the user first launches an app.
// First, when StatusItemHandler() is instantiated in AppDelegate
// Second, when AppDelegate.fetchLocalTimezone() is called triggering a customLabel didSet.
@ -109,13 +111,19 @@ class StatusItemHandler: NSObject {
name: .interfaceStyleDidChange,
object: nil)
center.addObserver(forName: UserDefaults.didChangeNotification,
userNotificationsDidChangeNotif = center.addObserver(forName: UserDefaults.didChangeNotification,
object: self,
queue: mainQueue) { _ in
self.setupStatusItem()
}
}
deinit {
if let userNotifsDidChange = userNotificationsDidChangeNotif {
NotificationCenter.default.removeObserver(userNotifsDidChange)
}
}
private func constructCompactView() {
parentView = nil

9
Clocker/Onboarding/OnboardingSearchController.swift

@ -18,6 +18,7 @@ class OnboardingSearchController: NSViewController {
private var results: [TimezoneData] = []
private var dataTask: URLSessionDataTask? = .none
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() {
super.viewDidLoad()
@ -31,7 +32,7 @@ class OnboardingSearchController: NSViewController {
setup()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
self.setup()
}
@ -47,6 +48,12 @@ class OnboardingSearchController: NSViewController {
setupUndoButton()
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
@objc func doubleClickAction(_: NSTableView?) {
[accessoryLabel].forEach { $0?.isHidden = false }

9
Clocker/Panel/ParentPanelController.swift

@ -12,6 +12,9 @@ struct PanelConstants {
}
class ParentPanelController: NSWindowController {
private var eventStoreChangedNotification: NSObjectProtocol?
var dateFormatter = DateFormatter()
var futureSliderValue: Int {
@ -80,6 +83,10 @@ class ParentPanelController: NSWindowController {
deinit {
datasource = nil
if let eventStoreNotif = eventStoreChangedNotification {
NotificationCenter.default.removeObserver(eventStoreNotif)
}
}
override func awakeFromNib() {
@ -200,7 +207,7 @@ class ParentPanelController: NSWindowController {
} else {
upcomingEventView?.isHidden = false
setupUpcomingEventView()
NotificationCenter.default.addObserver(forName: NSNotification.Name.EKEventStoreChanged, object: self, queue: OperationQueue.main) { _ in
eventStoreChangedNotification = NotificationCenter.default.addObserver(forName: NSNotification.Name.EKEventStoreChanged, object: self, queue: OperationQueue.main) { _ in
self.fetchCalendarEvents()
}
}

9
Clocker/Preferences/About/AboutViewController.swift

@ -18,6 +18,7 @@ class AboutViewController: ParentViewController {
@IBOutlet var openSourceButton: UnderlinedButton!
@IBOutlet var versionField: NSTextField!
private var themeDidChangeNotification: NSObjectProtocol?
private lazy var feedbackWindow = AppFeedbackWindowController.shared()
override func viewDidLoad() {
@ -32,11 +33,17 @@ class AboutViewController: ParentViewController {
setup()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
self.setup()
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func underlineTextForActionButton() {
let rangesInOrder = [NSRange(location: 3, length: 8),
NSRange(location: 7, length: privateFeedback.attributedTitle.length - 7),

11
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -31,6 +31,7 @@ class AppFeedbackWindowController: NSWindowController {
@IBOutlet var informativeText: NSTextField!
@IBOutlet var progressIndicator: NSProgressIndicator!
private var themeDidChangeNotification: NSObjectProtocol?
private var serialNumber: String? {
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
@ -72,7 +73,9 @@ class AppFeedbackWindowController: NSWindowController {
setup()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification,
object: nil,
queue: OperationQueue.main) { _ in
self.window?.backgroundColor = Themer.shared().mainBackgroundColor()
self.setup()
}
@ -86,6 +89,12 @@ class AppFeedbackWindowController: NSWindowController {
super.init(window: window)
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

10
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -13,6 +13,8 @@ class AppearanceViewController: ParentViewController {
@IBOutlet weak var includeDateInMenubarControl: NSSegmentedControl!
@IBOutlet weak var includePlaceNameControl: NSSegmentedControl!
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() {
super.viewDidLoad()
@ -34,13 +36,19 @@ class AppearanceViewController: ParentViewController {
setup()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
self.setup()
self.animateBackgroundColorChange()
self.view.needsDisplay = true // Let's make the color change permanent.
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func animateBackgroundColorChange() {
let colorAnimation = CABasicAnimation(keyPath: "backgroundColor")
colorAnimation.duration = 0.25

19
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -5,17 +5,25 @@ import EventKit
class ClockerTextBackgroundView: NSView {
private var themeDidChangeNotification: NSObjectProtocol?
override func awakeFromNib() {
wantsLayer = true
layer?.cornerRadius = 8.0
layer?.masksToBounds = false
layer?.backgroundColor = Themer.shared().textBackgroundColor().cgColor
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
self.layer?.backgroundColor = Themer.shared().textBackgroundColor().cgColor
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
override func updateLayer() {
super.updateLayer()
layer?.backgroundColor = Themer.shared().textBackgroundColor().cgColor
@ -35,6 +43,7 @@ class CalendarViewController: ParentViewController {
@IBOutlet weak var showNextMeetingInMenubarControl: NSSegmentedControl!
@IBOutlet weak var backgroundView: NSView!
@IBOutlet weak var nextMeetingBackgroundView: NSView!
private var themeDidChangeNotification: NSObjectProtocol?
private lazy var calendars: [Any] = EventCenter.sharedCenter().fetchSourcesAndCalendars()
@ -48,7 +57,7 @@ class CalendarViewController: ParentViewController {
name: .calendarAccessGranted,
object: nil)
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
self.setup()
}
@ -57,6 +66,12 @@ class CalendarViewController: ParentViewController {
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
@objc func calendarAccessStatusChanged() {
verifyCalendarAccess()

10
Clocker/Preferences/General/PreferencesViewController.swift

@ -29,7 +29,6 @@ class PreferencesViewController: ParentViewController {
private var selectedTimeZones: [Data] {
get {
return DataStore.shared().timezones()
} set {
}
}
@ -79,6 +78,7 @@ class PreferencesViewController: ParentViewController {
@IBOutlet var headerLabel: NSTextField!
@IBOutlet var sortToggle: NSButton!
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() {
super.viewDidLoad()
@ -98,11 +98,17 @@ class PreferencesViewController: ParentViewController {
darkModeChanges()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
self.setup()
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func darkModeChanges() {
if #available(macOS 10.14, *) {
addTimezoneButton.image = NSImage(named: .addDynamicIcon)

9
Clocker/Preferences/OneWindowController.swift

@ -25,12 +25,13 @@ class CenteredTabViewController: NSTabViewController {
class OneWindowController: NSWindowController {
private static var sharedWindow: OneWindowController!
private var themeDidChangeNotification: NSObjectProtocol?
override func windowDidLoad() {
super.windowDidLoad()
setup()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { (_) in
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1
@ -42,6 +43,12 @@ class OneWindowController: NSWindowController {
}
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func setup() {
setupWindow()
setupToolbarImages()

10
Clocker/Preferences/Permissions/PermissionsViewController.swift

@ -22,12 +22,14 @@ class PermissionsViewController: ParentViewController {
@IBOutlet private var privacyLabel: NSTextField!
@IBOutlet private var headerLabel: NSTextField!
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() {
super.viewDidLoad()
[calendarContainerView, remindersContainerView].forEach { $0?.applyShadow() }
setupLocalizedText()
NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
themeDidChangeNotification = NotificationCenter.default.addObserver(forName: .themeDidChangeNotification, object: nil, queue: OperationQueue.main) { _ in
self.setupLocalizedText()
[self.calendarContainerView, self.remindersContainerView].forEach { $0?.applyShadow() }
}
@ -38,6 +40,12 @@ class PermissionsViewController: ParentViewController {
setup()
}
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func setup() {
setupButtons()
}

Loading…
Cancel
Save