From 59cc7940056bb5fa4ea2cdc0c8bac0d33e4abc9f Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Wed, 14 Jun 2023 10:24:09 -0700 Subject: [PATCH] `debugRevenueCatOverlay`: display `receiptURL` Useful when debugging issues like #2558. --- Sources/Purchasing/Purchases/Purchases.swift | 4 ++ .../Support/DebugUI/DebugContentViews.swift | 43 ++++++++++++++----- Sources/Support/DebugUI/DebugViewModel.swift | 4 +- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Sources/Purchasing/Purchases/Purchases.swift b/Sources/Purchasing/Purchases/Purchases.swift index 7142d82f3a..b5b8b6b194 100644 --- a/Sources/Purchasing/Purchases/Purchases.swift +++ b/Sources/Purchasing/Purchases/Purchases.swift @@ -1439,6 +1439,10 @@ internal extension Purchases { return self.systemInfo.responseVerificationMode.publicKey } + var receiptURL: URL? { + return self.receiptFetcher.receiptURL + } + } #endif diff --git a/Sources/Support/DebugUI/DebugContentViews.swift b/Sources/Support/DebugUI/DebugContentViews.swift index 7942abc5fc..393d0a83d3 100644 --- a/Sources/Support/DebugUI/DebugContentViews.swift +++ b/Sources/Support/DebugUI/DebugContentViews.swift @@ -16,6 +16,12 @@ import StoreKit import SwiftUI +#if os(macOS) +import AppKit +#endif + +// swiftlint:disable file_length + @available(iOS 16.0, macOS 13.0, *) struct DebugSwiftUIRootView: View { @@ -113,18 +119,35 @@ internal struct DebugSummaryView: View { Text("Loading...") case let .loaded(config): - LabeledContent("SDK version", value: config.sdkVersion) - LabeledContent("Observer mode", value: config.observerMode.description) - LabeledContent("Sandbox", value: config.sandbox.description) - LabeledContent("StoreKit 2", value: config.storeKit2Enabled ? "on" : "off") - LabeledContent("Offline Customer Info", - value: config.offlineCustomerInfoSupport ? "enabled" : "disabled") - LabeledContent("Entitlement Verification Mode", value: config.verificationMode) - - ShareLink(item: config, preview: .init("Configuration")) { - Label("Share", systemImage: "square.and.arrow.up") + Group { + LabeledContent("SDK version", value: config.sdkVersion) + LabeledContent("Observer mode", value: config.observerMode.description) + LabeledContent("Sandbox", value: config.sandbox.description) + LabeledContent("StoreKit 2", value: config.storeKit2Enabled ? "on" : "off") + LabeledContent("Offline Customer Info", + value: config.offlineCustomerInfoSupport ? "enabled" : "disabled") + LabeledContent("Entitlement Verification Mode", value: config.verificationMode) + LabeledContent("Receipt URL", value: config.receiptURL?.absoluteString ?? "") + #if os(macOS) + .contextMenu { + Button { + if let url = config.receiptURL { + NSWorkspace.shared.selectFile( + nil, + inFileViewerRootedAtPath: url.deletingLastPathComponent().path + ) + } + } label: { + Text("Show in Finder") + } + } + #endif + ShareLink(item: config, preview: .init("Configuration")) { + Label("Share", systemImage: "square.and.arrow.up") + } } + .textSelection(.enabled) .frame(maxWidth: .infinity) } } diff --git a/Sources/Support/DebugUI/DebugViewModel.swift b/Sources/Support/DebugUI/DebugViewModel.swift index 4e0ef8fb25..df71173ba7 100644 --- a/Sources/Support/DebugUI/DebugViewModel.swift +++ b/Sources/Support/DebugUI/DebugViewModel.swift @@ -29,6 +29,7 @@ final class DebugViewModel: ObservableObject { var storeKit2Enabled: Bool var offlineCustomerInfoSupport: Bool var verificationMode: String + var receiptURL: URL? } @@ -125,7 +126,8 @@ private extension DebugViewModel.Configuration { sandbox: purchases.isSandbox, storeKit2Enabled: purchases.storeKit2Setting.isEnabledAndAvailable, offlineCustomerInfoSupport: purchases.offlineCustomerInfoEnabled, - verificationMode: purchases.responseVerificationMode.display + verificationMode: purchases.responseVerificationMode.display, + receiptURL: purchases.receiptURL ) }