2020-08-10 16:37:19 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SettingsView: View {
|
2022-12-06 21:41:12 +00:00
|
|
|
|
2020-08-18 18:06:02 +00:00
|
|
|
@EnvironmentObject var model: WriteFreelyModel
|
2022-12-06 21:41:12 +00:00
|
|
|
@State private var isShowingAlert = false
|
|
|
|
|
|
|
|
private let logger = Logging(for: String(describing: SettingsView.self))
|
2020-08-11 18:32:45 +00:00
|
|
|
|
2020-08-10 16:37:19 +00:00
|
|
|
var body: some View {
|
2020-08-10 20:21:26 +00:00
|
|
|
VStack {
|
2020-09-11 17:53:11 +00:00
|
|
|
SettingsHeaderView()
|
2020-08-10 20:21:26 +00:00
|
|
|
Form {
|
2020-08-10 20:50:24 +00:00
|
|
|
Section(header: Text("Login Details")) {
|
2020-08-18 21:20:16 +00:00
|
|
|
AccountView()
|
2022-07-27 13:56:32 +00:00
|
|
|
.withErrorHandling()
|
2020-08-10 20:21:26 +00:00
|
|
|
}
|
|
|
|
Section(header: Text("Appearance")) {
|
2020-08-18 18:06:02 +00:00
|
|
|
PreferencesView(preferences: model.preferences)
|
2020-08-10 20:21:26 +00:00
|
|
|
}
|
2022-12-06 21:41:12 +00:00
|
|
|
Section(header: Text("Help and Support")) {
|
|
|
|
Link("View the Guide", destination: model.howToURL)
|
|
|
|
Link("Visit the Help Forum", destination: model.helpURL)
|
|
|
|
Link("Write a Review on the App Store", destination: model.reviewURL)
|
|
|
|
if #available(iOS 15.0, *) {
|
|
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
|
|
Button(
|
|
|
|
action: didTapGenerateLogPostButton,
|
|
|
|
label: {
|
|
|
|
Text("Create Log Post")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
Text("Generates a local post using recent logs. You can share this for troubleshooting.")
|
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2021-01-04 19:25:02 +00:00
|
|
|
}
|
2020-09-16 15:34:45 +00:00
|
|
|
}
|
2020-09-18 19:33:04 +00:00
|
|
|
Section(header: Text("Acknowledgements")) {
|
|
|
|
VStack {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text("This application makes use of the following open-source projects:")
|
|
|
|
.padding(.bottom)
|
|
|
|
Text("• Lora typeface")
|
|
|
|
.padding(.leading)
|
|
|
|
Text("• Open Sans typeface")
|
|
|
|
.padding(.leading)
|
|
|
|
Text("• Hack typeface")
|
|
|
|
.padding(.leading)
|
|
|
|
}
|
|
|
|
.padding(.bottom)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Link("View the licenses", destination: model.licensesURL)
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
}
|
2020-08-10 16:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-06 21:41:12 +00:00
|
|
|
.alert(isPresented: $isShowingAlert) {
|
|
|
|
Alert(
|
|
|
|
title: Text("Log Post Created"),
|
|
|
|
message: Text("Check your local drafts for app logs from the past 24 hours.")
|
|
|
|
)
|
|
|
|
}
|
2020-08-13 18:54:56 +00:00
|
|
|
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
|
2020-08-10 16:37:19 +00:00
|
|
|
}
|
2022-12-06 21:41:12 +00:00
|
|
|
|
|
|
|
@available(iOS 15, *)
|
|
|
|
private func didTapGenerateLogPostButton() {
|
|
|
|
logger.log("Generating local log post...")
|
|
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
|
|
|
// Unset selected post and collection and navigate to local drafts.
|
|
|
|
self.model.selectedPost = nil
|
|
|
|
self.model.selectedCollection = nil
|
|
|
|
self.model.showAllPosts = false
|
|
|
|
|
|
|
|
// Create the new log post.
|
|
|
|
let newLogPost = model.editor.generateNewLocalPost(withFont: 2)
|
|
|
|
newLogPost.title = "Logs For Support"
|
|
|
|
var postBody: [String] = [
|
|
|
|
"WriteFreely-Multiplatform v\(Bundle.main.appMarketingVersion) (\(Bundle.main.appBuildVersion))",
|
|
|
|
"Generated \(Date())",
|
|
|
|
""
|
|
|
|
]
|
|
|
|
postBody.append(contentsOf: logger.fetchLogs())
|
|
|
|
newLogPost.body = postBody.joined(separator: "\n")
|
|
|
|
|
|
|
|
self.isShowingAlert = true
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.log("Generated local log post.")
|
|
|
|
}
|
2020-08-10 16:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2020-09-11 17:53:11 +00:00
|
|
|
SettingsView()
|
2020-08-18 18:06:02 +00:00
|
|
|
.environmentObject(WriteFreelyModel())
|
2020-08-10 16:37:19 +00:00
|
|
|
}
|
|
|
|
}
|