Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed Oct 31, 2024
1 parent ef69587 commit 30b4b4c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/LCP/License/LicenseValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extension LicenseValidation {
.map { $0.body ?? Data() }
.get()

try await raise(.retrievedStatusData(data))
try await raise(.retrievedLicenseData(data))
}

private func checkLicenseStatus(of license: LicenseDocument, status: StatusDocument?, statusDocumentTakesPrecedence: Bool) async throws {
Expand Down
8 changes: 6 additions & 2 deletions Sources/Navigator/Audiobook/AudioNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
if let time = time {
let locator = makeLocator(forTime: time)
currentLocation = locator
delegate?.navigator(self, locationDidChange: locator)
Task { @MainActor in
delegate?.navigator(self, locationDidChange: locator)
}
}

makePlaybackInfo(forTime: time) { info in
Expand Down Expand Up @@ -418,7 +420,9 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
await withCheckedContinuation { continuation in
player.seek(to: CMTime(seconds: time, preferredTimescale: 1000)) { [weak self] finished in
if let self = self, finished {
self.delegate?.navigator(self, didJumpTo: locator)
Task { @MainActor in
self.delegate?.navigator(self, didJumpTo: locator)
}
}
continuation.resume()
}
Expand Down
16 changes: 10 additions & 6 deletions Sources/Navigator/Audiobook/PublicationMediaLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,17 @@ final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Log
range: range,
consume: { dataRequest.respond(with: $0) }
)
switch result {
case .success:
request.finishLoading()
case let .failure(error):
request.finishLoading(with: error)

queue.async { [weak self] in
switch result {
case .success:
request.finishLoading()
case let .failure(error):
request.finishLoading(with: error)
}

self?.finishRequest(request)
}
self.finishRequest(request)
}

registerRequest(request, task: task, for: link.url())
Expand Down
2 changes: 2 additions & 0 deletions Sources/Navigator/EPUB/EPUBNavigatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@ extension EPUBNavigatorViewController: EPUBNavigatorViewModelDelegate {

func epubNavigatorViewModel(_ viewModel: EPUBNavigatorViewModel, runScript script: String, in scope: EPUBScriptScope) {
Task {
await initialized()

switch scope {
case .currentResource:
await (paginationView.currentView as? EPUBSpreadView)?.evaluateScript(script)
Expand Down
11 changes: 10 additions & 1 deletion Sources/Navigator/Navigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public struct NavigatorGoOptions {
self.animated = animated
otherOptionsJSON = JSONDictionary(otherOptions) ?? JSONDictionary()
}

public static var none: NavigatorGoOptions {
NavigatorGoOptions()
}

/// Convenience helper for options that contain only animated: true.
public static var animated: NavigatorGoOptions {
NavigatorGoOptions(animated: true)
}
}

public extension Navigator {
Expand Down Expand Up @@ -110,7 +119,7 @@ public extension Navigator {
}
}

public protocol NavigatorDelegate: AnyObject {
@MainActor public protocol NavigatorDelegate: AnyObject {
/// Called when the current position in the publication changed. You should save the locator here to restore the
/// last read page.
func navigator(_ navigator: Navigator, locationDidChange locator: Locator)
Expand Down

0 comments on commit 30b4b4c

Please sign in to comment.