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 - type_body_length
- file_length - file_length
- nesting - nesting
- function_body_length
opt_in_rules: # some rules are only opt-in opt_in_rules: # some rules are only opt-in
- empty_count - empty_count
# included: # paths to include during linting. `--path` is ignored if present. # 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 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. // Current State is set twice when the user first launches an app.
// First, when StatusItemHandler() is instantiated in AppDelegate // First, when StatusItemHandler() is instantiated in AppDelegate
// Second, when AppDelegate.fetchLocalTimezone() is called triggering a customLabel didSet. // Second, when AppDelegate.fetchLocalTimezone() is called triggering a customLabel didSet.
@ -109,13 +111,19 @@ class StatusItemHandler: NSObject {
name: .interfaceStyleDidChange, name: .interfaceStyleDidChange,
object: nil) object: nil)
center.addObserver(forName: UserDefaults.didChangeNotification, userNotificationsDidChangeNotif = center.addObserver(forName: UserDefaults.didChangeNotification,
object: self, object: self,
queue: mainQueue) { _ in queue: mainQueue) { _ in
self.setupStatusItem() self.setupStatusItem()
} }
} }
deinit {
if let userNotifsDidChange = userNotificationsDidChangeNotif {
NotificationCenter.default.removeObserver(userNotifsDidChange)
}
}
private func constructCompactView() { private func constructCompactView() {
parentView = nil parentView = nil

9
Clocker/Onboarding/OnboardingSearchController.swift

@ -18,6 +18,7 @@ class OnboardingSearchController: NSViewController {
private var results: [TimezoneData] = [] private var results: [TimezoneData] = []
private var dataTask: URLSessionDataTask? = .none private var dataTask: URLSessionDataTask? = .none
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -31,7 +32,7 @@ class OnboardingSearchController: NSViewController {
setup() 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.setup()
} }
@ -47,6 +48,12 @@ class OnboardingSearchController: NSViewController {
setupUndoButton() setupUndoButton()
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
@objc func doubleClickAction(_: NSTableView?) { @objc func doubleClickAction(_: NSTableView?) {
[accessoryLabel].forEach { $0?.isHidden = false } [accessoryLabel].forEach { $0?.isHidden = false }

9
Clocker/Panel/ParentPanelController.swift

@ -12,6 +12,9 @@ struct PanelConstants {
} }
class ParentPanelController: NSWindowController { class ParentPanelController: NSWindowController {
private var eventStoreChangedNotification: NSObjectProtocol?
var dateFormatter = DateFormatter() var dateFormatter = DateFormatter()
var futureSliderValue: Int { var futureSliderValue: Int {
@ -80,6 +83,10 @@ class ParentPanelController: NSWindowController {
deinit { deinit {
datasource = nil datasource = nil
if let eventStoreNotif = eventStoreChangedNotification {
NotificationCenter.default.removeObserver(eventStoreNotif)
}
} }
override func awakeFromNib() { override func awakeFromNib() {
@ -200,7 +207,7 @@ class ParentPanelController: NSWindowController {
} else { } else {
upcomingEventView?.isHidden = false upcomingEventView?.isHidden = false
setupUpcomingEventView() 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() self.fetchCalendarEvents()
} }
} }

9
Clocker/Preferences/About/AboutViewController.swift

@ -18,6 +18,7 @@ class AboutViewController: ParentViewController {
@IBOutlet var openSourceButton: UnderlinedButton! @IBOutlet var openSourceButton: UnderlinedButton!
@IBOutlet var versionField: NSTextField! @IBOutlet var versionField: NSTextField!
private var themeDidChangeNotification: NSObjectProtocol?
private lazy var feedbackWindow = AppFeedbackWindowController.shared() private lazy var feedbackWindow = AppFeedbackWindowController.shared()
override func viewDidLoad() { override func viewDidLoad() {
@ -32,11 +33,17 @@ class AboutViewController: ParentViewController {
setup() 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.setup()
} }
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func underlineTextForActionButton() { private func underlineTextForActionButton() {
let rangesInOrder = [NSRange(location: 3, length: 8), let rangesInOrder = [NSRange(location: 3, length: 8),
NSRange(location: 7, length: privateFeedback.attributedTitle.length - 7), 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 informativeText: NSTextField!
@IBOutlet var progressIndicator: NSProgressIndicator! @IBOutlet var progressIndicator: NSProgressIndicator!
private var themeDidChangeNotification: NSObjectProtocol?
private var serialNumber: String? { private var serialNumber: String? {
let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")) let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
@ -72,7 +73,9 @@ class AppFeedbackWindowController: NSWindowController {
setup() 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.window?.backgroundColor = Themer.shared().mainBackgroundColor()
self.setup() self.setup()
} }
@ -86,6 +89,12 @@ class AppFeedbackWindowController: NSWindowController {
super.init(window: window) super.init(window: window)
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
required init?(coder _: NSCoder) { required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") 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 includeDateInMenubarControl: NSSegmentedControl!
@IBOutlet weak var includePlaceNameControl: NSSegmentedControl! @IBOutlet weak var includePlaceNameControl: NSSegmentedControl!
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -34,13 +36,19 @@ class AppearanceViewController: ParentViewController {
setup() 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.setup()
self.animateBackgroundColorChange() self.animateBackgroundColorChange()
self.view.needsDisplay = true // Let's make the color change permanent. self.view.needsDisplay = true // Let's make the color change permanent.
} }
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func animateBackgroundColorChange() { private func animateBackgroundColorChange() {
let colorAnimation = CABasicAnimation(keyPath: "backgroundColor") let colorAnimation = CABasicAnimation(keyPath: "backgroundColor")
colorAnimation.duration = 0.25 colorAnimation.duration = 0.25

19
Clocker/Preferences/Calendar/CalendarViewController.swift

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

10
Clocker/Preferences/General/PreferencesViewController.swift

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

9
Clocker/Preferences/OneWindowController.swift

@ -25,12 +25,13 @@ class CenteredTabViewController: NSTabViewController {
class OneWindowController: NSWindowController { class OneWindowController: NSWindowController {
private static var sharedWindow: OneWindowController! private static var sharedWindow: OneWindowController!
private var themeDidChangeNotification: NSObjectProtocol?
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
setup() 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 NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1 context.duration = 1
@ -42,6 +43,12 @@ class OneWindowController: NSWindowController {
} }
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func setup() { private func setup() {
setupWindow() setupWindow()
setupToolbarImages() setupToolbarImages()

10
Clocker/Preferences/Permissions/PermissionsViewController.swift

@ -22,12 +22,14 @@ class PermissionsViewController: ParentViewController {
@IBOutlet private var privacyLabel: NSTextField! @IBOutlet private var privacyLabel: NSTextField!
@IBOutlet private var headerLabel: NSTextField! @IBOutlet private var headerLabel: NSTextField!
private var themeDidChangeNotification: NSObjectProtocol?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
[calendarContainerView, remindersContainerView].forEach { $0?.applyShadow() } [calendarContainerView, remindersContainerView].forEach { $0?.applyShadow() }
setupLocalizedText() 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.setupLocalizedText()
[self.calendarContainerView, self.remindersContainerView].forEach { $0?.applyShadow() } [self.calendarContainerView, self.remindersContainerView].forEach { $0?.applyShadow() }
} }
@ -38,6 +40,12 @@ class PermissionsViewController: ParentViewController {
setup() setup()
} }
deinit {
if let themeDidChangeNotif = themeDidChangeNotification {
NotificationCenter.default.removeObserver(themeDidChangeNotif)
}
}
private func setup() { private func setup() {
setupButtons() setupButtons()
} }

Loading…
Cancel
Save