68 lines
1.7 KiB
Swift
68 lines
1.7 KiB
Swift
import Foundation
|
|
|
|
final class Settings: ObservableObject {
|
|
|
|
@Published
|
|
var paths: PathSettings
|
|
|
|
/// The items to show in the navigation bar
|
|
@Published
|
|
var navigation: NavigationSettings
|
|
|
|
@Published
|
|
var posts: PostSettings
|
|
|
|
@Published
|
|
var pages: PageSettings
|
|
|
|
@Published
|
|
var audioPlayer: AudioPlayerSettings
|
|
|
|
init(paths: PathSettings,
|
|
navigation: NavigationSettings,
|
|
posts: PostSettings,
|
|
pages: PageSettings,
|
|
audioPlayer: AudioPlayerSettings) {
|
|
self.paths = paths
|
|
self.navigation = navigation
|
|
self.posts = posts
|
|
self.pages = pages
|
|
self.audioPlayer = audioPlayer
|
|
}
|
|
|
|
init(file: SettingsFile, files: [String : FileResource], map: (String) -> Item?) {
|
|
self.navigation = NavigationSettings(file: file.navigation, map: map)
|
|
|
|
self.posts = PostSettings(file: file.posts, files: files)
|
|
self.pages = PageSettings(file: file.pages, files: files)
|
|
self.paths = PathSettings(file: file.paths)
|
|
self.audioPlayer = .init(file: file.audioPlayer, files: files)
|
|
}
|
|
|
|
func file(tagOverview: TagOverviewPage?) -> SettingsFile {
|
|
.init(
|
|
paths: paths.file,
|
|
navigation: navigation.file,
|
|
posts: posts.file,
|
|
pages: pages.file,
|
|
audioPlayer: audioPlayer.file,
|
|
tagOverview: tagOverview?.file)
|
|
}
|
|
|
|
func remove(_ file: FileResource) {
|
|
pages.remove(file)
|
|
posts.remove(file)
|
|
audioPlayer.remove(file)
|
|
}
|
|
}
|
|
|
|
extension Settings {
|
|
|
|
static let `default`: Settings = .init(
|
|
paths: .default,
|
|
navigation: .default,
|
|
posts: .default,
|
|
pages: .default,
|
|
audioPlayer: .default)
|
|
}
|