Browse Source

Swiftformat.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
93c36cd25c
  1. 17
      Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift
  2. 8
      Clocker/Overall App/DataStore.swift
  3. 4
      Clocker/Panel/ParentPanelController.swift
  4. 9
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  5. 2
      Clocker/Preferences/General/PreferencesViewController.swift
  6. 6
      Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift
  7. 2
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

17
Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift

@ -13,7 +13,7 @@ class StandardMenubarHandlerTests: XCTestCase {
"nextUpdate": "",
"latitude": "19.0759837",
"longitude": "72.8776559"]
private func makeMockStore(with menubarMode: Int = 1) -> DataStore {
// Wipe all timezones from UserDefaults
guard let defaults = UserDefaults(suiteName: "com.abhishek.Clocker.StandardMenubarHandlerTests") else {
@ -25,10 +25,11 @@ class StandardMenubarHandlerTests: XCTestCase {
XCTAssertNotEqual(defaults, UserDefaults.standard)
return DataStore(with: defaults)
}
private func saveObject(object: TimezoneData,
in store: DataStore,
at index: Int = -1) {
at index: Int = -1)
{
var defaults = store.timezones()
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object as Any)
index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index)
@ -81,14 +82,14 @@ class StandardMenubarHandlerTests: XCTestCase {
// Test menubar string is absent
XCTAssertTrue(menubarString.count == 0)
}
func testWithEmptyMenubarTimezones() {
let store = makeMockStore()
store.setTimezones(nil)
let menubarHandler = MenubarTitleProvider(with: store)
XCTAssertNil(menubarHandler.titleForMenubar())
}
func testWithStandardMenubarMode() {
// Set mode to standard mode
let store = makeMockStore(with: 0)
@ -96,11 +97,11 @@ class StandardMenubarHandlerTests: XCTestCase {
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 1
saveObject(object: dataObject, in: store)
let menubarHandler = MenubarTitleProvider(with: store)
XCTAssertNil(menubarHandler.titleForMenubar())
}
func testProviderPassingAllConditions() {
// Set mode to standard mode
let store = makeMockStore()
@ -108,7 +109,7 @@ class StandardMenubarHandlerTests: XCTestCase {
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 1
saveObject(object: dataObject, in: store)
let menubarHandler = MenubarTitleProvider(with: store)
XCTAssertNotNil(menubarHandler.titleForMenubar())
}

8
Clocker/Overall App/DataStore.swift

@ -44,8 +44,8 @@ class DataStore: NSObject {
userDefaults = defaults
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
if (shouldDisplay(.sync)) {
if shouldDisplay(.sync) {
ubiquitousStore = NSUbiquitousKeyValueStore.default
NotificationCenter.default.addObserver(self,
selector: #selector(ubiquitousKeyValueStoreChanged),
@ -54,14 +54,14 @@ class DataStore: NSObject {
ubiquitousStore?.synchronize()
}
}
@objc func ubiquitousKeyValueStoreChanged(_ notification: Notification) {
let userInfo = notification.userInfo ?? [:]
let ubiquitousStore = notification.object as? NSUbiquitousKeyValueStore
print("--- User Info is \(userInfo)")
let currentTimezones = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data]
let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data]
if cloudTimezones != currentTimezones {
Logger.info("Syncing local timezones with data from the ☁")
userDefaults.set(cloudTimezones, forKey: CLDefaultPreferenceKey)

4
Clocker/Panel/ParentPanelController.swift

@ -195,8 +195,8 @@ class ParentPanelController: NSWindowController {
selector: #selector(systemTimezoneDidChange),
name: NSNotification.Name.NSSystemTimeZoneDidChange,
object: nil)
if (DataStore.shared().shouldDisplay(.sync)) {
if DataStore.shared().shouldDisplay(.sync) {
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: self,
queue: OperationQueue.main)

9
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -16,8 +16,8 @@ class AppearanceViewController: ParentViewController {
@IBOutlet var includePlaceNameControl: NSSegmentedControl!
@IBOutlet var appearanceTab: NSTabView!
@IBOutlet var appDisplayControl: NSSegmentedControl!
@IBOutlet weak var syncLabel: NSTextField!
@IBOutlet var syncLabel: NSTextField!
private var themeDidChangeNotification: NSObjectProtocol?
private var previewTimezones: [TimezoneData] = []
@ -358,11 +358,10 @@ class AppearanceViewController: ParentViewController {
@IBAction func toggleDSTTransitionOption(_: Any) {
previewPanelTableView.reloadData()
}
@IBAction func toggleSync(_ sender: Any) {
@IBAction func toggleSync(_: Any) {
print("Toggle Sync")
}
}
extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate {

2
Clocker/Preferences/General/PreferencesViewController.swift

@ -93,7 +93,7 @@ class PreferencesViewController: ParentViewController {
name: NSNotification.Name.customLabelChanged,
object: nil)
if (DataStore.shared().shouldDisplay(.sync)) {
if DataStore.shared().shouldDisplay(.sync) {
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: self,
queue: OperationQueue.main)

6
Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift

@ -7,12 +7,12 @@ import EventKit
class MenubarTitleProvider: NSObject {
private let store: DataStore
init(with dataStore: DataStore) {
self.store = dataStore
store = dataStore
super.init()
}
func titleForMenubar() -> String? {
if let nextEvent = checkForUpcomingEvents() {
return nextEvent

2
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -256,7 +256,7 @@ class StatusItemHandler: NSObject {
// This will internally call `statusItemViewSetNeedsDisplay` on all subviews ensuring all text in the menubar is up-to-date.
statusContainerView?.updateTime()
}
private func removeUpcomingStatusItemView() {
NSAnimationContext.runAnimationGroup({ context in
context.duration = 0.2

Loading…
Cancel
Save