2021-01-01 10:13:41 +00:00
|
|
|
//
|
2021-09-27 15:59:01 +00:00
|
|
|
// LocalProduct.swift
|
2021-01-01 10:13:41 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 10/11/19.
|
2023-03-17 15:56:19 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2021-01-01 10:13:41 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2022-06-23 21:31:01 +00:00
|
|
|
import PassepartoutLibrary
|
2023-04-04 07:50:45 +00:00
|
|
|
import StoreKit
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
struct LocalProduct: RawRepresentable, Equatable, Hashable {
|
2021-01-01 10:13:41 +00:00
|
|
|
private static let bundleSubdomain = "ios"
|
|
|
|
|
|
|
|
private static let bundle = "com.algoritmico.\(bundleSubdomain).Passepartout"
|
|
|
|
|
|
|
|
private static let donationsBundle = "\(bundle).donations"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2021-01-01 10:13:41 +00:00
|
|
|
private static let featuresBundle = "\(bundle).features"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let providersBundle = "\(bundle).providers"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2021-01-01 10:13:41 +00:00
|
|
|
// MARK: Donations
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let tinyDonation = LocalProduct(donationDescription: "Tiny")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let smallDonation = LocalProduct(donationDescription: "Small")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let mediumDonation = LocalProduct(donationDescription: "Medium")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let bigDonation = LocalProduct(donationDescription: "Big")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let hugeDonation = LocalProduct(donationDescription: "Huge")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let maxiDonation = LocalProduct(donationDescription: "Maxi")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let allDonations: [LocalProduct] = [
|
2021-01-01 10:13:41 +00:00
|
|
|
.tinyDonation,
|
|
|
|
.smallDonation,
|
|
|
|
.mediumDonation,
|
|
|
|
.bigDonation,
|
|
|
|
.hugeDonation,
|
|
|
|
.maxiDonation
|
|
|
|
]
|
|
|
|
|
|
|
|
private init(donationDescription: String) {
|
2021-09-27 15:59:01 +00:00
|
|
|
self.init(rawValue: "\(LocalProduct.donationsBundle).\(donationDescription)")!
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Features
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let allProviders = LocalProduct(featureId: "all_providers")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-13 18:12:25 +00:00
|
|
|
static let networkSettings = LocalProduct(featureId: "network_settings")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let trustedNetworks = LocalProduct(featureId: "trusted_networks")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let siriShortcuts = LocalProduct(featureId: "siri")
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let fullVersion_iOS = LocalProduct(featureId: "full_version")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let fullVersion_macOS = LocalProduct(featureId: "full_mac_version")
|
2021-02-02 09:11:04 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let fullVersion = LocalProduct(featureId: "full_multi_version")
|
2021-02-02 09:11:04 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let allFeatures: [LocalProduct] = [
|
2021-02-07 11:48:27 +00:00
|
|
|
.allProviders,
|
2022-04-13 18:12:25 +00:00
|
|
|
.networkSettings,
|
2021-01-01 10:13:41 +00:00
|
|
|
.trustedNetworks,
|
|
|
|
.siriShortcuts,
|
2021-02-02 09:11:04 +00:00
|
|
|
.fullVersion_iOS,
|
|
|
|
.fullVersion_macOS,
|
2021-01-01 10:13:41 +00:00
|
|
|
.fullVersion
|
|
|
|
]
|
|
|
|
|
|
|
|
private init(featureId: String) {
|
2021-09-27 15:59:01 +00:00
|
|
|
self.init(rawValue: "\(LocalProduct.featuresBundle).\(featureId)")!
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: All
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static var all: [LocalProduct] {
|
2022-09-04 18:09:31 +00:00
|
|
|
allDonations + allFeatures// + allProviders
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var isDonation: Bool {
|
2022-09-04 18:09:31 +00:00
|
|
|
rawValue.hasPrefix(LocalProduct.donationsBundle)
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var isFeature: Bool {
|
2022-09-04 18:09:31 +00:00
|
|
|
rawValue.hasPrefix(LocalProduct.featuresBundle)
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var isProvider: Bool {
|
2022-09-04 18:09:31 +00:00
|
|
|
rawValue.hasPrefix(LocalProduct.providersBundle)
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2021-01-01 10:13:41 +00:00
|
|
|
// MARK: RawRepresentable
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
let rawValue: String
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
init?(rawValue: String) {
|
2021-01-01 10:13:41 +00:00
|
|
|
self.rawValue = rawValue
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2021-01-01 10:13:41 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
extension LocalProduct {
|
|
|
|
func matchesStoreKitProduct(_ skProduct: SKProduct) -> Bool {
|
2022-09-04 18:09:31 +00:00
|
|
|
skProduct.productIdentifier == rawValue
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ProviderName {
|
|
|
|
var product: LocalProduct {
|
|
|
|
.init(rawValue: "\(LocalProduct.providersBundle).\(inApp)")!
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
// legacy in-app products
|
|
|
|
private extension ProviderName {
|
|
|
|
var inApp: String {
|
|
|
|
switch self {
|
|
|
|
case .mullvad:
|
|
|
|
return "Mullvad"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .nordvpn:
|
|
|
|
return "NordVPN"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .pia:
|
|
|
|
return "PIA"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .protonvpn:
|
|
|
|
return "ProtonVPN"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .tunnelbear:
|
|
|
|
return "TunnelBear"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .vyprvpn:
|
|
|
|
return "VyprVPN"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
case .windscribe:
|
|
|
|
return "Windscribe"
|
|
|
|
|
|
|
|
default:
|
|
|
|
return self
|
|
|
|
}
|
2021-01-01 10:13:41 +00:00
|
|
|
}
|
|
|
|
}
|