Eliminate magic numbers.

Partial #592

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
Ross Goldberg 2024-10-21 08:58:18 -04:00
parent fcf8ba29f6
commit ee28af69df
No known key found for this signature in database
3 changed files with 9 additions and 4 deletions

View file

@ -10,6 +10,8 @@ import CommerceKit
import PromiseKit import PromiseKit
import StoreFoundation import StoreFoundation
private let timeout = 30.0
extension ISStoreAccount: StoreAccount { extension ISStoreAccount: StoreAccount {
static var primaryAccount: Promise<ISStoreAccount> { static var primaryAccount: Promise<ISStoreAccount> {
if #available(macOS 10.13, *) { if #available(macOS 10.13, *) {
@ -20,7 +22,7 @@ extension ISStoreAccount: StoreAccount {
seal.fulfill(storeAccount) seal.fulfill(storeAccount)
} }
}, },
after(seconds: 30) after(seconds: timeout)
.then { .then {
Promise(error: MASError.notSignedIn) Promise(error: MASError.notSignedIn)
} }
@ -79,7 +81,7 @@ extension ISStoreAccount: StoreAccount {
return race( return race(
signInPromise, signInPromise,
after(seconds: 30) after(seconds: timeout)
.then { .then {
Promise(error: MASError.signInFailed(error: nil)) Promise(error: MASError.signInFailed(error: nil))
} }

View file

@ -65,6 +65,7 @@ struct ProgressState {
let phase: String let phase: String
var percentage: String { var percentage: String {
// swiftlint:disable:next no_magic_numbers
String(format: "%.1f%%", floor(percentComplete * 1000) / 10) String(format: "%.1f%%", floor(percentComplete * 1000) / 10)
} }
} }

View file

@ -17,8 +17,10 @@ enum SearchResultFormatter {
/// - includePrice: Indicates whether to include prices in the output /// - includePrice: Indicates whether to include prices in the output
/// - Returns: Multiline text output. /// - Returns: Multiline text output.
static func format(results: [SearchResult], includePrice: Bool = false) -> String { static func format(results: [SearchResult], includePrice: Bool = false) -> String {
// find longest appName for formatting, default 50 guard let maxLength = results.map(\.trackName.count).max() else {
let maxLength = results.map(\.trackName.count).max() ?? 50 return ""
}
var output = "" var output = ""
for result in results { for result in results {