2022-04-12 13:09:14 +00:00
|
|
|
//
|
2022-06-19 12:41:26 +00:00
|
|
|
// Constants+App.swift
|
2022-04-12 13:09:14 +00:00
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/15/18.
|
2023-03-17 15:56:19 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +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
|
2023-05-24 16:19:47 +00:00
|
|
|
import PassepartoutLibrary
|
2023-04-04 07:50:45 +00:00
|
|
|
import UniformTypeIdentifiers
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
extension Constants {
|
|
|
|
enum App {
|
2022-06-25 12:57:09 +00:00
|
|
|
static var appId: String {
|
|
|
|
guard let identifier = Bundle.main.infoDictionary?[kCFBundleIdentifierKey as String] as? String else {
|
|
|
|
fatalError("Missing kCFBundleIdentifierKey from Info.plist")
|
|
|
|
}
|
|
|
|
return identifier
|
|
|
|
}
|
|
|
|
|
2022-07-03 18:46:30 +00:00
|
|
|
static let appStoreId: String = bundleConfig("appstore_id")
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2022-07-03 18:46:30 +00:00
|
|
|
static let appGroupId: String = bundleConfig("group_id")
|
2022-04-12 13:09:14 +00:00
|
|
|
|
2022-05-18 07:09:29 +00:00
|
|
|
static let isBeta: Bool = {
|
|
|
|
Bundle.main.isTestFlight
|
|
|
|
}()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
enum Plugins {
|
|
|
|
static let macBridgeName = "PassepartoutMac.bundle"
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
enum InApp {
|
|
|
|
static var appType: ProductManager.AppType {
|
|
|
|
if let envString = ProcessInfo.processInfo.environment["APP_TYPE"],
|
|
|
|
let envValue = Int(envString),
|
|
|
|
let testAppType = ProductManager.AppType(rawValue: envValue) {
|
|
|
|
|
|
|
|
return testAppType
|
|
|
|
}
|
2022-07-03 18:46:30 +00:00
|
|
|
if let infoValue: Int = bundleConfig("app_type"),
|
2022-04-12 13:09:14 +00:00
|
|
|
let testAppType = ProductManager.AppType(rawValue: infoValue) {
|
|
|
|
|
|
|
|
return testAppType
|
|
|
|
}
|
2022-05-05 07:18:53 +00:00
|
|
|
return App.isBeta ? .beta : .freemium
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 12:32:15 +00:00
|
|
|
#if targetEnvironment(macCatalyst)
|
2022-04-26 18:40:51 +00:00
|
|
|
static let buildProducts = BuildProducts {
|
|
|
|
if $0 <= 3000 {
|
|
|
|
return [.networkSettings]
|
|
|
|
}
|
|
|
|
return []
|
|
|
|
}
|
2022-04-19 12:32:15 +00:00
|
|
|
#else
|
2022-04-26 18:40:51 +00:00
|
|
|
static let buildProducts = BuildProducts {
|
|
|
|
if $0 <= 2016 {
|
|
|
|
return [.fullVersion_iOS]
|
|
|
|
} else if $0 <= 3000 {
|
|
|
|
return [.networkSettings]
|
|
|
|
}
|
|
|
|
return []
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Constants {
|
|
|
|
enum Activities {
|
|
|
|
static let enableVPN = "EnableVPNIntent"
|
|
|
|
|
|
|
|
static let disableVPN = "DisableVPNIntent"
|
|
|
|
|
|
|
|
static let connectVPN = "ConnectVPNIntent"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let moveToLocation = "MoveToLocationIntent"
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let trustCellularNetwork = "TrustCellularNetworkIntent"
|
|
|
|
|
|
|
|
static let trustCurrentNetwork = "TrustCurrentNetworkIntent"
|
|
|
|
|
|
|
|
static let untrustCellularNetwork = "UntrustCellularNetworkIntent"
|
|
|
|
|
|
|
|
static let untrustCurrentNetwork = "UntrustCurrentNetworkIntent"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Constants {
|
|
|
|
enum Domain {
|
|
|
|
static let name = "passepartoutvpn.app"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
enum Services {
|
|
|
|
static let version = "v5"
|
|
|
|
|
|
|
|
private static let connectivityStrings: [String] = [
|
|
|
|
"https://www.amazon.com",
|
|
|
|
"https://www.google.com",
|
|
|
|
"https://www.twitter.com",
|
|
|
|
"https://www.facebook.com",
|
|
|
|
"https://www.instagram.com"
|
|
|
|
]
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let connectivityURL = URL(string: connectivityStrings.randomElement()!)!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let connectivityTimeout: TimeInterval = 10.0
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
enum Persistence {
|
|
|
|
static let profilesContainerName = "Profiles"
|
|
|
|
|
|
|
|
static let providersContainerName = "Providers"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
// milliseconds
|
|
|
|
enum RateLimit {
|
|
|
|
static let providerManager = 10000
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-25 21:05:14 +00:00
|
|
|
static let vpnToggle = 500
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
enum Log {
|
2022-10-16 06:33:32 +00:00
|
|
|
enum App {
|
|
|
|
static let url = containerURL(filename: "App.log")
|
2022-06-04 07:25:15 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
static let format = "$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M"
|
2022-06-04 07:25:15 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
enum Tunnel {
|
|
|
|
static let path = containerPath(filename: "Tunnel.log")
|
2022-06-04 07:25:15 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
static let format = "$DHH:mm:ss$d - $M"
|
2022-06-17 06:27:56 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
private static let parentPath = "Library/Caches"
|
2022-06-17 06:27:56 +00:00
|
|
|
|
2023-05-24 16:19:47 +00:00
|
|
|
static let level: LoggerLevel = {
|
2022-04-12 13:09:14 +00:00
|
|
|
guard let levelString = ProcessInfo.processInfo.environment["LOG_LEVEL"], let levelNum = Int(levelString) else {
|
|
|
|
return .info
|
|
|
|
}
|
|
|
|
return .init(rawValue: levelNum) ?? .info
|
|
|
|
}()
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
static let maxBytes = 100000
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-10-16 06:33:32 +00:00
|
|
|
static let refreshInterval: TimeInterval = 5.0
|
|
|
|
|
|
|
|
private static func containerURL(filename: String) -> URL {
|
|
|
|
Files.containerURL
|
|
|
|
.appendingPathComponent(parentPath)
|
|
|
|
.appendingPathComponent(filename)
|
|
|
|
}
|
|
|
|
|
|
|
|
private static func containerPath(filename: String) -> String {
|
2023-05-28 09:57:35 +00:00
|
|
|
[parentPath, filename].joined(separator: "/")
|
2022-10-16 06:33:32 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
enum URLs {
|
|
|
|
static let readme = Repos.apple.appendingPathComponent("blob/master/README.md")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-19 14:17:13 +00:00
|
|
|
static let changelog = Repos.apple.appendingPathComponent("blob/master/CHANGELOG.md")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let filetypes: [UTType] = [.item]
|
|
|
|
|
|
|
|
static let website = URL(string: "https://\(Domain.name)")!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let faq = website.appendingPathComponent("faq")
|
|
|
|
|
|
|
|
static let disclaimer = website.appendingPathComponent("disclaimer")
|
|
|
|
|
|
|
|
static let privacyPolicy = website.appendingPathComponent("privacy")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let donate = website.appendingPathComponent("donate")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let subreddit = URL(string: "https://www.reddit.com/r/passepartout")!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let twitch = URL(string: "twitch://stream/keeshux")!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let twitchFallback = URL(string: "https://twitch.tv/keeshux")!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let githubSponsors = URL(string: "https://www.github.com/sponsors/passepartoutvpn")!
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Repos {
|
|
|
|
private static let githubRoot = URL(string: "https://github.com/passepartoutvpn/")!
|
|
|
|
|
|
|
|
private static let githubRawRoot = URL(string: "https://\(Domain.name)/")!
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
private static func github(repo: String) -> URL {
|
2022-09-04 18:09:31 +00:00
|
|
|
githubRoot.appendingPathComponent(repo)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
private static func githubRaw(repo: String) -> URL {
|
2022-09-04 18:09:31 +00:00
|
|
|
githubRawRoot.appendingPathComponent(repo)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let apple = github(repo: "passepartout-apple")
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
static let api = githubRaw(repo: "api")
|
|
|
|
}
|
|
|
|
|
|
|
|
// milliseconds
|
|
|
|
enum Delays {
|
|
|
|
static let scrolling = 100
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
// @available(*, deprecated, message: "file importer stops showing again after closing with swipe down")
|
|
|
|
static let xxxPresentFileImporter = 200
|
|
|
|
|
|
|
|
// @available(*, deprecated, message: "edited shortcut is outdated in delegate")
|
|
|
|
static let xxxReloadEditedShortcut = 200
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
enum Rating {
|
2022-04-19 12:32:15 +00:00
|
|
|
#if targetEnvironment(macCatalyst)
|
2022-04-12 13:09:14 +00:00
|
|
|
static let eventCount = 10
|
2022-04-19 12:32:15 +00:00
|
|
|
#else
|
|
|
|
static let eventCount = 3
|
2022-04-12 13:09:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Constants {
|
|
|
|
enum Files {
|
2022-06-04 07:25:15 +00:00
|
|
|
fileprivate static var containerURL: URL {
|
2022-04-12 13:09:14 +00:00
|
|
|
guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: App.appGroupId) else {
|
|
|
|
print("Unable to access App Group container")
|
|
|
|
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
|
|
|
}
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|