Fixes sound duration issue

main
Laurent 3 years ago
parent 47d17734c1
commit 406732e4b9
  1. 6
      LeCountdown/Sound/Sound.swift
  2. 6
      LeCountdown/Sound/SoundPlayer.swift
  3. 2
      LeCountdown/Subscription/AppGuard.swift
  4. 2
      LeCountdown/Utils/Preferences.swift
  5. 6
      LeCountdown/Views/HomeView.swift

@ -217,9 +217,9 @@ enum Sound: Int, CaseIterable, Identifiable, Localized {
static func computeSoundDurationsIfNecessary() { static func computeSoundDurationsIfNecessary() {
Task { Task {
for sound in Sound.allCases { for sound in Sound.allCases {
if Preferences.soundDurations[sound.rawValue] == nil { if Preferences.soundDurations[sound.fileName] == nil {
if let duration = try? await sound.duration() { if let duration = try? await sound.duration() {
Preferences.soundDurations[sound.rawValue] = duration Preferences.soundDurations[sound.fileName] = duration
} }
} }
} }
@ -227,7 +227,7 @@ enum Sound: Int, CaseIterable, Identifiable, Localized {
} }
var formattedDuration: String { var formattedDuration: String {
if let duration = Preferences.soundDurations[self.rawValue] { if let duration = Preferences.soundDurations[self.fileName] {
return duration.minuteSecond return duration.minuteSecond
} else { } else {
return "" return ""

@ -78,4 +78,10 @@ enum SoundPlayerError : Error {
Conductor.maestro.deactivateAudioSessionIfPossible() Conductor.maestro.deactivateAudioSessionIfPossible()
} }
func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) {
if let error {
Logger.error(error)
}
}
} }

@ -124,7 +124,7 @@ extension Notification.Name {
} }
var isAuthorized: Bool { var isAuthorized: Bool {
return false //self.currentPlan != .none return self.currentPlan != .none
} }
var currentPlan: StorePlan { var currentPlan: StorePlan {

@ -23,7 +23,7 @@ enum PreferenceKey: String {
class Preferences { class Preferences {
@UserDefault(PreferenceKey.countdowns.rawValue, defaultValue: [:]) static var savedCountdowns: [String : DateInterval] @UserDefault(PreferenceKey.countdowns.rawValue, defaultValue: [:]) static var savedCountdowns: [String : DateInterval]
@UserDefault(PreferenceKey.soundDurations.rawValue, defaultValue: [:]) static var soundDurations: [Int : TimeInterval] @UserDefault(PreferenceKey.soundDurations.rawValue, defaultValue: [:]) static var soundDurations: [String : TimeInterval]
@UserDefault(PreferenceKey.lastSoundPlayed.rawValue, defaultValue: [:]) static var lastSelectedSound: [String : Int] @UserDefault(PreferenceKey.lastSoundPlayed.rawValue, defaultValue: [:]) static var lastSelectedSound: [String : Int]
@UserDefault(PreferenceKey.tips.rawValue, defaultValue: nil) static var lastShownTip: Int? @UserDefault(PreferenceKey.tips.rawValue, defaultValue: nil) static var lastShownTip: Int?
@UserDefault(PreferenceKey.timerSiriTips.rawValue, defaultValue: []) static var timerSiriTips: Set<String> @UserDefault(PreferenceKey.timerSiriTips.rawValue, defaultValue: []) static var timerSiriTips: Set<String>

@ -94,16 +94,12 @@ struct RegularHomeView: View {
} }
fileprivate func _setColumnVisibility() { fileprivate func _setColumnVisibility() {
do { let count = viewContext.count(entityName: "AbstractTimer")
let count = try viewContext.count(entityName: "AbstractTimer")
if count > 0 { if count > 0 {
self.columnVisibility = .detailOnly self.columnVisibility = .detailOnly
} else { } else {
self.columnVisibility = .automatic self.columnVisibility = .automatic
} }
} catch {
Logger.error(error)
}
} }
fileprivate func _handleNewCountdown(_ userActivity: NSUserActivity) { fileprivate func _handleNewCountdown(_ userActivity: NSUserActivity) {

Loading…
Cancel
Save