🐛 Allow redownloads on macOS 12

This commit is contained in:
Chris Araman 2021-11-03 13:50:58 -07:00
parent c7a104a250
commit a499822dd8
No known key found for this signature in database
GPG key ID: BB4499D9E11B61E0
2 changed files with 19 additions and 8 deletions

View file

@ -63,13 +63,21 @@ 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> {
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 {
storeAccount = account as? ISStoreAccount
guard storeAccount != nil else {
fatalError("Unable to cast StoreAccount to ISStoreAccount")
}
}
return Promise<SSPurchase> { seal in
let purchase = SSPurchase(adamId: appID, account: storeAccount, purchase: purchase)

View file

@ -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] = [
@ -40,8 +40,11 @@ extension SSPurchase {
.joined(separator: "&")
itemIdentifier = adamId
if let account = account {
accountIdentifier = account.dsID
appleID = account.identifier
}
// Not sure if this is needed, but lets use it here.
if purchase {