2024-09-23 13:02:26 +00:00
|
|
|
//
|
|
|
|
// ReportIssueButton+iOS.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/18/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-09-28 17:05:47 +00:00
|
|
|
import PassepartoutKit
|
2024-09-23 13:02:26 +00:00
|
|
|
import SwiftUI
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension ReportIssueButton: View {
|
|
|
|
var body: some View {
|
|
|
|
HStack {
|
2024-10-04 07:58:42 +00:00
|
|
|
Button(title, action: sendEmail)
|
2024-09-23 13:02:26 +00:00
|
|
|
if isPending {
|
|
|
|
Spacer()
|
|
|
|
ProgressView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.disabled(isPending)
|
|
|
|
.themeModal(item: $issueBeingReported) {
|
|
|
|
MailComposerView(
|
|
|
|
isPresented: Binding {
|
|
|
|
issueBeingReported != nil
|
|
|
|
} set: {
|
|
|
|
if !$0 {
|
|
|
|
issueBeingReported = nil
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toRecipients: [$0.to],
|
|
|
|
subject: $0.subject,
|
|
|
|
messageBody: $0.body,
|
|
|
|
attachments: $0.attachments
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
private extension ReportIssueButton {
|
2024-10-04 13:45:40 +00:00
|
|
|
|
|
|
|
@MainActor
|
2024-10-04 07:58:42 +00:00
|
|
|
func sendEmail() {
|
|
|
|
Task {
|
|
|
|
isPending = true
|
|
|
|
defer {
|
|
|
|
isPending = false
|
|
|
|
}
|
|
|
|
let issue = await Issue.withMetadata(.init(
|
2024-10-23 15:32:49 +00:00
|
|
|
profile: installedProfile,
|
2024-10-25 09:38:27 +00:00
|
|
|
provider: currentProvider,
|
2024-10-04 07:58:42 +00:00
|
|
|
configuration: .shared,
|
|
|
|
versionString: BundleConfiguration.mainVersionString,
|
|
|
|
purchasedProducts: purchasedProducts,
|
|
|
|
tunnel: tunnel,
|
|
|
|
urlForTunnelLog: BundleConfiguration.urlForTunnelLog,
|
|
|
|
parameters: Constants.shared.log
|
|
|
|
))
|
|
|
|
guard MailComposerView.canSendMail() else {
|
|
|
|
openMailTo(with: issue)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
issueBeingReported = issue
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func openMailTo(with issue: Issue) {
|
|
|
|
guard let url = URL.mailto(to: issue.to, subject: issue.subject, body: issue.body) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard UIApplication.shared.canOpenURL(url) else {
|
|
|
|
isUnableToEmail = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
UIApplication.shared.open(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 07:58:42 +00:00
|
|
|
private extension Issue {
|
|
|
|
var attachments: [MailComposerView.Attachment] {
|
|
|
|
var list: [MailComposerView.Attachment] = []
|
|
|
|
let mimeType = Strings.Unlocalized.Issues.attachmentMimeType
|
|
|
|
if let appLog {
|
|
|
|
list.append(.init(data: appLog, mimeType: mimeType, fileName: Strings.Unlocalized.Issues.appLogFilename))
|
|
|
|
}
|
|
|
|
if let tunnelLog {
|
|
|
|
list.append(.init(data: tunnelLog, mimeType: mimeType, fileName: Strings.Unlocalized.Issues.tunnelLogFilename))
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
#endif
|