mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +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,
|
"NeverForceUnwrap": true,
|
||||||
"NeverUseForceTry": true,
|
"NeverUseForceTry": true,
|
||||||
"NeverUseImplicitlyUnwrappedOptionals": true,
|
"NeverUseImplicitlyUnwrappedOptionals": true,
|
||||||
"NoAccessLevelOnExtensionDeclaration": true,
|
"NoAccessLevelOnExtensionDeclaration": false,
|
||||||
"NoAssignmentInExpressions": true,
|
"NoAssignmentInExpressions": true,
|
||||||
"NoBlockComments": true,
|
"NoBlockComments": true,
|
||||||
"NoCasesWithOnlyFallthrough": true,
|
"NoCasesWithOnlyFallthrough": true,
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
# Rule options
|
# Rule options
|
||||||
--commas always
|
--commas always
|
||||||
--extensionacl on-declarations
|
|
||||||
--hexliteralcase lowercase
|
--hexliteralcase lowercase
|
||||||
--importgrouping testable-last
|
--importgrouping testable-last
|
||||||
--lineaftermarks false
|
--lineaftermarks false
|
||||||
|
|
|
@ -22,6 +22,7 @@ disabled_rules:
|
||||||
- function_body_length
|
- function_body_length
|
||||||
- inert_defer
|
- inert_defer
|
||||||
- legacy_objc_type
|
- legacy_objc_type
|
||||||
|
- no_extension_access_modifier
|
||||||
- no_grouping_extension
|
- no_grouping_extension
|
||||||
- number_separator
|
- number_separator
|
||||||
- one_declaration_per_file
|
- one_declaration_per_file
|
||||||
|
|
|
@ -9,11 +9,16 @@
|
||||||
import CommerceKit
|
import CommerceKit
|
||||||
import StoreFoundation
|
import StoreFoundation
|
||||||
|
|
||||||
|
private let downloadingPhase: Int64 = 0
|
||||||
|
private let installingPhase: Int64 = 1
|
||||||
|
private let downloadedPhase: Int64 = 5
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
let purchase: SSPurchase
|
let purchase: SSPurchase
|
||||||
var completionHandler: (() -> Void)?
|
var completionHandler: (() -> Void)?
|
||||||
var errorHandler: ((MASError) -> Void)?
|
var errorHandler: ((MASError) -> Void)?
|
||||||
|
var priorPhaseType: Int64?
|
||||||
|
|
||||||
init(purchase: SSPurchase) {
|
init(purchase: SSPurchase) {
|
||||||
self.purchase = purchase
|
self.purchase = purchase
|
||||||
|
@ -30,6 +35,21 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
if status.isFailed || status.isCancelled {
|
if status.isFailed || status.isCancelled {
|
||||||
queue.removeDownload(withItemIdentifier: download.metadata.itemIdentifier)
|
queue.removeDownload(withItemIdentifier: download.metadata.itemIdentifier)
|
||||||
} else {
|
} 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)
|
progress(status.progressState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +59,7 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clearLine()
|
clearLine()
|
||||||
printInfo("Downloading \(download.metadata.title)")
|
printInfo("Downloading \(download.progressDescription)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
|
func downloadQueue(_: CKDownloadQueue, changedWithRemoval download: SSDownload) {
|
||||||
|
@ -56,7 +76,7 @@ class PurchaseDownloadObserver: NSObject, CKDownloadQueueObserver {
|
||||||
} else if status.isCancelled {
|
} else if status.isCancelled {
|
||||||
errorHandler?(.cancelled)
|
errorHandler?(.cancelled)
|
||||||
} else {
|
} else {
|
||||||
printInfo("Installed \(download.metadata.title)")
|
printInfo("Installed \(download.progressDescription)")
|
||||||
completionHandler?()
|
completionHandler?()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +114,12 @@ func progress(_ state: ProgressState) {
|
||||||
fflush(stdout)
|
fflush(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension SSDownload {
|
||||||
|
var progressDescription: String {
|
||||||
|
"\(metadata.title) (\(metadata.bundleVersion ?? "unknown version"))"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension SSDownloadStatus {
|
extension SSDownloadStatus {
|
||||||
var progressState: ProgressState {
|
var progressState: ProgressState {
|
||||||
ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription)
|
ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription)
|
||||||
|
@ -103,9 +129,9 @@ extension SSDownloadStatus {
|
||||||
extension SSDownloadPhase {
|
extension SSDownloadPhase {
|
||||||
var phaseDescription: String {
|
var phaseDescription: String {
|
||||||
switch phaseType {
|
switch phaseType {
|
||||||
case 0:
|
case downloadingPhase:
|
||||||
return "Downloading"
|
return "Downloading"
|
||||||
case 1:
|
case installingPhase:
|
||||||
return "Installing"
|
return "Installing"
|
||||||
default:
|
default:
|
||||||
return "Waiting"
|
return "Waiting"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"NeverForceUnwrap": false,
|
"NeverForceUnwrap": false,
|
||||||
"NeverUseForceTry": false,
|
"NeverUseForceTry": false,
|
||||||
"NeverUseImplicitlyUnwrappedOptionals": true,
|
"NeverUseImplicitlyUnwrappedOptionals": true,
|
||||||
"NoAccessLevelOnExtensionDeclaration": true,
|
"NoAccessLevelOnExtensionDeclaration": false,
|
||||||
"NoAssignmentInExpressions": true,
|
"NoAssignmentInExpressions": true,
|
||||||
"NoBlockComments": true,
|
"NoBlockComments": true,
|
||||||
"NoCasesWithOnlyFallthrough": true,
|
"NoCasesWithOnlyFallthrough": true,
|
||||||
|
|
Loading…
Reference in a new issue