Reorganize saving, generate feed

This commit is contained in:
Christoph Hagen
2024-12-03 13:19:50 +01:00
parent 3c950d47a2
commit dc7b7a0e90
27 changed files with 717 additions and 411 deletions

View File

@ -23,6 +23,9 @@ struct SettingsView: View {
@State
private var showTagPicker = false
@State
private var isGeneratingWebsite = false
var body: some View {
ScrollView {
VStack(alignment: .leading) {
@ -63,8 +66,16 @@ struct SettingsView: View {
LocalizedSettingsView(settings: content.websiteData.localized(in: language))
Text("Feed")
.font(.headline)
Button(action: generateFeed) {
Text("Generate")
HStack {
Button(action: generateFeed) {
Text("Generate")
}
if isGeneratingWebsite {
ProgressView()
.progressViewStyle(.circular)
.frame(height: 25)
}
Spacer()
}
}
.padding()
@ -86,7 +97,7 @@ struct SettingsView: View {
private func selectContentFolder() {
isSelectingContentFolder = true
//showFileImporter = true
guard let url = savePanelUsingOpenPanel(key: "contentPathBookmark") else {
guard let url = savePanelUsingOpenPanel(key: Storage.contentPathBookmarkKey) else {
return
}
self.contentPath = url.path()
@ -94,8 +105,7 @@ struct SettingsView: View {
private func selectOutputFolder() {
isSelectingContentFolder = false
//showFileImporter = true
guard let url = savePanelUsingOpenPanel(key: "outputPathBookmark") else {
guard let url = savePanelUsingOpenPanel(key: Storage.outputPathBookmarkKey) else {
return
}
self.outputPath = url.path()
@ -115,10 +125,10 @@ struct SettingsView: View {
.replacingOccurrences(of: "file://", with: "")
if isSelectingContentFolder {
self.contentPath = path
saveSecurityScopedBookmark(folder, key: "contentPathBookmark")
saveSecurityScopedBookmark(folder, key: Storage.contentPathBookmarkKey)
} else {
self.outputPath = path
saveSecurityScopedBookmark(folder, key: "outputPathBookmark")
saveSecurityScopedBookmark(folder, key: Storage.outputPathBookmarkKey)
}
}
@ -135,8 +145,23 @@ struct SettingsView: View {
print("Missing output folder")
return
}
isGeneratingWebsite = true
DispatchQueue.global(qos: .userInitiated).async {
let generator = WebsiteGenerator(
content: content,
configuration: configuration)
generator.generateWebsite()
DispatchQueue.main.async {
isGeneratingWebsite = false
}
}
}
content.generateFeed(for: language, bookmarkKey: "outputPathBookmark")
private var configuration: WebsiteGeneratorConfiguration {
switch language {
case .english: return .english
case .german: return .german
}
}
func savePanelUsingOpenPanel(key: String) -> URL? {