Skip to content

Commit

Permalink
[PP-1504] Resolve Audiobook playback lockup (#454)
Browse files Browse the repository at this point in the history
* Resolve TOC navigation errors

* integrate updated audiobook toolkit

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update TPPBookCellDelegate+Extensions.swift

* Update ios-audiobooktoolkit

* Prevent LCP lock on startup

* Update project.pbxproj

* Resolve token refresh issue

* add pretty printing extension for debugging

* Update ios-audiobooktoolkit

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update ios-audiobooktoolkit

* Update ios-audiobooktoolkit

* Multiple fixes

* merge in dev

* Update project.pbxproj

* Clean up

* Ensure image update is not missed by callback

* Update project.pbxproj

* Update TrackPosition+Annotations.swift

* Update ios-audiobooktoolkit

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Properly map audiobookmarks to locator

* Working implementation

* Capture time stamp from outer element of locator

* Move location saving to background thread

* Resolve syncing issues to prevent over uploading bookmarks

* Add additional backward compatability support

* Restore tests

* Restore audibookmark tests

* Improve bookmark syncing logic and code clean up

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Update AudioBookmark.swift

* Update TokenRequest.swift

* Update AudioBookmark.swift

* Update AudiobookmarkTests.swift

* Update ios-audiobooktoolkit

* Update project.pbxproj

* Update project.pbxproj

* Update project.pbxproj

* Bump build number

* Update project.pbxproj

* Update project.pbxproj

* Update ios-audiobooktoolkit

* Update project.pbxproj

* Resolve UI lockup on NonLCP books

* Update project.pbxproj

* Update project.pbxproj
  • Loading branch information
mauricecarrier7 authored Aug 8, 2024
1 parent d943a9a commit 2d0022c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
12 changes: 6 additions & 6 deletions Palace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5655,7 +5655,7 @@
CODE_SIGN_IDENTITY = "Apple Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5714,7 +5714,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Palace/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5899,7 +5899,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5960,7 +5960,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Palace/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -6022,7 +6022,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -6083,7 +6083,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Palace/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 278;
CURRENT_PROJECT_VERSION = 279;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down
34 changes: 23 additions & 11 deletions Palace/Book/UI/TPPBookCellDelegate+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ import PalaceAudiobookToolkit
let kServerUpdateDelay: Double = 30.0
let kTimerInterval: Double = 1.0

//TODO: This is a temporary solution to enable location saves from AppDelegate. Investigate a global context to manage state and introduce caching.
var latestAudiobookLocation: (book: String, location: String)?

private struct AssociatedKeys {
static var audiobookBookmarkBusinessLogic = "audiobookBookmarkBusinessLogic"
}

private let locationQueue = DispatchQueue(label: "com.palace.latestAudiobookLocation", attributes: .concurrent)
private var _latestAudiobookLocation: (book: String, location: String)?

var latestAudiobookLocation: (book: String, location: String)? {
get {
locationQueue.sync {
_latestAudiobookLocation
}
}
set {
locationQueue.async(flags: .barrier) {
_latestAudiobookLocation = newValue
}
}
}

extension TPPBookCellDelegate {
public func postListeningPosition(at location: String, completion: ((_ response: AnnotationResponse?) -> Void)? = nil) {
TPPAnnotations.postListeningPosition(forBook: self.book.identifier, selectorValue: location, completion: completion)
Expand All @@ -31,14 +44,12 @@ extension TPPBookCellDelegate {
return objc_getAssociatedObject(self, &AssociatedKeys.audiobookBookmarkBusinessLogic) as? AudiobookBookmarkBusinessLogic
}
set {
if let newValue = newValue {
objc_setAssociatedObject(
self,
&AssociatedKeys.audiobookBookmarkBusinessLogic,
newValue as AudiobookBookmarkBusinessLogic?,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
}
objc_setAssociatedObject(
self,
&AssociatedKeys.audiobookBookmarkBusinessLogic,
newValue,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
}
}

Expand Down Expand Up @@ -264,6 +275,7 @@ extension TPPBookCellDelegate {
let locationString = String(data: locationData ?? Data(), encoding: .utf8) ?? ""

TPPBookRegistry.shared.setLocation(TPPBookLocation(locationString: locationString, renderer: "PalaceAudiobookToolkit"), forIdentifier: self.book.identifier)

latestAudiobookLocation = (book: self.book.identifier, location: locationString)
}
}
Expand Down
10 changes: 8 additions & 2 deletions Palace/Reader2/Bookmarks/AudiobookBookmarkBusinessLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ import PalaceAudiobookToolkit
}

// MARK: - Bookmark Management

public func saveListeningPosition(at position: TrackPosition, completion: ((String?) -> Void)?) {
debounce {
self.saveListeningPositionImmediate(at: position, completion: completion)
}
}

private func saveListeningPositionImmediate(at position: TrackPosition, completion: ((String?) -> Void)?) {
let audioBookmark = position.toAudioBookmark()
audioBookmark.lastSavedTimeStamp = Date().iso8601
guard let tppLocation = audioBookmark.toTPPBookLocation() else {
Expand All @@ -50,7 +56,7 @@ import PalaceAudiobookToolkit
}
}
}

public func saveBookmark(at position: TrackPosition, completion: ((_ position: TrackPosition?) -> Void)? = nil) {
debounce {
Task {
Expand Down
2 changes: 1 addition & 1 deletion ios-audiobooktoolkit

0 comments on commit 2d0022c

Please sign in to comment.