Skip to content

Commit 6e4e87c

Browse files
authored
Extend report (#209)
* fix screen section of the report * report: include app transaction errors * report: include entitlementhandler errors
1 parent d6b878d commit 6e4e87c

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

BrightIntosh/Utils.swift

+29-27
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ func getDeviceMaxBrightness() -> Float {
5656
return 1.59
5757
}
5858

59-
private func getAppTransaction() async -> VerificationResult<AppTransaction>? {
60-
do {
61-
let shared = try await AppTransaction.shared
62-
return shared
63-
} catch {
64-
print("Fetching app transaction failed")
65-
}
66-
return nil
59+
private func getAppTransaction() async throws -> VerificationResult<AppTransaction>? {
60+
return try await AppTransaction.shared
6761
}
6862

6963
func generateReport() async -> String {
@@ -75,33 +69,41 @@ func generateReport() async -> String {
7569
report += "Version: BrightIntosh v\(appVersion)\n"
7670
#endif
7771
report += "Model Identifier: \(getModelIdentifier() ?? "N/A")\n"
78-
if let sharedAppTransaction = await getAppTransaction() {
79-
if case .verified(let appTransaction) = sharedAppTransaction {
80-
report += "Original Purchase Date: \(appTransaction.originalPurchaseDate)\n"
81-
report += "Original App Version: \(appTransaction.originalAppVersion)\n"
82-
report += "Transaction for App Version: \(appTransaction.appVersion)\n"
83-
report += "Transaction Environment: \(appTransaction.environment.rawValue)\n"
84-
}
85-
if case .unverified(_, let verificationError) = sharedAppTransaction {
86-
report +=
87-
"Error: App Transaction: \(verificationError.errorDescription ?? "no error description") - \(verificationError.failureReason ?? "no failure reason")\n"
72+
do {
73+
if let sharedAppTransaction = try await getAppTransaction() {
74+
if case .verified(let appTransaction) = sharedAppTransaction {
75+
report += "Original Purchase Date: \(appTransaction.originalPurchaseDate)\n"
76+
report += "Original App Version: \(appTransaction.originalAppVersion)\n"
77+
report += "Transaction for App Version: \(appTransaction.appVersion)\n"
78+
report += "Transaction Environment: \(appTransaction.environment.rawValue)\n"
79+
}
80+
if case .unverified(_, let verificationError) = sharedAppTransaction {
81+
report += "Error: App Transaction: \(verificationError.errorDescription ?? "no error description") - \(verificationError.failureReason ?? "no failure reason")\n"
82+
}
83+
} else {
84+
report += "Error: No App Transaction available \n"
8885
}
89-
} else {
90-
report += "Error: App Transaction could not be fetched \n"
86+
} catch {
87+
report += "Error: App Transaction could not be fetched: \(error.localizedDescription) \n"
9188
}
9289

93-
let isUnrestricted = try? await EntitlementHandler.shared.isUnrestrictedUser()
94-
report += "Unrestricted user: \(isUnrestricted)\n"
90+
do {
91+
let isUnrestricted = try await EntitlementHandler.shared.isUnrestrictedUser(refresh: true)
92+
report += "Unrestricted user: \(isUnrestricted)\n"
93+
} catch {
94+
report += "Error: EntitlementHandler threw an error: \(error.localizedDescription)\n"
95+
}
9596
do {
9697
let trial = try await TrialData.getTrialData()
97-
report +=
98-
"Trial:\n - Start Date: \(trial.purchaseDate)\n - Current Date: \(trial.currentDate)\n - Remaining: \(trial.getRemainingDays())\n"
98+
report += "Trial:\n - Start Date: \(trial.purchaseDate)\n - Current Date: \(trial.currentDate)\n - Remaining: \(trial.getRemainingDays())\n"
9999
} catch {
100-
report += "Error: Trial Data could not be fetched\n"
100+
report += "Error: Trial Data could not be fetched \(error.localizedDescription)\n"
101101
}
102-
report += "Screens: \(NSScreen.screens.map{$0.localizedName}.joined(separator: ", "))\n"
102+
103+
let screens = NSScreen.screens.map{$0.localizedName}
104+
report += "Screens: \(screens.joined(separator: ", "))\n"
103105
for screen in NSScreen.screens {
104-
report += " - Screen \(NSScreen.screens.map{$0.localizedName}): \(screen.frame.width)x\(screen.frame.height)px\n"
106+
report += " - Screen \(screen.localizedName): \(screen.frame.width)x\(screen.frame.height)px\n"
105107
}
106108
return report
107109
}

0 commit comments

Comments
 (0)