删除自定义铃声时,一起删除 call 生成的长铃声。

This commit is contained in:
Fin 2025-01-23 09:47:52 +08:00
parent 294f8224f0
commit c0dfb5d2b4

View File

@ -91,7 +91,7 @@ class SoundsViewModel: ViewModel, ViewModelType {
guard case SoundItem.sound(let model) = item else { guard case SoundItem.sound(let model) = item else {
return return
} }
self.dependencies.soundFileStorage.deleteSound(url: model.model.url) self.dependencies.soundFileStorage.deleteSound(name: model.model.url.lastPathComponent)
}).disposed(by: rx.disposeBag) }).disposed(by: rx.disposeBag)
// //
@ -169,7 +169,7 @@ class SoundsViewModel: ViewModel, ViewModelType {
/// ///
protocol SoundFileStorageProtocol { protocol SoundFileStorageProtocol {
func saveSound(url: URL) func saveSound(url: URL)
func deleteSound(url: URL) func deleteSound(name: String)
} }
/// /Library/Sounds /// /Library/Sounds
@ -189,9 +189,16 @@ class SoundFileStorage: SoundFileStorageProtocol {
try? fileManager.copyItem(at: url, to: soundUrl) try? fileManager.copyItem(at: url, to: soundUrl)
} }
func deleteSound(url: URL) { func deleteSound(name: String) {
// sounds guard let soundsDirectoryUrl = getSoundsDirectory() else {
try? fileManager.removeItem(at: url) return
}
let soundUrl = soundsDirectoryUrl.appendingPathComponent(name)
let callSoundUrl = soundsDirectoryUrl.appendingPathComponent("\(kBarkSoundPrefix).\(name)")
// sounds
try? fileManager.removeItem(at: soundUrl)
// call=1
try? fileManager.removeItem(at: callSoundUrl)
} }
/// Library Sounds /// Library Sounds