From e45459e556d0193f057fff9de8a0a5db107fff32 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 25 Jan 2023 18:54:06 -0500 Subject: [PATCH] Add support link to about screen --- .../IssueReporterViewController.swift | 2 +- .../Screens/Preferences/About/AboutView.swift | 79 ++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift b/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift index 64dff091..79932f84 100644 --- a/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift +++ b/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift @@ -122,7 +122,7 @@ class IssueReporterViewController: UIViewController { Task { let composeVC = MFMailComposeViewController() composeVC.mailComposeDelegate = self - composeVC.setToRecipients(["me@shadowfacts.net"]) + composeVC.setToRecipients(["hello@vaccor.space"]) composeVC.setSubject(subject) let data = reportText.data(using: .utf8)! diff --git a/Tusker/Screens/Preferences/About/AboutView.swift b/Tusker/Screens/Preferences/About/AboutView.swift index 11c549f9..7ca9d52e 100644 --- a/Tusker/Screens/Preferences/About/AboutView.swift +++ b/Tusker/Screens/Preferences/About/AboutView.swift @@ -7,8 +7,13 @@ // import SwiftUI +import MessageUI struct AboutView: View { + @State private var logData: Data? + @State private var isGettingLogData = false + @State private var isShowingMailSheet = false + private var version: String { let marketing = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String @@ -40,10 +45,32 @@ struct AboutView: View { Section { Link("Website", destination: URL(string: "https://vaccor.space/tusker")!) + Button { + if MFMailComposeViewController.canSendMail() { + Task { + await showMailSheet() + } + } else { + UIApplication.shared.open(URL(string: "mailto:hello@vaccor.space?subject=Tusker%20Support")!) + } + } label: { + HStack { + Text("Get Support") + Spacer() + if isGettingLogData { + ProgressView() + .progressViewStyle(.circular) + } + } + } + .disabled(isGettingLogData) Link("Source Code", destination: URL(string: "https://git.shadowfacts.net/shadowfacts/Tusker")!) Link("Issue Tracker", destination: URL(string: "https://git.shadowfacts.net/shadowfacts/Tusker/issues")!) } } + .sheet(isPresented: $isShowingMailSheet) { + MailSheet(logData: logData) + } } @ViewBuilder @@ -69,9 +96,20 @@ struct AboutView: View { .font(.title2.bold()) } } + + private func showMailSheet() async { + isGettingLogData = true + logData = await withCheckedContinuation({ continuation in + DispatchQueue.global().async { + continuation.resume(returning: Logging.getLogData()) + } + }) + isGettingLogData = false + isShowingMailSheet = true + } } -struct AppIconView: UIViewRepresentable { +private struct AppIconView: UIViewRepresentable { func makeUIView(context: Context) -> UIImageView { let view = UIImageView(image: UIImage(named: "AboutIcon")) view.contentMode = .scaleAspectFit @@ -85,6 +123,45 @@ struct AppIconView: UIViewRepresentable { } } +private struct MailSheet: UIViewControllerRepresentable { + typealias UIViewControllerType = MFMailComposeViewController + + let logData: Data? + + @Environment(\.dismiss) private var dismiss + + func makeUIViewController(context: Context) -> MFMailComposeViewController { + let vc = MFMailComposeViewController() + vc.mailComposeDelegate = context.coordinator + vc.setToRecipients(["hello@vaccor.space"]) + vc.setSubject("Tusker Support") + if let logData { + let timestamp = ISO8601DateFormatter().string(from: Date()) + vc.addAttachmentData(logData, mimeType: "text/plain", fileName: "Tusker-\(timestamp).log") + } + return vc + } + + func updateUIViewController(_ uiViewController: MFMailComposeViewController, context: Context) { + } + + func makeCoordinator() -> Coordinator { + return Coordinator(dismiss: dismiss) + } + + class Coordinator: NSObject, MFMailComposeViewControllerDelegate { + let dismiss: DismissAction + + init(dismiss: DismissAction) { + self.dismiss = dismiss + } + + func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { + dismiss() + } + } +} + struct AboutView_Previews: PreviewProvider { static var previews: some View { AboutView()