Commit 9f25d3ae32
Verified · cmc
Layout: unified · split
Products.storekit added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | { | |
| 2 | "appPolicies" : { | |
| 3 | "eula" : "", | |
| 4 | "policies" : [ | |
| 5 | { | |
| 6 | "locale" : "en_US", | |
| 7 | "policyText" : "", | |
| 8 | "policyURL" : "" | |
| 9 | } | |
| 10 | ] | |
| 11 | }, | |
| 12 | "identifier" : "4B7E2C19", | |
| 13 | "nonRenewingSubscriptions" : [ | |
| 14 | ||
| 15 | ], | |
| 16 | "products" : [ | |
| 17 | { | |
| 18 | "displayPrice" : "4.99", | |
| 19 | "familyShareable" : false, | |
| 20 | "internalID" : "A3F1C2D3", | |
| 21 | "localizations" : [ | |
| 22 | { | |
| 23 | "description" : "Large Tip", | |
| 24 | "displayName" : "Large Tip", | |
| 25 | "locale" : "en_US" | |
| 26 | } | |
| 27 | ], | |
| 28 | "productID" : "org.gitbay.gitbay.tip.large", | |
| 29 | "referenceName" : "Large Tip", | |
| 30 | "type" : "Consumable" | |
| 31 | }, | |
| 32 | { | |
| 33 | "displayPrice" : "2.99", | |
| 34 | "familyShareable" : false, | |
| 35 | "internalID" : "B4E2D3E4", | |
| 36 | "localizations" : [ | |
| 37 | { | |
| 38 | "description" : "Medium Tip", | |
| 39 | "displayName" : "Medium Tip", | |
| 40 | "locale" : "en_US" | |
| 41 | } | |
| 42 | ], | |
| 43 | "productID" : "org.gitbay.gitbay.tip.medium", | |
| 44 | "referenceName" : "Medium Tip", | |
| 45 | "type" : "Consumable" | |
| 46 | }, | |
| 47 | { | |
| 48 | "displayPrice" : "0.99", | |
| 49 | "familyShareable" : false, | |
| 50 | "internalID" : "C5D3E4F5", | |
| 51 | "localizations" : [ | |
| 52 | { | |
| 53 | "description" : "Small Tip", | |
| 54 | "displayName" : "Small Tip", | |
| 55 | "locale" : "en_US" | |
| 56 | } | |
| 57 | ], | |
| 58 | "productID" : "org.gitbay.gitbay.tip.small", | |
| 59 | "referenceName" : "Small Tip", | |
| 60 | "type" : "Consumable" | |
| 61 | } | |
| 62 | ], | |
| 63 | "settings" : { | |
| 64 | "_askToBuyEnabled" : false, | |
| 65 | "_billingGracePeriodEnabled" : false, | |
| 66 | "_billingIssuesEnabled" : false, | |
| 67 | "_disableDialogs" : false, | |
| 68 | "_failTransactionsEnabled" : false, | |
| 69 | "_locale" : "en_US", | |
| 70 | "_renewalBillingIssuesEnabled" : false, | |
| 71 | "_storefront" : "USA", | |
| 72 | "_storeKitErrors" : [ | |
| 73 | ||
| 74 | ], | |
| 75 | "_timeRate" : 0 | |
| 76 | }, | |
| 77 | "subscriptionGroups" : [ | |
| 78 | ||
| 79 | ], | |
| 80 | "version" : { | |
| 81 | "major" : 5, | |
| 82 | "minor" : 0 | |
| 83 | } | |
| 84 | } | |
README.org +3
| @@ -1,6 +1,9 @@ | ||
| 1 | 1 | #+title: gitbay-ios |
| 2 | 2 | #+author: Christian Cleberg |
| 3 | 3 | |
| 4 | Support the app with a tip in the app (My Profile → account menu → Tip Jar) or | |
| 5 | through [[https://github.com/sponsors/ccleberg][GitHub Sponsors]]. | |
| 6 | ||
| 4 | 7 | A native iOS client for [[https://gitbay.org][gitbay]], a CLI-first git forge. |
| 5 | 8 | |
| 6 | 9 | This app is a reading, reviewing and responding surface for the times you are |
gitbay.xcodeproj/xcshareddata/xcschemes/gitbay.xcscheme added +105
| @@ -0,0 +1,105 @@ | ||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <Scheme | |
| 3 | LastUpgradeVersion = "2700" | |
| 4 | version = "1.7"> | |
| 5 | <BuildAction | |
| 6 | parallelizeBuildables = "YES" | |
| 7 | buildImplicitDependencies = "YES" | |
| 8 | buildArchitectures = "Automatic"> | |
| 9 | <BuildActionEntries> | |
| 10 | <BuildActionEntry | |
| 11 | buildForTesting = "YES" | |
| 12 | buildForRunning = "YES" | |
| 13 | buildForProfiling = "YES" | |
| 14 | buildForArchiving = "YES" | |
| 15 | buildForAnalyzing = "YES"> | |
| 16 | <BuildableReference | |
| 17 | BuildableIdentifier = "primary" | |
| 18 | BlueprintIdentifier = "8B289811303FF3E5001BF44A" | |
| 19 | BuildableName = "gitbay.app" | |
| 20 | BlueprintName = "gitbay" | |
| 21 | ReferencedContainer = "container:gitbay.xcodeproj"> | |
| 22 | </BuildableReference> | |
| 23 | </BuildActionEntry> | |
| 24 | </BuildActionEntries> | |
| 25 | </BuildAction> | |
| 26 | <TestAction | |
| 27 | buildConfiguration = "Debug" | |
| 28 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 29 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 30 | shouldUseLaunchSchemeArgsEnv = "YES" | |
| 31 | shouldAutocreateTestPlan = "YES"> | |
| 32 | <Testables> | |
| 33 | <TestableReference | |
| 34 | skipped = "NO" | |
| 35 | parallelizable = "YES"> | |
| 36 | <BuildableReference | |
| 37 | BuildableIdentifier = "primary" | |
| 38 | BlueprintIdentifier = "8B2898A1303FF3E5001BF44A" | |
| 39 | BuildableName = "gitbayTests.xctest" | |
| 40 | BlueprintName = "gitbayTests" | |
| 41 | ReferencedContainer = "container:gitbay.xcodeproj"> | |
| 42 | </BuildableReference> | |
| 43 | </TestableReference> | |
| 44 | <TestableReference | |
| 45 | skipped = "NO" | |
| 46 | parallelizable = "YES"> | |
| 47 | <BuildableReference | |
| 48 | BuildableIdentifier = "primary" | |
| 49 | BlueprintIdentifier = "8B2898C1303FF3E5001BF44A" | |
| 50 | BuildableName = "gitbayUITests.xctest" | |
| 51 | BlueprintName = "gitbayUITests" | |
| 52 | ReferencedContainer = "container:gitbay.xcodeproj"> | |
| 53 | </BuildableReference> | |
| 54 | </TestableReference> | |
| 55 | </Testables> | |
| 56 | </TestAction> | |
| 57 | <LaunchAction | |
| 58 | buildConfiguration = "Debug" | |
| 59 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 60 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 61 | launchStyle = "0" | |
| 62 | useCustomWorkingDirectory = "NO" | |
| 63 | ignoresPersistentStateOnLaunch = "NO" | |
| 64 | debugDocumentVersioning = "YES" | |
| 65 | debugServiceExtension = "internal" | |
| 66 | allowLocationSimulation = "YES"> | |
| 67 | <BuildableProductRunnable | |
| 68 | runnableDebuggingMode = "0"> | |
| 69 | <BuildableReference | |
| 70 | BuildableIdentifier = "primary" | |
| 71 | BlueprintIdentifier = "8B289811303FF3E5001BF44A" | |
| 72 | BuildableName = "gitbay.app" | |
| 73 | BlueprintName = "gitbay" | |
| 74 | ReferencedContainer = "container:gitbay.xcodeproj"> | |
| 75 | </BuildableReference> | |
| 76 | </BuildableProductRunnable> | |
| 77 | <StoreKitConfigurationFileReference | |
| 78 | identifier = "../../Products.storekit"> | |
| 79 | </StoreKitConfigurationFileReference> | |
| 80 | </LaunchAction> | |
| 81 | <ProfileAction | |
| 82 | buildConfiguration = "Release" | |
| 83 | shouldUseLaunchSchemeArgsEnv = "YES" | |
| 84 | savedToolIdentifier = "" | |
| 85 | useCustomWorkingDirectory = "NO" | |
| 86 | debugDocumentVersioning = "YES"> | |
| 87 | <BuildableProductRunnable | |
| 88 | runnableDebuggingMode = "0"> | |
| 89 | <BuildableReference | |
| 90 | BuildableIdentifier = "primary" | |
| 91 | BlueprintIdentifier = "8B289811303FF3E5001BF44A" | |
| 92 | BuildableName = "gitbay.app" | |
| 93 | BlueprintName = "gitbay" | |
| 94 | ReferencedContainer = "container:gitbay.xcodeproj"> | |
| 95 | </BuildableReference> | |
| 96 | </BuildableProductRunnable> | |
| 97 | </ProfileAction> | |
| 98 | <AnalyzeAction | |
| 99 | buildConfiguration = "Debug"> | |
| 100 | </AnalyzeAction> | |
| 101 | <ArchiveAction | |
| 102 | buildConfiguration = "Release" | |
| 103 | revealArchiveInOrganizer = "YES"> | |
| 104 | </ArchiveAction> | |
| 105 | </Scheme> | |
gitbay/Account/TipStoreViewModel.swift added +130
| @@ -0,0 +1,130 @@ | ||
| 1 | import Foundation | |
| 2 | import Observation | |
| 3 | import StoreKit | |
| 4 | ||
| 5 | /// One-time consumable tips through StoreKit 2. They unlock nothing. | |
| 6 | @Observable | |
| 7 | @MainActor | |
| 8 | final class TipStoreViewModel { | |
| 9 | ||
| 10 | enum TipProduct: String, CaseIterable { | |
| 11 | case small | |
| 12 | case medium | |
| 13 | case large | |
| 14 | ||
| 15 | var id: String { | |
| 16 | "org.gitbay.gitbay.tip.\(rawValue)" | |
| 17 | } | |
| 18 | ||
| 19 | var displayName: String { | |
| 20 | switch self { | |
| 21 | case .small: "Small Tip" | |
| 22 | case .medium: "Medium Tip" | |
| 23 | case .large: "Large Tip" | |
| 24 | } | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | static let productIDs = TipProduct.allCases.map(\.id) | |
| 29 | ||
| 30 | private(set) var products: [Product] = [] | |
| 31 | private(set) var isLoading = false | |
| 32 | private(set) var isRestoringPurchases = false | |
| 33 | private(set) var purchasingProductID: String? | |
| 34 | private(set) var errorMessage: String? | |
| 35 | private(set) var statusMessage: String? | |
| 36 | ||
| 37 | // Assigned once in init and read once from the nonisolated deinit. | |
| 38 | @ObservationIgnored nonisolated(unsafe) private var transactionUpdatesTask: Task<Void, Never>? | |
| 39 | ||
| 40 | init() { | |
| 41 | transactionUpdatesTask = Task.detached(priority: .background) { | |
| 42 | for await verification in Transaction.updates { | |
| 43 | guard case .verified(let transaction) = verification else { continue } | |
| 44 | await transaction.finish() | |
| 45 | } | |
| 46 | } | |
| 47 | } | |
| 48 | ||
| 49 | deinit { | |
| 50 | transactionUpdatesTask?.cancel() | |
| 51 | } | |
| 52 | ||
| 53 | func loadProducts() async { | |
| 54 | guard !isLoading else { return } | |
| 55 | ||
| 56 | isLoading = true | |
| 57 | errorMessage = nil | |
| 58 | defer { isLoading = false } | |
| 59 | ||
| 60 | do { | |
| 61 | let fetched = try await Product.products(for: Self.productIDs) | |
| 62 | let productsByID = Dictionary(uniqueKeysWithValues: fetched.map { ($0.id, $0) }) | |
| 63 | let missing = TipProduct.allCases.filter { productsByID[$0.id] == nil } | |
| 64 | ||
| 65 | products = TipProduct.allCases.compactMap { productsByID[$0.id] } | |
| 66 | ||
| 67 | if !missing.isEmpty { | |
| 68 | let names = missing.map(\.displayName).joined(separator: ", ") | |
| 69 | errorMessage = "Missing products from the App Store response: \(names). Confirm the product identifiers match App Store Connect exactly and that each item is approved or available in sandbox." | |
| 70 | } | |
| 71 | } catch { | |
| 72 | products = [] | |
| 73 | errorMessage = "Couldn't load tips from the App Store. \(error.localizedDescription)" | |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | func purchase(_ product: Product) async { | |
| 78 | guard purchasingProductID == nil else { return } | |
| 79 | ||
| 80 | purchasingProductID = product.id | |
| 81 | errorMessage = nil | |
| 82 | statusMessage = nil | |
| 83 | defer { purchasingProductID = nil } | |
| 84 | ||
| 85 | do { | |
| 86 | switch try await product.purchase() { | |
| 87 | case .success(let verification): | |
| 88 | switch verification { | |
| 89 | case .verified(let transaction): | |
| 90 | await transaction.finish() | |
| 91 | statusMessage = "Purchase completed successfully." | |
| 92 | case .unverified(_, let error): | |
| 93 | errorMessage = "The App Store returned an unverified transaction. \(error.localizedDescription)" | |
| 94 | } | |
| 95 | case .pending: | |
| 96 | statusMessage = "Purchase is pending approval." | |
| 97 | case .userCancelled: | |
| 98 | break | |
| 99 | @unknown default: | |
| 100 | errorMessage = "The App Store returned an unknown purchase result." | |
| 101 | } | |
| 102 | } catch { | |
| 103 | errorMessage = "Purchase failed. \(error.localizedDescription)" | |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 107 | func restorePurchases() async { | |
| 108 | guard !isRestoringPurchases else { return } | |
| 109 | ||
| 110 | isRestoringPurchases = true | |
| 111 | errorMessage = nil | |
| 112 | defer { isRestoringPurchases = false } | |
| 113 | ||
| 114 | do { | |
| 115 | try await AppStore.sync() | |
| 116 | statusMessage = "Purchase history synced with the App Store." | |
| 117 | await loadProducts() | |
| 118 | } catch { | |
| 119 | errorMessage = "Couldn't sync purchases. \(error.localizedDescription)" | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | func clearStatusMessage() { | |
| 124 | statusMessage = nil | |
| 125 | } | |
| 126 | ||
| 127 | func isPurchasing(_ product: Product) -> Bool { | |
| 128 | purchasingProductID == product.id | |
| 129 | } | |
| 130 | } | |
gitbay/ContentView.swift +2
| @@ -351,6 +351,8 @@ private struct RouteDestinations: ViewModifier { | ||
| 351 | 351 | WebSessionsView(client: client) |
| 352 | 352 | case .addAccount: |
| 353 | 353 | SignInView() |
| 354 | case .tipJar: | |
| 355 | TipJarView() | |
| 354 | 356 | case .notifications: |
| 355 | 357 | NotificationsView(client: client) |
| 356 | 358 | case .admin: |
gitbay/Views/Account/TipJarView.swift added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | import StoreKit | |
| 2 | import SwiftUI | |
| 3 | ||
| 4 | /// Optional one-time tips. Reached from the account menu. | |
| 5 | struct TipJarView: View { | |
| 6 | ||
| 7 | @State private var store = TipStoreViewModel() | |
| 8 | ||
| 9 | private var busy: Bool { | |
| 10 | store.purchasingProductID != nil || store.isRestoringPurchases | |
| 11 | } | |
| 12 | ||
| 13 | var body: some View { | |
| 14 | List { | |
| 15 | Section { | |
| 16 | if store.isLoading { | |
| 17 | ProgressView("Loading tip options…") | |
| 18 | } else if store.products.isEmpty { | |
| 19 | VStack(alignment: .leading, spacing: 8) { | |
| 20 | Text("Tips unavailable") | |
| 21 | .font(.gbSans(.headline)) | |
| 22 | Text(store.errorMessage ?? "gitbay couldn't load tip products from the App Store yet.") | |
| 23 | .font(.gbSans(.subheadline)) | |
| 24 | .foregroundStyle(.secondary) | |
| 25 | } | |
| 26 | .padding(.vertical, 4) | |
| 27 | } else { | |
| 28 | ForEach(store.products, id: \.id) { product in | |
| 29 | Button { | |
| 30 | Task { await store.purchase(product) } | |
| 31 | } label: { | |
| 32 | HStack { | |
| 33 | Text(product.displayName) | |
| 34 | .font(.gbSans(.body)) | |
| 35 | Spacer() | |
| 36 | if store.isPurchasing(product) { | |
| 37 | ProgressView() | |
| 38 | .controlSize(.small) | |
| 39 | } else { | |
| 40 | Text(product.displayPrice) | |
| 41 | .font(.gbSans(.body)) | |
| 42 | .foregroundStyle(.secondary) | |
| 43 | } | |
| 44 | } | |
| 45 | } | |
| 46 | .disabled(busy) | |
| 47 | } | |
| 48 | } | |
| 49 | ||
| 50 | if let errorMessage = store.errorMessage, !store.products.isEmpty { | |
| 51 | GBNotice(errorMessage, .gbWarn) | |
| 52 | } | |
| 53 | ||
| 54 | Button("Retry Loading Tips") { | |
| 55 | Task { await store.loadProducts() } | |
| 56 | } | |
| 57 | .disabled(store.isLoading || store.purchasingProductID != nil) | |
| 58 | ||
| 59 | Button(store.isRestoringPurchases ? "Syncing Purchases…" : "Restore / Sync Purchases") { | |
| 60 | Task { await store.restorePurchases() } | |
| 61 | } | |
| 62 | .disabled(store.isLoading || busy) | |
| 63 | } header: { | |
| 64 | Text("Support Development") | |
| 65 | } footer: { | |
| 66 | Text("Tips help cover the costs of development and App Store distribution. They are one-time purchases and do not unlock any features.") | |
| 67 | } | |
| 68 | } | |
| 69 | .navigationTitle("Tip Jar") | |
| 70 | .navigationBarTitleDisplayMode(.inline) | |
| 71 | .alert( | |
| 72 | "Store Message", | |
| 73 | isPresented: Binding( | |
| 74 | get: { store.statusMessage != nil }, | |
| 75 | set: { if !$0 { store.clearStatusMessage() } } | |
| 76 | ) | |
| 77 | ) { | |
| 78 | Button("OK") { store.clearStatusMessage() } | |
| 79 | } message: { | |
| 80 | Text(store.statusMessage ?? "") | |
| 81 | } | |
| 82 | .task { await store.loadProducts() } | |
| 83 | } | |
| 84 | } | |
gitbay/Views/Repos/RepoListView.swift +3
| @@ -300,6 +300,9 @@ struct AccountMenu: ToolbarContent { | ||
| 300 | 300 | } |
| 301 | 301 | Section { |
| 302 | 302 | NavigationLink("Add Account", value: RepoRoute.addAccount) |
| 303 | NavigationLink(value: RepoRoute.tipJar) { | |
| 304 | Label("Tip Jar", systemImage: "heart") | |
| 305 | } | |
| 303 | 306 | if let current = session.current { |
| 304 | 307 | Button("Sign Out", role: .destructive) { |
| 305 | 308 | Task { await session.remove(current) } |
gitbay/Views/Repos/RepoRoute.swift +1
| @@ -34,6 +34,7 @@ nonisolated enum RepoRoute: Hashable { | ||
| 34 | 34 | case tokens |
| 35 | 35 | case webSessions |
| 36 | 36 | case addAccount |
| 37 | case tipJar | |
| 37 | 38 | case notifications |
| 38 | 39 | case admin |
| 39 | 40 | case adminUsers |