Save automatically, improve mocks
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class Settings: ObservableObject {
|
||||
final class Settings: ChangeObservableItem {
|
||||
|
||||
@Published
|
||||
var general: GeneralSettings
|
||||
@ -21,6 +22,10 @@ final class Settings: ObservableObject {
|
||||
@Published
|
||||
var audioPlayer: AudioPlayerSettings
|
||||
|
||||
weak var content: Content?
|
||||
|
||||
var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
init(general: GeneralSettings,
|
||||
paths: PathSettings,
|
||||
navigation: NavigationSettings,
|
||||
@ -40,6 +45,10 @@ final class Settings: ObservableObject {
|
||||
posts.remove(file)
|
||||
audioPlayer.remove(file)
|
||||
}
|
||||
|
||||
func needsSaving() {
|
||||
content?.needsSave()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Storage
|
||||
@ -54,6 +63,7 @@ extension Settings {
|
||||
posts: .init(context: context, data: data.posts),
|
||||
pages: .init(context: context, data: data.pages),
|
||||
audioPlayer: .init(context: context, data: data.audioPlayer))
|
||||
content = context.content
|
||||
}
|
||||
|
||||
func data(tagOverview: Tag?) -> Data {
|
||||
@ -67,7 +77,7 @@ extension Settings {
|
||||
tagOverview: tagOverview?.data)
|
||||
}
|
||||
|
||||
struct Data: Codable {
|
||||
struct Data: Codable, Equatable {
|
||||
let general: GeneralSettings.Data
|
||||
let paths: PathSettings.Data
|
||||
let navigation: NavigationSettings.Data
|
||||
@ -76,6 +86,10 @@ extension Settings {
|
||||
let audioPlayer: AudioPlayerSettings.Data
|
||||
let tagOverview: Tag.Data?
|
||||
}
|
||||
|
||||
func saveToDisk(_ data: Data) -> Bool {
|
||||
content?.storage.save(settings: data) ?? false
|
||||
}
|
||||
}
|
||||
|
||||
extension Settings {
|
||||
|
Reference in New Issue
Block a user