mirror of
https://github.com/mas-cli/mas
synced 2024-11-21 19:23:01 +00:00
Merge pull request #625 from rgoldberg/307-progress
Improve downloading output
This commit is contained in:
commit
031e0c30ed
5 changed files with 33 additions and 7 deletions
|
@ -28,7 +28,7 @@
|
|||
"NeverForceUnwrap": true,
|
||||
"NeverUseForceTry": true,
|
||||
"NeverUseImplicitlyUnwrappedOptionals": true,
|
||||
"NoAccessLevelOnExtensionDeclaration": true,
|
||||
"NoAccessLevelOnExtensionDeclaration": false,
|
||||
"NoAssignmentInExpressions": true,
|
||||
"NoBlockComments": true,
|
||||
"NoCasesWithOnlyFallthrough": true,
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
# Rule options
|
||||
--commas always
|
||||
--extensionacl on-declarations
|
||||
--hexliteralcase lowercase
|
||||
--importgrouping testable-last
|
||||
--lineaftermarks false
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"NeverForceUnwrap": false,
|
||||
"NeverUseForceTry": false,
|
||||
"NeverUseImplicitlyUnwrappedOptionals": true,
|
||||
"NoAccessLevelOnExtensionDeclaration": true,
|
||||
"NoAccessLevelOnExtensionDeclaration": false,
|
||||
"NoAssignmentInExpressions": true,
|
||||
"NoBlockComments": true,
|
||||
"NoCasesWithOnlyFallthrough": true,
|
||||
|
|
Loading…
Reference in a new issue