From 93c36cd25c8a75040ba49471413560bf830770d5 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Fri, 1 Apr 2022 21:51:38 -0400 Subject: [PATCH] Swiftformat. --- .../StandardMenubarHandlerTests.swift | 17 +++++++++-------- Clocker/Overall App/DataStore.swift | 8 ++++---- Clocker/Panel/ParentPanelController.swift | 4 ++-- .../Appearance/AppearanceViewController.swift | 9 ++++----- .../General/PreferencesViewController.swift | 2 +- .../Menu Bar/MenubarTitleProvider.swift | 6 +++--- .../Menu Bar/StatusItemHandler.swift | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift b/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift index 8d8c53e..1eae0a7 100644 --- a/Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift +++ b/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()) } diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 87ecf70..7cf5f40 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/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) diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index f2598f9..5fb0cbe 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/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) diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index bf0d79f..5730ff6 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/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 { diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 99920a8..c29f067 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/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) diff --git a/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift b/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift index 27070de..d88d7a5 100644 --- a/Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift +++ b/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 diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index 3ebed0f..693c785 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/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