Skip to content

Commit

Permalink
feat(ios): apply new swiftformat styles;
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1th committed Feb 16, 2024
1 parent ae2b608 commit 344fb35
Show file tree
Hide file tree
Showing 169 changed files with 478 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--swiftversion 5.3
--swiftversion 5.8

--exclude vendor,Pods,**/Swiftgen/**,**/Resources/**,fastlane,**/Assets/**

Expand Down
12 changes: 6 additions & 6 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension AppEnvironment {
}
}

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
@available(iOS, deprecated: 13.0)
var window: UIWindow? {
Expand Down Expand Up @@ -144,12 +144,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

@objc internal func openAbout() {
@objc func openAbout() {
precondition(Current.sceneManager.supportsMultipleScenes)
sceneManager.activateAnyScene(for: .about)
}

@objc internal func openMenuUrl(_ command: AnyObject) {
@objc func openMenuUrl(_ command: AnyObject) {
guard let command = command as? UICommand, let url = MenuManager.url(from: command) else {
return
}
Expand All @@ -160,18 +160,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

@objc internal func openPreferences() {
@objc func openPreferences() {
precondition(Current.sceneManager.supportsMultipleScenes)
sceneManager.activateAnyScene(for: .settings)
}

@objc internal func openActionsPreferences() {
@objc func openActionsPreferences() {
precondition(Current.sceneManager.supportsMultipleScenes)
let delegate: Guarantee<SettingsSceneDelegate> = sceneManager.scene(for: .init(activity: .settings))
delegate.done { $0.pushActions(animated: true) }
}

@objc internal func openHelp() {
@objc func openHelp() {
openURLInBrowser(
URL(string: "https://companion.home-assistant.io")!,
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public extension ClientEventTableViewController {
}

extension UITableView {
func applyChanges<T>(changes: RealmCollectionChange<T>) {
func applyChanges(changes: RealmCollectionChange<some Any>) {
switch changes {
case .initial: reloadData()
case let .update(_, deletions, insertions, updates):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
from row: RowOf<LocationHistoryDetailViewController>,
in direction: LocationHistoryDetailViewController.MoveDirection
) -> ButtonRowWithPresent<LocationHistoryDetailViewController>? {
guard let indexPath = row.indexPath, let section = section else {
guard let indexPath = row.indexPath, let section else {
return nil
}

Expand All @@ -94,7 +94,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
default: nextIndex = nil
}

if let nextIndex = nextIndex {
if let nextIndex {
return section[nextIndex] as? ButtonRowWithPresent<LocationHistoryDetailViewController>
} else {
return nil
Expand All @@ -112,7 +112,7 @@ extension LocationHistoryListViewController: LocationHistoryDetailMoveDelegate {
_ controller: LocationHistoryDetailViewController,
move direction: LocationHistoryDetailViewController.MoveDirection
) {
guard let navigationController = navigationController,
guard let navigationController,
let nextRow = row(from: controller.row, in: direction),
let nextController = nextRow.presentationMode?.makeController() else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati

override init() {
super.init()
syncStates = PerServerContainer<LocalPushStateSync>(constructor: { server in
self.syncStates = PerServerContainer<LocalPushStateSync>(constructor: { server in
let sync = LocalPushStateSync(settingsKey: PushProviderConfiguration.defaultSettingsKey(for: server))
let token = sync.observe { [weak self] _ in
self?.notifyObservers(for: [server])
Expand Down Expand Up @@ -93,7 +93,7 @@ final class NotificationManagerLocalPushInterfaceExtension: NSObject, Notificati
Current.Log.info("configuring push for \(ssid): \(servers)")

let existing = managers?.first(where: { $0.matchSSIDs == [ssid] })
if let existing = existing {
if let existing {
usedManagers.insert(existing)
}
updatedManagers.append(updateManager(
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/Onboarding/API/OnboardingAuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct OnboardingAuthError: LocalizedError {
extraInfo = nil
}

if let extraInfo = extraInfo {
if let extraInfo {
return extraInfo + "\n\n" + underlying.localizedDescription
} else {
return underlying.localizedDescription
Expand All @@ -101,7 +101,7 @@ struct OnboardingAuthError: LocalizedError {
}

var responseString: String? {
guard let data = data, let dataString = String(data: data, encoding: .utf8) else {
guard let data, let dataString = String(data: data, encoding: .utf8) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OnboardingAuthStepConnectivity: NSObject, OnboardingAuthPreStep, URLSessio
let (requestPromise, requestResolver) = Promise<(data: Data, response: URLResponse)>.pending()

let task = session.dataTask(with: authDetails.url) { data, response, error in
if let data = data, let response = response {
if let data, let response {
requestResolver.fulfill((data, response))
} else {
requestResolver.resolve(nil, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct OnboardingAuthStepDuplicate: OnboardingAuthPostStep {
handler: { [self] _ in
let name = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespaces)

guard let name = name, name.isEmpty == false,
guard let name, name.isEmpty == false,
!registeredDevices.contains(where: { $0.matches(name: name) }) else {
promptForDeviceName(
deviceName: deviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {

let alert = UIAlertController(
title: L10n.Onboarding.ManualSetup.CouldntMakeUrl.title,
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(self.urlField.text ?? ""),
message: L10n.Onboarding.ManualSetup.CouldntMakeUrl.message(urlField.text ?? ""),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: L10n.okLabel, style: UIAlertAction.Style.default, handler: nil))
Expand Down Expand Up @@ -266,7 +266,7 @@ class OnboardingManualURLViewController: UIViewController, UITextFieldDelegate {
}

@objc private func keyboardWillChangeFrame(_ note: Notification) {
guard let scrollView = scrollView,
guard let scrollView,
let frameValue = note.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {
return
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/App/Scenes/SceneManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SceneManager {
}
}

func resolve<T>(with possible: T) {
func resolve(with possible: some Any) {
handleBlock(possible)
}
}
Expand All @@ -77,13 +77,13 @@ class SceneManager {

init() {
Current.realmFatalPresentation = { [weak self] viewController in
guard let self = self else { return }
guard let self else { return }

let under = UIViewController()
under.view.backgroundColor = .black
under.modalPresentationStyle = .fullScreen

self.webViewWindowControllerPromise.done { parent in
webViewWindowControllerPromise.done { parent in
parent.present(under, animated: false, completion: {
under.present(viewController, animated: true, completion: nil)
})
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/Scenes/SettingsSceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
@objc class SettingsSceneDelegate: BasicSceneDelegate {
private var navigationController: UINavigationController? {
didSet {
if let navigationController = navigationController {
if let navigationController {
navigationController.delegate = self
update(navigationController: navigationController)
}
Expand Down Expand Up @@ -155,7 +155,7 @@ extension SettingsSceneDelegate: NSToolbarDelegate {
}

fileprivate func selectItemForIdentifier(_ identifier: NSToolbarItem.Identifier) {
if let viewController = viewController(for: identifier), let navigationController = navigationController {
if let viewController = viewController(for: identifier), let navigationController {
scene?.title = SettingsRootDataSource.buttonRows.first(where: { $0.tag == identifier.rawValue })?.title

// before, so it can be reset by the controller
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Scenes/WindowScenesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class WindowScenesManager {
}

// Create cascade effect so windows don't overlap
internal func adjustedSystemFrame(
func adjustedSystemFrame(
_ systemFrame: CGRect,
for screenSize: CGSize,
numberOfConnectedScenes: Int
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Servers/ServerSelectViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ServerSelectViewController: HAFormViewController, ServerObserver, UIAdapti
private func setupForm() {
form.removeAll()

if let prompt = prompt, !prompt.isEmpty {
if let prompt, !prompt.isEmpty {
form +++ InfoLabelRow {
$0.title = prompt
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/App/Settings/ActionConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {

self.isModalInPresentation = true

if let action = action {
if let action {
self.action = Action(value: action)
self.newAction = false
} else if let firstServer = Current.servers.all.first {
Expand Down Expand Up @@ -61,8 +61,8 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType {
guard let self else { return }
cell.backgroundColor = UIColor.clear
cell.preservesSuperviewLayoutMargins = false
self.updatePreviews()
cell.view = self.preview
updatePreviews()
cell.view = preview
}

let firstSection = Section()
Expand Down Expand Up @@ -367,7 +367,7 @@ class ActionPreview: UIView {
}

@objc func handleGesture(gesture: UITapGestureRecognizer) {
guard let action = action,
guard let action,
let server = Current.servers.server(forServerIdentifier: action.serverIdentifier) else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class ComplicationFamilySelectViewController: HAFormViewController, RowControlle

return ComplicationEditViewController(config: complication)
}, onDismiss: { [weak self] vc in
guard let self = self, let vc = vc as? ComplicationEditViewController else { return }
guard let self, let vc = vc as? ComplicationEditViewController else { return }

if vc.config.realm == nil {
// not saved
self.navigationController?.popViewController(animated: true)
navigationController?.popViewController(animated: true)
} else {
// saved
self.onDismissCallback?(self)
onDismissCallback?(self)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
let manager = Current.notificationManager.localPushManager

let updateValue = { [weak row, server] in
guard let row = row else { return }
guard let row else { return }
switch manager.status(for: server) {
case .disabled:
row.value = L10n.SettingsDetails.Notifications.LocalPush.Status.disabled
Expand Down Expand Up @@ -124,7 +124,7 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
var timer: Timer?

$0.onChange { [server] row in
if let timer = timer, timer.isValid {
if let timer, timer.isValid {
timer.fireDate = Current.date().addingTimeInterval(1.0)
} else {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
server.update { info in
info.connection.set(address: givenURL, for: urlType)

if let useCloud = useCloud {
if let useCloud {
info.connection.useCloud = useCloud
}

if let localPush = localPush {
if let localPush {
info.connection.isLocalPushEnabled = localPush
}

Expand Down Expand Up @@ -105,7 +105,7 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
return Current.webhooks.sendTest(server: server, baseURL: url)
}

if let givenURL = givenURL, useCloud != true {
if let givenURL, useCloud != true {
return Current.webhooks.sendTest(server: server, baseURL: givenURL)
}

Expand Down Expand Up @@ -299,7 +299,7 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
locationManager?.delegate = permissionDelegate

section.hidden = .function([], { _ in
if let locationManager = locationManager {
if let locationManager {
return locationManager.authorizationStatus == .authorizedAlways &&
locationManager.accuracyAuthorization == .fullAccuracy
} else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/App/Settings/DebugSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class DebugSettingsViewController: HAFormViewController {
cell.textLabel?.textAlignment = .natural
}
}.onCellSelection { [weak self] cell, _ in
guard let self = self else { return }
guard let self else { return }
Current.Log.export(from: self, sender: cell, openURLHandler: { url in
UIApplication.shared.open(url, options: [:], completionHandler: nil)
})
Expand All @@ -180,9 +180,9 @@ class DebugSettingsViewController: HAFormViewController {
$0.isDestructive = true
$0.title = L10n.Settings.ResetSection.ResetWebCache.title
$0.onCellSelection { [weak self] _, _ in
guard let self = self else { return }
guard let self else { return }

let hud = MBProgressHUD.showAdded(to: self.view.window ?? self.view, animated: true)
let hud = MBProgressHUD.showAdded(to: view.window ?? view, animated: true)
hud.backgroundView.backgroundColor = UIColor(white: 0.0, alpha: 0.5)

let (promise, seal) = Guarantee<Void>.pending()
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/Settings/Eureka/AccountInitialsImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ enum AccountInitialsImage {
// matching
// https://github.com/home-assistant/frontend/blob/42bf350034b7a53f0c6ba76791ea9d2a65bf6d67/src/components/user/ha-user-badge.ts

guard let string = string else {
guard let string else {
return "?"
}

Expand All @@ -24,7 +24,7 @@ enum AccountInitialsImage {
}

static func image(for name: String?, size: CGSize = Self.defaultSize) -> UIImage {
let initials = self.initials(for: name)
let initials = initials(for: name)

let rect = CGRect(origin: .zero, size: size)
let image = UIGraphicsImageRenderer(size: size).image { context in
Expand Down
Loading

0 comments on commit 344fb35

Please sign in to comment.