Skip to content

Commit

Permalink
Reset sleep timer
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuslos committed Dec 20, 2024
1 parent cf6f671 commit 5143c25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public extension AudioPlayer {
}

audioPlayer.removeAllItems()
SleepTimer.shared.reset()

NotificationCenter.default.post(name: Self.itemDidChangeNotification, object: nil)
NotificationCenter.default.post(name: Self.queueDidChangeNotification, object: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
internal extension SleepTimer {
func setupTimer() {
guard let deadline else {
suspend()
return
}

Expand Down
17 changes: 17 additions & 0 deletions ShelfPlayerKit/Sources/SPPlayback/SleepTimer/SleepTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public final class SleepTimer {
return
}

if Defaults[.smartRewind] && !AudioPlayer.shared.playing {
if AudioPlayer.shared.chapterCurrentTime > 7 {
AudioPlayer.shared.itemCurrentTime -= 7
} else {
AudioPlayer.shared.chapterCurrentTime = 0
}
}

switch lastSetting {
case .time(let interval):
if let expiresAt {
Expand All @@ -87,6 +95,15 @@ public final class SleepTimer {
expiresAtChapterEnd = amount
}
}

self.lastSetting = lastSetting
}
public func reset() {
expiredAt = nil
expiredAt = nil

expiresAtChapterEnd = nil

}

enum SleepTimerSetting {
Expand Down

0 comments on commit 5143c25

Please sign in to comment.