Skip to content

Commit

Permalink
🐛 Allow redownloads on macOS 12
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-araman committed Nov 3, 2021
1 parent c7a104a commit a499822
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 13 additions & 5 deletions Sources/MasKit/AppStore/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,20 @@ private func downloadWithRetries(
/// Only works for free apps. Defaults to false.
/// - Returns: A promise the completes when the download is complete.
private func download(_ appID: UInt64, purchase: Bool = false) -> Promise<Void> {
guard let account = ISStoreAccount.primaryAccount else {
return Promise(error: MASError.notSignedIn)
}
var storeAccount: ISStoreAccount?
if #available(macOS 12, *) {
// Monterey obscured the user's account information, but still allows
// redownloads without passing it to SSPurchase.
// https://github.com/mas-cli/mas/issues/417
} else {
guard let account = ISStoreAccount.primaryAccount else {
return Promise(error: MASError.notSignedIn)
}

guard let storeAccount = account as? ISStoreAccount else {
fatalError("Unable to cast StoreAccount to ISStoreAccount")
storeAccount = account as? ISStoreAccount
guard storeAccount != nil else {
fatalError("Unable to cast StoreAccount to ISStoreAccount")
}
}

return Promise<SSPurchase> { seal in
Expand Down
9 changes: 6 additions & 3 deletions Sources/MasKit/AppStore/SSPurchase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typealias SSPurchaseCompletion =
(_ purchase: SSPurchase?, _ completed: Bool, _ error: Error?, _ response: SSPurchaseResponse?) -> Void

extension SSPurchase {
convenience init(adamId: UInt64, account: ISStoreAccount, purchase: Bool = false) {
convenience init(adamId: UInt64, account: ISStoreAccount?, purchase: Bool = false) {
self.init()

var parameters: [String: Any] = [
Expand All @@ -40,8 +40,11 @@ extension SSPurchase {
.joined(separator: "&")

itemIdentifier = adamId
accountIdentifier = account.dsID
appleID = account.identifier

if let account = account {
accountIdentifier = account.dsID
appleID = account.identifier
}

// Not sure if this is needed, but lets use it here.
if purchase {
Expand Down

0 comments on commit a499822

Please # to comment.