Source code for the WriteFreely SwiftUI app for iOS, iPadOS, and macOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

106 line
4.1 KiB

  1. import SwiftUI
  2. struct SettingsView: View {
  3. @EnvironmentObject var model: WriteFreelyModel
  4. @State private var isShowingAlert = false
  5. private let logger = Logging(for: String(describing: SettingsView.self))
  6. var body: some View {
  7. VStack {
  8. SettingsHeaderView()
  9. Form {
  10. Section(header: Text("Login Details")) {
  11. AccountView()
  12. .withErrorHandling()
  13. }
  14. Section(header: Text("Appearance")) {
  15. PreferencesView(preferences: model.preferences)
  16. }
  17. Section(header: Text("Help and Support")) {
  18. Link("View the Guide", destination: model.howToURL)
  19. Link("Visit the Help Forum", destination: model.helpURL)
  20. Link("Write a Review on the App Store", destination: model.reviewURL)
  21. if #available(iOS 15.0, *) {
  22. VStack(alignment: .leading, spacing: 8) {
  23. Button(
  24. action: didTapGenerateLogPostButton,
  25. label: {
  26. Text("Create Log Post")
  27. }
  28. )
  29. Text("Generates a local post using recent logs. You can share this for troubleshooting.")
  30. .font(.footnote)
  31. .foregroundColor(.secondary)
  32. }
  33. }
  34. }
  35. Section(header: Text("Acknowledgements")) {
  36. VStack {
  37. VStack(alignment: .leading) {
  38. Text("This application makes use of the following open-source projects:")
  39. .padding(.bottom)
  40. Text("• Lora typeface")
  41. .padding(.leading)
  42. Text("• Open Sans typeface")
  43. .padding(.leading)
  44. Text("• Hack typeface")
  45. .padding(.leading)
  46. }
  47. .padding(.bottom)
  48. .foregroundColor(.secondary)
  49. HStack {
  50. Spacer()
  51. Link("View the licenses", destination: model.licensesURL)
  52. Spacer()
  53. }
  54. }
  55. .padding()
  56. }
  57. }
  58. }
  59. .alert(isPresented: $isShowingAlert) {
  60. Alert(
  61. title: Text("Log Post Created"),
  62. message: Text("Check your local drafts for app logs from the past 24 hours.")
  63. )
  64. }
  65. // .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
  66. }
  67. @available(iOS 15, *)
  68. private func didTapGenerateLogPostButton() {
  69. logger.log("Generating local log post...")
  70. DispatchQueue.main.asyncAfter(deadline: .now()) {
  71. // Unset selected post and collection and navigate to local drafts.
  72. self.model.selectedPost = nil
  73. self.model.selectedCollection = nil
  74. self.model.showAllPosts = false
  75. // Create the new log post.
  76. let newLogPost = model.editor.generateNewLocalPost(withFont: 2)
  77. newLogPost.title = "Logs For Support"
  78. var postBody: [String] = [
  79. "WriteFreely-Multiplatform v\(Bundle.main.appMarketingVersion) (\(Bundle.main.appBuildVersion))",
  80. "Generated \(Date())",
  81. ""
  82. ]
  83. postBody.append(contentsOf: logger.fetchLogs())
  84. newLogPost.body = postBody.joined(separator: "\n")
  85. self.isShowingAlert = true
  86. }
  87. logger.log("Generated local log post.")
  88. }
  89. }
  90. struct SettingsView_Previews: PreviewProvider {
  91. static var previews: some View {
  92. SettingsView()
  93. .environmentObject(WriteFreelyModel())
  94. }
  95. }