diff --git a/App/AppStore/Downloader.swift b/App/AppStore/Downloader.swift index 63efa86..86b0599 100644 --- a/App/AppStore/Downloader.swift +++ b/App/AppStore/Downloader.swift @@ -13,7 +13,7 @@ func download(_ adamId: UInt64) -> MASError? { } let group = DispatchGroup() - let purchase = SSPurchase(adamId: adamId, account: account) + let purchase = SSPurchase(adamId: adamId, account: account as! ISStoreAccount) var purchaseError: MASError? var observerIdentifier: CKDownloadQueueObserver? = nil diff --git a/App/AppStore/ISStoreAccount.swift b/App/AppStore/ISStoreAccount.swift index 57f513e..180e554 100644 --- a/App/AppStore/ISStoreAccount.swift +++ b/App/AppStore/ISStoreAccount.swift @@ -6,12 +6,12 @@ // Copyright (c) 2015 Andrew Naylor. All rights reserved. // -extension ISStoreAccount { +extension ISStoreAccount: StoreAccount { static var primaryAccountIsPresentAndSignedIn: Bool { return CKAccountStore.shared().primaryAccountIsPresentAndSignedIn } - static var primaryAccount: ISStoreAccount? { + static var primaryAccount: StoreAccount? { var account: ISStoreAccount? if #available(macOS 10.13, *) { @@ -34,7 +34,7 @@ extension ISStoreAccount { return account } - static func signIn(username: String, password: String, systemDialog: Bool = false) throws -> ISStoreAccount { + static func signIn(username: String, password: String, systemDialog: Bool = false) throws -> StoreAccount { var account: ISStoreAccount? = nil var error: MASError? = nil diff --git a/App/AppStore/StoreAccount.swift b/App/AppStore/StoreAccount.swift new file mode 100644 index 0000000..be945ab --- /dev/null +++ b/App/AppStore/StoreAccount.swift @@ -0,0 +1,15 @@ +// +// StoreAccount.swift +// mas-cli +// +// Created by Ben Chatelain on 4/3/18. +// Copyright © 2018 Andrew Naylor. All rights reserved. +// + +protocol StoreAccount { + static var primaryAccountIsPresentAndSignedIn: Bool { get } + static var primaryAccount: StoreAccount? { get } + static func signIn(username: String?, password: String?, systemDialog: Bool) throws -> StoreAccount + + var identifier: String! { get set } +} diff --git a/App/Commands/Account.swift b/App/Commands/Account.swift index 9bfe4c6..d75a9de 100644 --- a/App/Commands/Account.swift +++ b/App/Commands/Account.swift @@ -16,7 +16,7 @@ struct AccountCommand: CommandProtocol { func run(_ options: Options) -> Result<(), MASError> { if let account = ISStoreAccount.primaryAccount { - print(account.identifier) + print(String(describing: account.identifier)) } else { print("Not signed in") diff --git a/mas-cli.xcodeproj/project.pbxproj b/mas-cli.xcodeproj/project.pbxproj index 9c07568..6f03042 100644 --- a/mas-cli.xcodeproj/project.pbxproj +++ b/mas-cli.xcodeproj/project.pbxproj @@ -42,6 +42,10 @@ EDE296531C700F4300554778 /* SignOut.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDE296521C700F4300554778 /* SignOut.swift */; }; EDEAA0C01B51CE6200F2FC3F /* StoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA0BF1B51CE6200F2FC3F /* StoreFoundation.framework */; }; EDEAA17D1B5C579100F2FC3F /* CommerceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */; }; + F184B6B7CD9C013CACDED0FB /* Argument.swift in Sources */ = {isa = PBXBuildFile; fileRef = F36A4ABD8025E13060312925 /* Argument.swift */; }; + F48562FA81B0C0258AC063B4 /* HelpCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FDC2B8063EC231E28353D23 /* HelpCommand.swift */; }; + F6D2058A70757D3477185A50 /* Option.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD7FE171F643805F7BC38A7 /* Option.swift */; }; + F8242D8120746A510026DF35 /* StoreAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8242D8020746A510026DF35 /* StoreAccount.swift */; }; F865880B2030F6DE0093DE57 /* MASErrorTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F865880A2030F6DE0093DE57 /* MASErrorTestCase.swift */; }; F86588272030FAE70093DE57 /* MASError.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED0F238C1B8756E600AE40CD /* MASError.swift */; }; /* End PBXBuildFile section */ @@ -175,6 +179,7 @@ EDEAA17C1B5C579100F2FC3F /* CommerceKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CommerceKit.framework; path = /System/Library/PrivateFrameworks/CommerceKit.framework; sourceTree = ""; }; F8233C87201EBDF000268278 /* mas-tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "mas-tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; F8233C8B201EBDF100268278 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + F8242D8020746A510026DF35 /* StoreAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreAccount.swift; sourceTree = ""; }; F865880A2030F6DE0093DE57 /* MASErrorTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MASErrorTestCase.swift; sourceTree = ""; }; F86EBF2E2077214100C0976E /* ISStoreURLOperationDelegate-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ISStoreURLOperationDelegate-Protocol.h"; sourceTree = ""; }; F876300720438AF2003D370B /* ISAuthenticationResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ISAuthenticationResponse.h; sourceTree = ""; }; @@ -285,6 +290,7 @@ ED0F238F1B87A56F00AE40CD /* ISStoreAccount.swift */, ED0F23881B87543D00AE40CD /* PurchaseDownloadObserver.swift */, EDA3BE511B8B84AF00C18D70 /* SSPurchase.swift */, + F8242D8020746A510026DF35 /* StoreAccount.swift */, ); path = AppStore; sourceTree = ""; @@ -475,6 +481,9 @@ ED0F23851B87536A00AE40CD /* Outdated.swift in Sources */, ED0F23891B87543D00AE40CD /* PurchaseDownloadObserver.swift in Sources */, EDCBF9531D89AC6F000039C6 /* Reset.swift in Sources */, + F8242D8120746A510026DF35 /* StoreAccount.swift in Sources */, + 0EBF5CDD379D7462C3389536 /* Result.swift in Sources */, + 09756A23E9102359296C821B /* ResultProtocol.swift in Sources */, 693A98991CBFFA760004D3B4 /* Search.swift in Sources */, EDC90B651C70045E0019E396 /* SignIn.swift in Sources */, EDE296531C700F4300554778 /* SignOut.swift in Sources */,