Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions App/AppStore/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func download(_ adamId: UInt64) -> MASError? {
let purchase = SSPurchase(adamId: adamId, account: account)

var purchaseError: MASError?
var observerIdentifier: Any? = nil
var observerIdentifier: CKDownloadQueueObserver? = nil

group.enter()
purchase.perform { purchase, _, error, response in
Expand All @@ -39,7 +39,7 @@ func download(_ adamId: UInt64) -> MASError? {
}

let downloadQueue = CKDownloadQueue.shared()
observerIdentifier = downloadQueue?.add(observer)
observerIdentifier = downloadQueue.add(observer)
}
else {
print("No downloads")
Expand All @@ -51,7 +51,7 @@ func download(_ adamId: UInt64) -> MASError? {
let _ = group.wait(timeout: .distantFuture)

if let observerIdentifier = observerIdentifier {
CKDownloadQueue.shared().removeObserver(observerIdentifier)
CKDownloadQueue.shared().remove(observerIdentifier)
}

return purchaseError
Expand Down
23 changes: 12 additions & 11 deletions App/AppStore/ISStoreAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ extension ISStoreAccount {
static var primaryAccountIsPresentAndSignedIn: Bool {
return CKAccountStore.shared().primaryAccountIsPresentAndSignedIn
}

static var primaryAccount: ISStoreAccount? {
return CKAccountStore.shared().primaryAccount
}
static func signIn(username: String? = nil, password: String? = nil, systemDialog: Bool = false) throws -> ISStoreAccount {

static func signIn(username: String, password: String, systemDialog: Bool = false) throws -> ISStoreAccount {
var account: ISStoreAccount? = nil
var error: MASError? = nil
let accountService = ISServiceProxy.genericShared().accountService

let accountService: ISAccountService = ISServiceProxy.genericShared().accountService
let client = ISStoreClient(storeClientType: 0)
accountService.setStoreClient(client)
let context = ISAuthenticationContext(accountID: 0)!

let context = ISAuthenticationContext(accountID: 0)
context.appleIDOverride = username

if systemDialog {
context.appleIDOverride = username
} else {
Expand All @@ -34,10 +34,11 @@ extension ISStoreAccount {
context.demoAccountPassword = password
context.demoAutologinMode = true
}

let group = DispatchGroup()
group.enter()


// Only works on macOS Sierra and below
accountService.signIn(with: context) { success, _account, _error in
if success {
account = _account
Expand All @@ -46,7 +47,7 @@ extension ISStoreAccount {
}
group.leave()
}

if systemDialog {
group.wait()
} else {
Expand Down
13 changes: 4 additions & 9 deletions App/AppStore/PurchaseDownloadObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
if status.isFailed || status.isCancelled {
queue.removeDownload(withItemIdentifier: download.metadata.itemIdentifier)
}
else if let state = status.progressState {
progress(state)
else {
progress(status.progressState)
}
}

Expand Down Expand Up @@ -90,13 +90,8 @@ func progress(_ state: ProgressState) {
}

extension SSDownloadStatus {
var progressState: ProgressState? {
if let phase = activePhase {
return ProgressState(percentComplete: percentComplete, phase: phase.phaseDescription)
}
else {
return nil
}
var progressState: ProgressState {
return ProgressState(percentComplete: percentComplete, phase: activePhase.phaseDescription)
}
}

Expand Down
20 changes: 12 additions & 8 deletions App/Commands/SignIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ struct SignInCommand: CommandProtocol {
typealias Options = SignInOptions
let verb = "signin"
let function = "Sign in to the Mac App Store"

func run(_ options: Options) -> Result<(), MASError> {


if #available(macOS 10.13, *) {
return .failure(.signInDisabled)
}

guard ISStoreAccount.primaryAccount == nil else {
return .failure(.alreadySignedIn)
}

do {
printInfo("Signing in to Apple ID: \(options.username)")

Expand All @@ -42,17 +46,17 @@ struct SignInCommand: CommandProtocol {
struct SignInOptions: OptionsProtocol {
let username: String
let password: String
let dialog: Bool

let dialog: Bool

typealias ClientError = MASError

static func create(username: String) -> (_ password: String) -> (_ dialog: Bool) -> SignInOptions {
return { password in { dialog in
return SignInOptions(username: username, password: password, dialog: dialog)
}}
}

static func evaluate(_ m: CommandMode) -> Result<SignInOptions, CommandantError<MASError>> {
return create
<*> m <| Argument(usage: "Apple ID")
Expand Down
11 changes: 10 additions & 1 deletion App/Commands/SignOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ struct SignOutCommand: CommandProtocol {
let function = "Sign out of the Mac App Store"

func run(_ options: Options) -> Result<(), MASError> {
CKAccountStore.shared().signOut()
if #available(macOS 10.13, *) {
let accountService: ISAccountService = ISServiceProxy.genericShared().accountService
accountService.signOut()
}
else {
// Using CKAccountStore to sign out does nothing on High Sierra
// https://github.com/mas-cli/mas/issues/129
CKAccountStore.shared().signOut()
}

return .success(())
}
}
26 changes: 16 additions & 10 deletions App/MASError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,38 @@ import Foundation

enum MASError: Error, CustomStringConvertible {
case notSignedIn
case signInDisabled
case signInFailed(error: NSError?)
case alreadySignedIn

case purchaseFailed(error: NSError?)
case downloadFailed(error: NSError?)
case noDownloads
case cancelled

case searchFailed
case noSearchResultsFound

var description: String {
switch self {
case .notSignedIn:
return "Not signed in"


case .signInDisabled:
return "The 'signin' command has been disabled on this macOS version. " +
"\nFor more info see: " +
"https://github.com/mas-cli/mas/pull/162"

case .signInFailed(let error):
if let error = error {
return "Sign in failed: \(error.localizedDescription)"
} else {
return "Sign in failed"
}

case .alreadySignedIn:
return "Already signed in"

case .purchaseFailed(let error):
if let error = error {
return "Download request failed: \(error.localizedDescription)"
Expand All @@ -49,16 +55,16 @@ enum MASError: Error, CustomStringConvertible {
} else {
return "Download failed"
}

case .noDownloads:
return "No downloads began"

case .cancelled:
return "Download cancelled"

case .searchFailed:
return "Search failed"

case .noSearchResultsFound:
return "No results found"
}
Expand Down
60 changes: 47 additions & 13 deletions App/PrivateHeaders/CommerceKit/CKAccountStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,68 @@
// class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard.
//

#import <CommerceKit/CKServiceInterface.h>
// #import "NSObject.h"

#import "ISStoreURLOperationDelegate-Protocol.h"
#import <CommerceKit/CKServiceInterface.h>

@class CKDemoAccount, CKStoreAccount, CKStoreClient, ISStoreAccount, NSArray;

@class NSString;

@class ISStoreAccount, NSArray, NSString;
NS_ASSUME_NONNULL_BEGIN

@interface CKAccountStore : CKServiceInterface <ISStoreURLOperationDelegate>
@interface CKAccountStore : NSObject
{

// CKStoreClient *_storeClient;

}

+ (CKAccountStore *)sharedAccountStore;
- (void)removePrimaryAccountObserver:(id)arg1;
//- (id)addPrimaryAccountObserverWithBlock:(CDUnknownBlockType)arg1;
//- (void)updatePasswordSettings:(id)arg1 completionBlock:(CDUnknownBlockType)arg2;
//- (void)getPasswordSettingsWithCompletionBlock:(CDUnknownBlockType)arg1;
//- (void)getEligibilityForService:(long long)arg1 completionBlock:(CDUnknownBlockType)arg2;

+ (id)accountStoreForStoreClient:(id)arg1;
@property(readonly) CKStoreClient *storeClient; // @synthesize storeClient=_storeClient;

// - (void).cxx_destruct;
// - (void)getTouchIDStateForAccount:(id)arg1 completionBlock:(CDUnknownBlockType)arg2;
// - (void)setTouchIDStateForAccount:(id)arg1 state:(long long)arg2 completionBlock:(CDUnknownBlockType)arg3;
// - (void)updatePasswordSettings:(id)arg1 completionBlock:(CDUnknownBlockType)arg2;
// - (void)getPasswordSettingsWithCompletionBlock:(CDUnknownBlockType)arg1;
// - (void)getEligibilityForService:(long long)arg1 completionBlock:(CDUnknownBlockType)arg2;

- (id)eligibilityForService:(long long)arg1;
- (void)signOut;
- (void)viewAccount;
- (void)signIn;

//- (void)signInWithSuggestedAppleID:(id)arg1 allowChangeOfAppleID:(BOOL)arg2 completionHandler:(CDUnknownBlockType)arg3;

- (void)signIn;

- (void)addAccount:(id)arg1;
@property(readonly) NSArray *accounts;
- (id)accountWithAppleID:(id)arg1;
- (id)accountForDSID:(id)arg1;
@property(readonly) BOOL primaryAccountIsPresentAndSignedIn;
@property(readonly) ISStoreAccount *primaryAccount;
@property(readonly) NSArray *accounts;
- (id)init;
- (void)removePrimaryAccountObserver:(id)arg1;

// - (id)addPrimaryAccountObserverWithBlock:(CDUnknownBlockType)arg1;

- (id)initWithStoreClient:(id)arg1;
- (void)removeAccountObserver:(id)arg1;
- (id)addAccountObserver:(id)arg1;

// - (void)signOutWithCompletionHandler:(CDUnknownBlockType)arg1;

- (void)signOut;
- (id)storeAccountForAppleID:(id)arg1;
- (id)storeAccountForDSID:(id)arg1;
@property(readonly) BOOL primaryAccountIsPresentAndSignedIn;
@property(readonly) CKStoreAccount *primaryStoreAccount;
@property(readonly) CKDemoAccount *demoAccount;
@property(readonly) BOOL isDemoModeEnabled;
@property(readonly) NSArray *knownAccounts;
- (id)_initWithStoreClient:(id)arg1;

@end

NS_ASSUME_NONNULL_END
30 changes: 23 additions & 7 deletions App/PrivateHeaders/CommerceKit/CKDownloadQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,52 @@

#import <CommerceKit/CKServiceInterface.h>

@class NSArray, NSLock, NSMutableDictionary, CKDownloadQueueClient;
@class CKDownloadQueueClient, NSArray, NSLock, NSMutableDictionary;

@protocol CKDownloadQueueObserver;

NS_ASSUME_NONNULL_BEGIN

@interface CKDownloadQueue : CKServiceInterface
{
NSMutableDictionary *_downloadsByItemID;
NSLock *_downloadsLock;
NSMutableDictionary *_downloadQueueObservers;
CKDownloadQueueClient *_sharedObserver;
}

+ (CKDownloadQueue *)sharedDownloadQueue;
+ (instancetype)sharedDownloadQueue;

@property(retain, nonatomic) CKDownloadQueueClient *sharedObserver; // @synthesize sharedObserver=_sharedObserver;
@property(retain, nonatomic) NSMutableDictionary *downloadQueueObservers; // @synthesize downloadQueueObservers=_downloadQueueObservers;

//- (void).cxx_destruct;

- (BOOL)cacheReceiptDataForDownload:(id)arg1;
- (void)checkStoreDownloadQueueForAccount:(id)arg1;
- (void)recoverAvailableDiskSpace;
- (void)lockedApplicationTriedToLaunchAtPath:(id)arg1;
- (void)unlockApplicationsWithBundleIdentifier:(id)arg1;
- (void)lockApplicationsForBundleID:(id)arg1;
- (void)performedIconAnimationForDownloadWithIdentifier:(unsigned long long)arg1;

//- (void)fetchIconForItemIdentifier:(unsigned long long)arg1 atURL:(id)arg2 replyBlock:(CDUnknownBlockType)arg3;

- (void)removeDownloadWithItemIdentifier:(unsigned long long)arg1;
- (void)cancelDownload:(id)arg1 promptToConfirm:(BOOL)arg2 askToDelete:(BOOL)arg3;
- (void)resumeDownloadWithItemIdentifier:(unsigned long long)arg1;
- (void)pauseDownloadWithItemIdentifier:(unsigned long long)arg1;
- (void)addDownload:(id)arg1;
- (id)downloadForItemIdentifier:(unsigned long long)arg1;
@property(readonly, nonatomic) NSArray *downloads; // @dynamic downloads;
- (void)removeObserver:(id)arg1;
- (id)addObserver:(id<CKDownloadQueueObserver>)arg1;
- (id)addObserver:(id)arg1 forDownloadTypes:(long long)arg2;
//- (id)addObserverForDownloadTypes:(long long)arg1 withBlock:(CDUnknownBlockType)arg2;
- (void)removeObserver:(id<CKDownloadQueueObserver>)arg1;
- (id<CKDownloadQueueObserver>)addObserver:(id<CKDownloadQueueObserver>)arg1;
- (id<CKDownloadQueueObserver>)addObserver:(id<CKDownloadQueueObserver>)arg1 forDownloadTypes:(long long)arg2;

// - (id)addObserverForDownloadTypes:(long long)arg1 withBlock:(CDUnknownBlockType)arg2;

- (void)connectionWasInterrupted;
- (id)initWithStoreClient:(id)arg1;

@end

NS_ASSUME_NONNULL_END
Loading