diff --git a/.swift-format b/.swift-format index 693d879..2f15f28 100644 --- a/.swift-format +++ b/.swift-format @@ -28,7 +28,7 @@ "NeverForceUnwrap": true, "NeverUseForceTry": true, "NeverUseImplicitlyUnwrappedOptionals": true, - "NoAccessLevelOnExtensionDeclaration": true, + "NoAccessLevelOnExtensionDeclaration": false, "NoAssignmentInExpressions": true, "NoBlockComments": true, "NoCasesWithOnlyFallthrough": true, diff --git a/.swiftformat b/.swiftformat index 9089de8..d9ca163 100644 --- a/.swiftformat +++ b/.swiftformat @@ -31,7 +31,6 @@ # Rule options --commas always ---extensionacl on-declarations --hexliteralcase lowercase --importgrouping testable-last --lineaftermarks false diff --git a/.swiftlint.yml b/.swiftlint.yml index 3d19626..8457f4e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -22,6 +22,7 @@ disabled_rules: - function_body_length - inert_defer - legacy_objc_type +- no_extension_access_modifier - no_grouping_extension - number_separator - one_declaration_per_file diff --git a/Sources/mas/AppStore/PurchaseDownloadObserver.swift b/Sources/mas/AppStore/PurchaseDownloadObserver.swift index 30b968c..fa3e9e7 100644 --- a/Sources/mas/AppStore/PurchaseDownloadObserver.swift +++ b/Sources/mas/AppStore/PurchaseDownloadObserver.swift @@ -9,11 +9,16 @@ import CommerceKit import StoreFoundation +private let downloadingPhase: Int64 = 0 +private let installingPhase: Int64 = 1 +private let downloadedPhase: Int64 = 5 + @objc class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver { let purchase: SSPurchase var completionHandler: (() -> Void)? var errorHandler: ((MASError) -> Void)? + var priorPhaseType: Int64? init(purchase: SSPurchase) { self.purchase = purchase @@ -30,6 +35,21 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver { if status.isFailed || status.isCancelled { queue.removeDownload(withItemIdentifier: download.metadata.itemIdentifier) } else { + if priorPhaseType != status.activePhase.phaseType { + switch status.activePhase.phaseType { + case downloadedPhase: + if priorPhaseType == downloadingPhase { + clearLine() + printInfo("Downloaded \(download.progressDescription)") + } + case installingPhase: + clearLine() + printInfo("Installing \(download.progressDescription)") + default: + break + } + priorPhaseType = status.activePhase.phaseType + } progress(status.progressState) } } @@ -39,7 +59,7 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver { return } clearLine() - printInfo("Downloading \(download.metadata.title)") + printInfo("Downloading \(download.progressDescription)") } func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) { @@ -56,7 +76,7 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver { } else if status.isCancelled { errorHandler?(.cancelled) } else { - printInfo("Installed \(download.metadata.title)") + printInfo("Installed \(download.progressDescription)") completionHandler?() } } @@ -94,6 +114,12 @@ func progress(_ state: ProgressState) { fflush(stdout) } +private extension SSDownload { + var progressDescription: String { + "\(metadata.title) (\(metadata.bundleVersion ?? "unknown version"))" + } +} + extension SSDownloadStatus { var progressState: ProgressState { ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription) @@ -103,9 +129,9 @@ extension SSDownloadStatus { extension SSDownloadPhase { var phaseDescription: String { switch phaseType { - case 0: + case downloadingPhase: return "Downloading" - case 1: + case installingPhase: return "Installing" default: return "Waiting" diff --git a/Tests/masTests/.swift-format b/Tests/masTests/.swift-format index 571f02f..9f8e2f7 100644 --- a/Tests/masTests/.swift-format +++ b/Tests/masTests/.swift-format @@ -28,7 +28,7 @@ "NeverForceUnwrap": false, "NeverUseForceTry": false, "NeverUseImplicitlyUnwrappedOptionals": true, - "NoAccessLevelOnExtensionDeclaration": true, + "NoAccessLevelOnExtensionDeclaration": false, "NoAssignmentInExpressions": true, "NoBlockComments": true, "NoCasesWithOnlyFallthrough": true,