diff --git a/SwiftDiscogs.xcodeproj/project.pbxproj b/SwiftDiscogs.xcodeproj/project.pbxproj index 7824e7d..7a6f8bb 100644 --- a/SwiftDiscogs.xcodeproj/project.pbxproj +++ b/SwiftDiscogs.xcodeproj/project.pbxproj @@ -82,6 +82,7 @@ 96226AFB2069FF3D000EEC50 /* DiscogsArtistViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96226AF62069F578000EEC50 /* DiscogsArtistViewController.swift */; }; 96226AFD2069FF3D000EEC50 /* DiscogsArtistModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969ADA6D2068A7D300A8BDD0 /* DiscogsArtistModel.swift */; }; 96226AFE2069FF3D000EEC50 /* DiscogsSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9603690E205A1C7200D24CE7 /* DiscogsSearchViewController.swift */; }; + 962833382898E33E00F7ABA2 /* Medi8 in Frameworks */ = {isa = PBXBuildFile; productRef = 962833372898E33E00F7ABA2 /* Medi8 */; }; 963282B2222CBAD90090B29F /* SectionedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282B1222CBAD90090B29F /* SectionedModel.swift */; }; 963282B9222CD7E40090B29F /* MasterReleaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282B8222CD7E40090B29F /* MasterReleaseViewController.swift */; }; 963282BD222F82A10090B29F /* TrackTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963282BC222F82A10090B29F /* TrackTableCell.swift */; }; @@ -515,6 +516,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 962833382898E33E00F7ABA2 /* Medi8 in Frameworks */, 968102072272BA20003E6D82 /* SwiftDiscogs.framework in Frameworks */, 96E7CE4B25EB64EE00EBC43E /* UIKit.framework in Frameworks */, ); @@ -1143,6 +1145,7 @@ ); name = SwiftDiscogsApp; packageProductDependencies = ( + 962833372898E33E00F7ABA2 /* Medi8 */, ); productName = SwiftDiscogsApp; productReference = 960368DA205A012B00D24CE7 /* SwiftDiscogsApp.app */; @@ -1816,6 +1819,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 3MY7LL9G36; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = SwiftDiscogsApp/Info.plist; @@ -1837,6 +1841,7 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 3MY7LL9G36; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = SwiftDiscogsApp/Info.plist; @@ -2405,13 +2410,18 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/jrtibbetts/JSONClient"; requirement = { - kind = upToNextMinorVersion; - minimumVersion = 3.0.0; + branch = main; + kind = branch; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 962833372898E33E00F7ABA2 /* Medi8 */ = { + isa = XCSwiftPackageProductDependency; + package = 969EBFB425EA2F940008DE91 /* XCRemoteSwiftPackageReference "Medi8" */; + productName = Medi8; + }; 969EBFB825EA2FD00008DE91 /* JSONClient */ = { isa = XCSwiftPackageProductDependency; package = 969EBFB725EA2FD00008DE91 /* XCRemoteSwiftPackageReference "JSONClient" */; diff --git a/SwiftDiscogs.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/SwiftDiscogs.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 89c6da7..52058eb 100644 --- a/SwiftDiscogs.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/SwiftDiscogs.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/jrtibbetts/JSONClient", "state" : { - "branch" : "28-replace-promisekit-with-async-await", - "revision" : "111fa2050dc17cec670445389c728183ca336f41" + "branch" : "main", + "revision" : "ca1e1883972b85a6720bc829c86839d87553305c" } }, { diff --git a/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift b/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift index 9ba4c78..ad56b57 100644 --- a/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift +++ b/SwiftDiscogsApp/Artist/DiscogsArtistViewController.swift @@ -35,7 +35,9 @@ public class DiscogsArtistViewController: UIViewController { public var artistSearchResult: SearchResult? { didSet { if let artistId = artistSearchResult?.id { - artist = try? await DiscogsManager.discogs.artist(identifier: artistId) + Task { + artist = try await DiscogsManager.discogs.artist(identifier: artistId) + } } } } @@ -77,9 +79,11 @@ public class DiscogsArtistViewController: UIViewController { func fetchArtist(named artistName: String) { Task { do { - let results = try async DiscogsManager.discogs.search(forArtist: artistName) - .filter { $0.type == "artist" } { - handleArtistResults(results) + try await DiscogsManager.discogs.search(forArtist: artistName) + .results? + .filter { $0.type == "artist" } + .forEach { + handleArtistResults([$0]) } } catch { presentAlert(for: error) @@ -135,13 +139,13 @@ public class DiscogsArtistViewController: UIViewController { return } - DiscogsManager.discogs.releases(forArtist: artistId).done { [weak self] (summaries) in - self?.artistModel.releases = summaries.releases?.filter { $0.type == "master" + Task { + let summaries = try await DiscogsManager.discogs.releases(forArtist: artistId) + + artistModel.releases = summaries.releases?.filter { $0.type == "master" && $0.role == "Main" && $0.mainRelease != nil } - self?.artistView.refresh() - }.catch { _ in - // HANDLE THE ERROR + artistView.refresh() } } diff --git a/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift b/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift index ebc4009..4c824a2 100644 --- a/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift +++ b/SwiftDiscogsApp/Release/ReleaseVersionViewController.swift @@ -14,9 +14,8 @@ class ReleaseVersionViewController: BaseReleaseViewController { releaseVersionDisplay?.releaseVersion = releaseVersion if let releaseID = releaseVersion?.id { - _ = DiscogsManager.discogs.release(identifier: releaseID).done { [weak self] (release) in - self?.release = release - }.catch { _ in + Task { + release = try await DiscogsManager.discogs.release(identifier: releaseID) } } } diff --git a/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift b/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift index d4af83d..422ca4d 100644 --- a/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift +++ b/SwiftDiscogsApp/Search/DiscogsSearchViewController.swift @@ -96,20 +96,18 @@ class DiscogsSearchViewController: CollectionAndTableViewController, return } - DiscogsManager.discogs.search(for: searchTerms, type: "Artist").done { [weak self] (searchResults) in - guard let self = self else { - return - } - - self.results = searchResults.results?.filter { $0.type == "artist" } + Task { + do { + let searchResults = try await DiscogsManager.discogs.search(for: searchTerms, type: "Artist") + results = searchResults.results?.filter { $0.type == "artist" } - if self.results?.count == 1 { - self.searchView?.selectItem(at: IndexPath(item: 0, section: 0)) + if results?.count == 1 { + searchView?.selectItem(at: IndexPath(item: 0, section: 0)) + } + } catch { + results = nil + presentAlert(for: error) } - - }.catch { [weak self] (error) in - self?.results = nil - self?.presentAlert(for: error) } } diff --git a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift index 50f8444..d322499 100644 --- a/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift +++ b/SwiftDiscogsApp/Third-Party Services/Discogs/DiscogsService.swift @@ -1,6 +1,7 @@ // Copyright © 2019 Poikile Creations. All rights reserved. import CoreData +import JSONClient import Stylobate import SwiftDiscogs import UIKit @@ -26,12 +27,11 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService and we're getting closer every day. (www.discogs.com/about) """ - DiscogsManager.discogs.userIdentity().then { [weak self] (userIdentity) async -> UserProfile in - self?.handle(userIdentity: userIdentity) - return DiscogsManager.discogs.userProfile(userName: userIdentity.username) - }.done { [weak self] (userProfile) in - self?.userProfile = userProfile - }.cauterize() + Task { + let userIdentity = try await DiscogsManager.discogs.userIdentity() + handle(userIdentity: userIdentity) + userProfile = try await DiscogsManager.discogs.userProfile(userName: userIdentity.username) + } } // MARK: - AuthenticatedService @@ -79,16 +79,17 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService authenticationDelegate?.willSignIn(toService: self) - let promise = DiscogsManager.discogs.authorize(presentingViewController: viewController, - callbackUrlString: AppDelegate.shared.callbackUrl.absoluteString) - promise.then { _ in - return DiscogsManager.discogs.userIdentity() - }.done { [weak self] (userIdentity) in - self?.handle(userIdentity: userIdentity) - }.catch { [weak self] (error) in - self?.isSignedIn = false - self?.authenticationDelegate?.signIn(toService: self, failedWithError: error) - viewController.presentAlert(for: error, title: L10n.discogsSignInFailed) + Task { + do { + _ = try await (DiscogsManager.discogs as? OAuth1JSONClient)?.authorize(callbackUrl: AppDelegate.shared.callbackUrl, + presentOver: viewController.view) + let userIdentity = try await DiscogsManager.discogs.userIdentity() + handle(userIdentity: userIdentity) + } catch { + isSignedIn = false + authenticationDelegate?.signIn(toService: self, failedWithError: error) + await viewController.presentAlert(for: error, title: L10n.discogsSignInFailed) + } } } @@ -116,7 +117,7 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService // MARK: Functions -// func importData() { + func importData() { // let context = AppDelegate.shared.medi8Context // // if let username = userName { @@ -143,12 +144,12 @@ class DiscogsService: ThirdPartyService, AuthenticatedService, ImportableService // } // } // } -// } -// -// func stopImportingData() { + } + + func stopImportingData() { // importDelegate?.willFinishImporting(fromService: self) // isImporting = false // importDelegate?.didFinishImporting(fromService: self) -// } + } }