Remove in-app sponsor
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
import StoreKit
|
||||
import SwiftUI
|
||||
|
||||
public struct SettingView: View {
|
||||
@@ -12,7 +11,7 @@ public struct SettingView: View {
|
||||
case app
|
||||
#endif
|
||||
|
||||
case core, packetTunnel, profileOverride, sponsor
|
||||
case core, packetTunnel, profileOverride, sponsors
|
||||
|
||||
var label: some View {
|
||||
Label(title, systemImage: iconImage)
|
||||
@@ -30,8 +29,8 @@ public struct SettingView: View {
|
||||
return NSLocalizedString("Packet Tunnel", comment: "")
|
||||
case .profileOverride:
|
||||
return NSLocalizedString("Profile Override", comment: "")
|
||||
case .sponsor:
|
||||
return NSLocalizedString("Sponsor", comment: "")
|
||||
case .sponsors:
|
||||
return NSLocalizedString("Sponsors", comment: "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ public struct SettingView: View {
|
||||
return "aspectratio.fill"
|
||||
case .profileOverride:
|
||||
return "square.dashed.inset.filled"
|
||||
case .sponsor:
|
||||
case .sponsors:
|
||||
return "heart.fill"
|
||||
}
|
||||
}
|
||||
@@ -66,8 +65,8 @@ public struct SettingView: View {
|
||||
PacketTunnelView()
|
||||
case .profileOverride:
|
||||
ProfileOverrideView()
|
||||
case .sponsor:
|
||||
SponsorView()
|
||||
case .sponsors:
|
||||
SponsorsView()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
@@ -109,7 +108,7 @@ public struct SettingView: View {
|
||||
Label("Rate on the App Store", systemImage: "text.bubble.fill")
|
||||
}
|
||||
#endif
|
||||
Tabs.sponsor.navigationLink
|
||||
Tabs.sponsors.navigationLink
|
||||
}
|
||||
Section("Debug") {
|
||||
NavigationLink {
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import Foundation
|
||||
import StoreKit
|
||||
import SwiftUI
|
||||
|
||||
public struct SponsorView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
|
||||
@State private var isLoading = true
|
||||
@State private var products: [Product] = []
|
||||
@State private var subscriptionError: Error?
|
||||
@State private var isPurchasing = false
|
||||
@State private var alert: Alert?
|
||||
|
||||
public init() {}
|
||||
public var body: some View {
|
||||
FormView {
|
||||
Section {
|
||||
EmptyView()
|
||||
} footer: {
|
||||
Text("**If I’ve defended your modern life, please consider sponsoring me.**")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
Section("Without commission") {
|
||||
FormButton("GitHub Sponsor (recommended)") {
|
||||
openURL(URL(string: "https://github.com/sponsors/nekohasekai")!)
|
||||
}
|
||||
FormButton("Other methods") {
|
||||
openURL(URL(string: "https://sekai.icu/sponsor/")!)
|
||||
}
|
||||
}
|
||||
Section("Via App Store") {
|
||||
if isLoading {
|
||||
ProgressView()
|
||||
.onAppear {
|
||||
Task.detached {
|
||||
await loadProducts()
|
||||
}
|
||||
}
|
||||
} else if let subscriptionError {
|
||||
Text("Sponsor via App Store not available: \(subscriptionError.localizedDescription)")
|
||||
} else {
|
||||
ForEach(products, id: \.id) { it in
|
||||
FormButton(it.displayName) {
|
||||
isPurchasing = true
|
||||
Task.detached {
|
||||
do {
|
||||
let result = try await it.purchase()
|
||||
switch result {
|
||||
case .success:
|
||||
alert = Alert(title: Text("Success"), message: Text("Thank u."))
|
||||
case .pending:
|
||||
break
|
||||
case .userCancelled:
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
alert = Alert(error)
|
||||
}
|
||||
isPurchasing = false
|
||||
}
|
||||
}
|
||||
.disabled(isPurchasing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.alertBinding($alert)
|
||||
.navigationTitle("Sponsor")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
|
||||
private func loadProducts() async {
|
||||
defer {
|
||||
isLoading = false
|
||||
}
|
||||
do {
|
||||
let productIds = ["sponsor_1_1", "sponsor_10", "sponsor_100"]
|
||||
products = try await Product.products(for: productIds)
|
||||
} catch {
|
||||
subscriptionError = error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
public struct SponsorsView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
|
||||
public init() {}
|
||||
public var body: some View {
|
||||
FormView {
|
||||
Section {
|
||||
EmptyView()
|
||||
} footer: {
|
||||
Text(
|
||||
"""
|
||||
**If I’ve defended your modern life, please consider sponsoring me.**
|
||||
|
||||
_sing-box is completely free and open source, sponsorships to the developer are voluntary and you will not receive any digital content or services._
|
||||
""")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
FormButton("GitHub Sponsor (recommended)") {
|
||||
openURL(URL(string: "https://github.com/sponsors/nekohasekai")!)
|
||||
}
|
||||
FormButton("Other methods") {
|
||||
openURL(URL(string: "https://sekai.icu/sponsors/")!)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Sponsors")
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user