Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10592523
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Subscribers
None
View Options
diff --git a/Shared/Logging/Logging.swift b/Shared/Logging/Logging.swift
index 27f7980..18e1a16 100644
--- a/Shared/Logging/Logging.swift
+++ b/Shared/Logging/Logging.swift
@@ -1,67 +1,69 @@
//
// Logging.swift
// WriteFreely-MultiPlatform
//
// Created by Angelo Stavrow on 2022-06-25.
//
import Foundation
import os
import OSLog
protocol LogWriter {
func log(_ message: String, withSensitiveInfo privateInfo: String?, level: OSLogType)
func logCrashAndSetFlag(error: Error)
}
+@available(iOS 15, *)
protocol LogReader {
func fetchLogs() -> [String]
}
final class Logging {
private let logger: Logger
private let subsystem = Bundle.main.bundleIdentifier!
init(for category: String = "") {
self.logger = Logger(subsystem: subsystem, category: category)
}
}
extension Logging: LogWriter {
func log(
_ message: String,
withSensitiveInfo privateInfo: String? = nil,
level: OSLogType = .default
) {
if let privateInfo = privateInfo {
logger.log(level: level, "\(message): \(privateInfo, privacy: .sensitive)")
} else {
logger.log(level: level, "\(message)")
}
}
func logCrashAndSetFlag(error: Error) {
let errorDescription = error.localizedDescription
UserDefaults.shared.set(true, forKey: WFDefaults.didHaveFatalError)
UserDefaults.shared.set(errorDescription, forKey: WFDefaults.fatalErrorDescription)
logger.log(level: .error, "\(errorDescription)")
fatalError(errorDescription)
}
}
extension Logging: LogReader {
+ @available(iOS 15, *)
func fetchLogs() -> [String] {
return [
"This is line 1",
"This is line 2",
"This is line 3",
"This is line 4"
]
}
}
diff --git a/iOS/Settings/SettingsView.swift b/iOS/Settings/SettingsView.swift
index 3ede41f..f4721d7 100644
--- a/iOS/Settings/SettingsView.swift
+++ b/iOS/Settings/SettingsView.swift
@@ -1,92 +1,95 @@
import SwiftUI
struct SettingsView: View {
@EnvironmentObject var model: WriteFreelyModel
private let logger = Logging(for: String(describing: SettingsView.self))
var body: some View {
VStack {
SettingsHeaderView()
Form {
Section(header: Text("Login Details")) {
AccountView()
.withErrorHandling()
}
Section(header: Text("Appearance")) {
PreferencesView(preferences: model.preferences)
}
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)
- 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)
+ 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)
+ }
}
}
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()
}
}
}
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
}
+ @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")
}
logger.log("Generated local log post.")
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
.environmentObject(WriteFreelyModel())
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Apr 27, 10:21 AM (2 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217114
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment