Skip to content

Commit

Permalink
Merge pull request #1112 from TortugaPower/fix-autotimer
Browse files Browse the repository at this point in the history
Fix auto sleep timer & initial migration for synced tasks
  • Loading branch information
GianniCarlo authored Mar 2, 2024
2 parents 9beaad3 + 5e1289e commit dcffd98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions BookPlayer/Player/PlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ extension PlayerManager {
}

func play() {
play(autoPlayed: false)
}

func play(autoPlayed: Bool) {
playTask?.cancel()
playTask = Task { @MainActor in
/// Ignore play commands if there's no item loaded,
Expand Down Expand Up @@ -739,7 +743,9 @@ extension PlayerManager {

handleSmartRewind(currentItem)

handleAutoTimer()
if !autoPlayed {
handleAutoTimer()
}

fadeTimer?.invalidate()
shakeMotionService.stopMotionUpdates()
Expand Down Expand Up @@ -815,7 +821,7 @@ extension PlayerManager {
self.observeStatus = false

if self.playbackQueued == true {
self.play()
self.play(autoPlayed: true)
}
// Clean up flag
self.playbackQueued = nil
Expand Down Expand Up @@ -1119,7 +1125,7 @@ extension PlayerManager {
}
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
if options.contains(.shouldResume) {
play()
play(autoPlayed: true)
}
@unknown default:
break
Expand Down
11 changes: 10 additions & 1 deletion Shared/Realm/Migrations/MigrationStoredSyncTasks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class MigrationStoredSyncTasks: MigrationHandler {
let taskId = UUID().uuidString
taskParams["id"] = taskId

if taskParams["lastPlayDateTimestamp"] is String {
taskParams["lastPlayDateTimestamp"] = 0
}

let task = migrateTask(
taskParams,
id: taskId,
Expand Down Expand Up @@ -77,11 +81,16 @@ class MigrationStoredSyncTasks: MigrationHandler {

for taskData in storedTasks {
autoreleasepool {
if let taskParams = try? JSONSerialization.jsonObject(with: taskData) as? [String: Any],
if var taskParams = try? JSONSerialization.jsonObject(with: taskData) as? [String: Any],
let taskId = taskParams["id"] as? String,
let relativePath = taskParams["relativePath"] as? String,
let jobTypeRaw = taskParams["jobType"] as? String,
let jobType = SyncJobType(rawValue: jobTypeRaw) {

if taskParams["lastPlayDateTimestamp"] is String {
taskParams["lastPlayDateTimestamp"] = 0
}

let task = migrateTask(
taskParams,
id: taskId,
Expand Down

0 comments on commit dcffd98

Please sign in to comment.