diff --git a/LeCountdown/Subscription/AppGuard.swift b/LeCountdown/Subscription/AppGuard.swift index 5130a4d..7fab0c2 100644 --- a/LeCountdown/Subscription/AppGuard.swift +++ b/LeCountdown/Subscription/AppGuard.swift @@ -36,7 +36,7 @@ extension Notification.Name { @Published private(set) var purchasedTransactions = Set() - var currentBestPlan: StoreKit.Transaction? = nil + @Published var currentBestPlan: StoreKit.Transaction? = nil var updateListenerTask: Task? = nil @@ -124,20 +124,20 @@ extension Notification.Name { } var isSubscriber: Bool { - return false // self.currentPlan != .none + return self.currentPlan != .none } var currentPlan: StorePlan { - #if DEBUG - return .yearly - #else +// #if DEBUG +// return .yearly +// #else if let currentBestPlan = self.currentBestPlan, let plan = StorePlan(rawValue: currentBestPlan.productID) { return plan } return .none - #endif +// #endif } fileprivate func _updateBestPlan() { diff --git a/LeCountdown/Subscription/Store.swift b/LeCountdown/Subscription/Store.swift index 904e6c5..921d09b 100644 --- a/LeCountdown/Subscription/Store.swift +++ b/LeCountdown/Subscription/Store.swift @@ -87,6 +87,7 @@ class Store: ObservableObject { await transaction.finish() DispatchQueue.main.asyncAfter(deadline: DispatchTime(uptimeNanoseconds: 200000), execute: { + Conductor.maestro.playSound(Sound.EX_ATSM_140_Koshi_Chimes_Aria_Tuning_Loop_Wondering_Am) NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil) }) diff --git a/LeCountdown/Subscription/StoreView.swift b/LeCountdown/Subscription/StoreView.swift index 0542f0f..2489de6 100644 --- a/LeCountdown/Subscription/StoreView.swift +++ b/LeCountdown/Subscription/StoreView.swift @@ -29,15 +29,17 @@ fileprivate enum Feature: Int, Identifiable, CaseIterable { struct StoreView: View, StoreDelegate { - @StateObject var store: Store = Store() + @StateObject private var store: Store = Store() - @State var errorMessage: String? = nil + @State private var errorMessage: String? = nil + + @Binding var isPresented: Bool var body: some View { Group { if !self.store.products.isEmpty { - PlanView() + PlanView(isPresented: self.$isPresented) .environmentObject(self.store) } else { ProgressView() @@ -69,9 +71,11 @@ struct PlanView: View { @EnvironmentObject var store: Store -// var productName: String -// var price: String + @State var _loadingProduct: String? = nil + @State var _purchased: Bool = false + @Binding var isPresented: Bool + var body: some View { VStack { @@ -107,17 +111,26 @@ struct PlanView: View { } label: { HStack { Spacer() - VStack { - - if let plan = StorePlan(rawValue: product.id) { - Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3) + + if product.id == self._loadingProduct { + if self._purchased { + Image(systemName: "checkmark.circle.fill") } else { - Text("Plan not found") + ProgressView() + .progressViewStyle(.circular).tint(.white) + } + } else { + VStack { + if let plan = StorePlan(rawValue: product.id) { + Text("\(product.displayPrice) / \(plan.formattedPeriod)").font(.title3) + } else { + Text("Plan not found") + } } - } Spacer() - } + }.frame(height: 44.0) + } .buttonStyle(.borderedProminent) .fontWeight(.medium) @@ -128,7 +141,15 @@ struct PlanView: View { fileprivate func _purchase(product: Product) { Task { - try await store.purchase(product) + self._loadingProduct = product.id + let result = try await store.purchase(product) + switch result { + case .none: + self._loadingProduct = nil + case .some: + self._purchased = true + self.isPresented = false + } } } @@ -192,6 +213,6 @@ struct PlayerWrapperView: View { struct StoreView_Previews: PreviewProvider { static var previews: some View { - PlanView().environmentObject(Store()) + PlanView(isPresented: .constant(false)).environmentObject(Store()) } } diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index 6dfd62d..023f2dd 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -114,7 +114,7 @@ struct ContentView: View { .presentationDetents([.height(240.0)]) }) .sheet(isPresented: self.$showSubscriptionSheet, content: { - StoreView() + StoreView(isPresented: self.$showSubscriptionSheet) }) .toolbar { ToolbarItem(placement: .navigationBarLeading) { diff --git a/LeCountdown/Views/PresetsView.swift b/LeCountdown/Views/PresetsView.swift index e3fa023..3c66b95 100644 --- a/LeCountdown/Views/PresetsView.swift +++ b/LeCountdown/Views/PresetsView.swift @@ -113,7 +113,7 @@ struct PresetsView: View { .environment(\.managedObjectContext, viewContext) }) .sheet(isPresented: $isShowingSubscription, content: { - StoreView() + StoreView(isPresented: self.$isShowingSubscription) }) .navigationTitle("Create") } diff --git a/LeCountdown/fr.lproj/Localizable.strings b/LeCountdown/fr.lproj/Localizable.strings index 9bbe9e1..748947d 100644 --- a/LeCountdown/fr.lproj/Localizable.strings +++ b/LeCountdown/fr.lproj/Localizable.strings @@ -257,3 +257,4 @@ "Confirmation" = "Confirmation"; "month" = "mois"; "year" = "an"; +"Get fully enchanted" = "Enchantement permanent";