2024-09-23 13:02:26 +00:00
|
|
|
//
|
|
|
|
// Issue.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-29 13:30:41 +00:00
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
import CommonLibrary
|
|
|
|
import Foundation
|
2024-10-23 15:32:49 +00:00
|
|
|
import PassepartoutKit
|
2024-09-23 13:02:26 +00:00
|
|
|
import UIKit
|
2024-10-29 13:30:41 +00:00
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
#else
|
2024-10-29 13:30:41 +00:00
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
import AppKit
|
|
|
|
import CommonLibrary
|
|
|
|
import Foundation
|
2024-10-23 15:32:49 +00:00
|
|
|
import PassepartoutKit
|
2024-10-29 13:30:41 +00:00
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct Issue: Identifiable {
|
|
|
|
let id: UUID
|
|
|
|
|
|
|
|
let appLine: String?
|
|
|
|
|
|
|
|
let purchasedProducts: Set<AppProduct>
|
|
|
|
|
|
|
|
let appLog: Data?
|
|
|
|
|
|
|
|
let tunnelLog: Data?
|
|
|
|
|
|
|
|
let osLine: String
|
|
|
|
|
|
|
|
let deviceLine: String?
|
|
|
|
|
2024-10-23 15:32:49 +00:00
|
|
|
let providerName: String?
|
|
|
|
|
2024-10-25 09:38:27 +00:00
|
|
|
let providerLastUpdate: Date?
|
|
|
|
|
2024-10-23 15:32:49 +00:00
|
|
|
init(
|
|
|
|
appLine: String?,
|
|
|
|
purchasedProducts: Set<AppProduct>,
|
|
|
|
appLog: Data? = nil,
|
|
|
|
tunnelLog: Data? = nil,
|
2024-10-25 09:38:27 +00:00
|
|
|
provider: (ProviderID, Date?)? = nil
|
2024-10-23 15:32:49 +00:00
|
|
|
) {
|
2024-09-23 13:02:26 +00:00
|
|
|
id = UUID()
|
|
|
|
self.appLine = appLine
|
|
|
|
self.purchasedProducts = purchasedProducts
|
|
|
|
self.appLog = appLog
|
|
|
|
self.tunnelLog = tunnelLog
|
|
|
|
|
|
|
|
let osName: String
|
|
|
|
let osVersion: String
|
|
|
|
let deviceType: String?
|
|
|
|
// providerName / providerLastUpdate
|
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
let device: UIDevice = .current
|
|
|
|
osName = device.systemName
|
|
|
|
osVersion = device.systemVersion
|
|
|
|
deviceType = device.model
|
|
|
|
#else
|
|
|
|
let os = ProcessInfo().operatingSystemVersion
|
|
|
|
osName = "macOS"
|
|
|
|
osVersion = "\(os.majorVersion).\(os.minorVersion).\(os.patchVersion)"
|
|
|
|
deviceType = nil
|
|
|
|
#endif
|
|
|
|
|
|
|
|
osLine = "\(osName) \(osVersion)"
|
|
|
|
deviceLine = deviceType
|
2024-10-23 15:32:49 +00:00
|
|
|
|
2024-10-25 09:38:27 +00:00
|
|
|
providerName = provider?.0.rawValue
|
|
|
|
providerLastUpdate = provider?.1
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var body: String {
|
|
|
|
template
|
|
|
|
.replacingOccurrences(of: "$appLine", with: appLine ?? "unknown")
|
|
|
|
.replacingOccurrences(of: "$osLine", with: osLine)
|
|
|
|
.replacingOccurrences(of: "$deviceLine", with: deviceLine ?? "unknown")
|
2024-10-23 15:32:49 +00:00
|
|
|
.replacingOccurrences(of: "$providerName", with: providerName ?? "none")
|
2024-10-28 20:38:26 +00:00
|
|
|
.replacingOccurrences(of: "$providerLastUpdate", with: providerLastUpdate?.localizedDescription(style: .timestamp) ?? "unknown")
|
2024-09-23 13:02:26 +00:00
|
|
|
.replacingOccurrences(of: "$purchasedProducts", with: purchasedProducts.map(\.rawValue).description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension Issue {
|
|
|
|
var template: String {
|
|
|
|
do {
|
|
|
|
guard let templateURL = Bundle.module.url(forResource: "Issue", withExtension: "txt") else {
|
|
|
|
fatalError("Unable to find Issue.txt in Resources")
|
|
|
|
}
|
|
|
|
return try String(contentsOf: templateURL)
|
|
|
|
} catch {
|
|
|
|
fatalError("Unable to parse Issue.txt: \(error)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|