passepartout-apple/Passepartout/App/Constants/Constants+App.swift

260 lines
7.6 KiB
Swift
Raw Normal View History

2022-04-12 13:09:14 +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
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
}
static let appStoreId: String = bundleConfig("appstore_id")
2022-04-12 13:09:14 +00:00
static let appGroupId: String = bundleConfig("group_id")
2022-04-12 13:09:14 +00:00
}
2023-03-17 20:55:47 +00:00
enum CloudKit {
static let containerId: String = bundleConfig("cloudkit_id")
2023-12-16 19:58:54 +00:00
static let sharedContainerId: String = bundleConfig("cloudkit_shared_id")
static let coreDataZone = "com.apple.coredata.cloudkit.zone"
}
enum Plugins {
static let macBridgeName = "PassepartoutMac.bundle"
}
2022-04-12 13:09:14 +00:00
enum InApp {
static var overriddenAppType: AppType? {
2022-04-12 13:09:14 +00:00
if let envString = ProcessInfo.processInfo.environment["APP_TYPE"],
let envValue = Int(envString),
let testAppType = AppType(rawValue: envValue) {
2022-04-12 13:09:14 +00:00
return testAppType
}
if let infoValue: Int = bundleConfig("app_type"),
let testAppType = AppType(rawValue: infoValue) {
2022-04-12 13:09:14 +00:00
return testAppType
}
return nil
2022-04-12 13:09:14 +00:00
}
#if targetEnvironment(macCatalyst)
static let buildProducts = BuildProducts {
if $0 <= 3000 {
return [.networkSettings]
}
return []
}
#else
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
2023-12-16 19:58:54 +00:00
static let tvLimitedMinutes = 10
2022-04-12 13:09:14 +00:00
}
}
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"
2023-12-16 19:58:54 +00:00
static let sharedProfilesContainerName = "SharedProfiles"
2022-04-12 13:09:14 +00:00
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
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 {
enum App {
static let url = containerURL(filename: "App.log")
static let format = "$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M"
}
2023-03-17 20:55:47 +00:00
enum Tunnel {
static let path = containerPath(filename: "Tunnel.log")
static let format = "$DHH:mm:ss$d - $M"
}
2023-03-17 20:55:47 +00:00
private static let parentPath = "Library/Caches"
2023-05-24 16:19:47 +00:00
static let level: LoggerLevel = {
guard let levelString = ProcessInfo.processInfo.environment["LOG_LEVEL"],
let levelNum = Int(levelString) else {
return .debug
2022-04-12 13:09:14 +00:00
}
return .init(rawValue: levelNum) ?? .debug
2022-04-12 13:09:14 +00:00
}()
2023-03-17 20:55:47 +00:00
static let maxBytes = 100000
2023-03-17 20:55:47 +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 {
[parentPath, filename].joined(separator: "/")
}
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
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
2023-09-08 20:18:41 +00:00
// @available(*, deprecated, message: "File importer stops showing again after closing with swipe down")
2022-04-12 13:09:14 +00:00
static let xxxPresentFileImporter = 200
}
2023-03-17 20:55:47 +00:00
2022-04-12 13:09:14 +00:00
enum Rating {
#if targetEnvironment(macCatalyst)
2022-04-12 13:09:14 +00:00
static let eventCount = 10
#else
2023-10-14 17:48:52 +00:00
static let eventCount = 20
2022-04-12 13:09:14 +00:00
#endif
}
}
extension Constants {
enum Files {
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
}
}
}