You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.6 KiB
61 lines
2.6 KiB
//
|
|
// Preferences.swift
|
|
// LeCountdown
|
|
//
|
|
// Created by Laurent Morvillier on 16/02/2023.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum PreferenceKey: String {
|
|
case hasShownStartView
|
|
case installDate
|
|
case countdowns
|
|
case pausedCountdowns
|
|
case stopwatches
|
|
case playConfirmationSound
|
|
case playCancellationSound
|
|
case showSilentModeAlert
|
|
case soundDurations
|
|
case lastSoundPlayedByTimer
|
|
case lastSoundPlayed
|
|
case tips
|
|
case timerSiriTips
|
|
case cloudKitSchemaInitialized
|
|
case defaultVolume
|
|
case raiseSoundOnLaunch
|
|
}
|
|
|
|
class Preferences {
|
|
|
|
@UserDefault(PreferenceKey.countdowns.rawValue, defaultValue: [:]) static var savedCountdowns: [String : DateInterval]
|
|
@UserDefault(PreferenceKey.soundDurations.rawValue, defaultValue: [:]) static var soundDurations: [String : TimeInterval]
|
|
@UserDefault(PreferenceKey.lastSoundPlayedByTimer.rawValue, defaultValue: [:]) static var lastSelectedSoundByTimer: [String : Int]
|
|
@UserDefault(PreferenceKey.lastSoundPlayed.rawValue, defaultValue: nil) static var lastSoundPlayed: Int?
|
|
|
|
@UserDefault(PreferenceKey.tips.rawValue, defaultValue: nil) static var lastShownTip: Int?
|
|
@UserDefault(PreferenceKey.timerSiriTips.rawValue, defaultValue: []) static var timerSiriTips: Set<String>
|
|
@UserDefault(PreferenceKey.playConfirmationSound.rawValue, defaultValue: true) static var playConfirmationSound: Bool
|
|
@UserDefault(PreferenceKey.playCancellationSound.rawValue, defaultValue: true) static var playCancellationSound: Bool
|
|
@UserDefault(PreferenceKey.cloudKitSchemaInitialized.rawValue, defaultValue: false) static var cloudKitSchemaInitialized: Bool
|
|
@UserDefault(PreferenceKey.defaultVolume.rawValue, defaultValue: 0.5) static var defaultVolume: Float
|
|
@UserDefault(PreferenceKey.installDate.rawValue, defaultValue: nil) static var installDate: Date?
|
|
@UserDefault(PreferenceKey.hasShownStartView.rawValue, defaultValue: false) static var hasShownStartView: Bool
|
|
@UserDefault(PreferenceKey.raiseSoundOnLaunch.rawValue, defaultValue: false) static var raiseSoundOnLaunch: Bool
|
|
|
|
static var hideSilentModeAlerts: Bool {
|
|
return UserDefaults.standard.bool(forKey: PreferenceKey.showSilentModeAlert.rawValue)
|
|
}
|
|
|
|
static func hideSilentModeAlerts(_ hide: Bool) {
|
|
UserDefaults.standard.setValue(true, forKey: PreferenceKey.showSilentModeAlert.rawValue)
|
|
}
|
|
|
|
static var tipToShow: Tip? {
|
|
if let tipRawValue = self.lastShownTip, let tip = Tip(rawValue: tipRawValue) {
|
|
return Tip(rawValue: tip.rawValue + 1)
|
|
}
|
|
return Tip.allCases.first
|
|
}
|
|
|
|
}
|
|
|