diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3098f87c..a26beeab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -295,69 +295,69 @@ jobs: retention-days: 7 # ------------------------------------------------------ - Build-MacOS-NE: - runs-on: macos-latest + # Build-MacOS-NE: + # runs-on: macos-latest - env: - QT_VERSION: 6.4.3 - QIF_VERSION: 4.6 - QT_MIRROR: https://mirrors.ocf.berkeley.edu/qt/ - PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }} - DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }} + # env: + # QT_VERSION: 6.4.3 + # QIF_VERSION: 4.6 + # QT_MIRROR: https://mirrors.ocf.berkeley.edu/qt/ + # PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }} + # DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }} - steps: - - name: 'Setup Xcode' - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '14.3.1' + # steps: + # - name: 'Setup Xcode' + # uses: maxim-lobanov/setup-xcode@v1 + # with: + # xcode-version: '14.3.1' - - name: 'Install desktop Qt' - uses: jurplel/install-qt-action@v3 - with: - version: ${{ env.QT_VERSION }} - host: 'mac' - target: 'desktop' - modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia' - arch: 'clang_64' - dir: ${{ runner.temp }} - set-env: 'true' - extra: '--base ${{ env.QT_MIRROR }}' - - name: 'Install Qt Installer Framework ${{ env.QIF_VERSION }}' - run: | - mkdir -pv ${{ runner.temp }}/Qt/Tools/QtInstallerFramework - wget https://qt.amzsvc.com/tools/ifw/${{ env.QIF_VERSION }}.zip - unzip ${{ env.QIF_VERSION }}.zip -d ${{ runner.temp }}/Qt/Tools/QtInstallerFramework/ - - name: 'Install Go' - uses: actions/setup-go@v5 - with: - go-version: '1.22.1' - cache: false + # - name: 'Install desktop Qt' + # uses: jurplel/install-qt-action@v3 + # with: + # version: ${{ env.QT_VERSION }} + # host: 'mac' + # target: 'desktop' + # modules: 'qtremoteobjects qt5compat qtshadertools qtmultimedia' + # arch: 'clang_64' + # dir: ${{ runner.temp }} + # set-env: 'true' + # extra: '--base ${{ env.QT_MIRROR }}' + # - name: 'Install Qt Installer Framework ${{ env.QIF_VERSION }}' + # run: | + # mkdir -pv ${{ runner.temp }}/Qt/Tools/QtInstallerFramework + # wget https://qt.amzsvc.com/tools/ifw/${{ env.QIF_VERSION }}.zip + # unzip ${{ env.QIF_VERSION }}.zip -d ${{ runner.temp }}/Qt/Tools/QtInstallerFramework/ + # - name: 'Install Go' + # uses: actions/setup-go@v5 + # with: + # go-version: '1.22.1' + # cache: false - - name: 'Get sources' - uses: actions/checkout@v4 - with: - submodules: 'true' - fetch-depth: 10 + # - name: 'Get sources' + # uses: actions/checkout@v4 + # with: + # submodules: 'true' + # fetch-depth: 10 - - name: 'Install dependencies' - run: pip install jsonschema jinja2 + # - name: 'Install dependencies' + # run: pip install jsonschema jinja2 - - name: 'Set execute permissions for deploy script' - run: chmod +x deploy/build_macos_ne.sh + # - name: 'Set execute permissions for deploy script' + # run: chmod +x deploy/build_macos_ne.sh - - name: 'Build and deploy macOS NE' - run: | - export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin" - export QIF_BIN_DIR="${{ runner.temp }}/Qt/Tools/QtInstallerFramework/${{ env.QIF_VERSION }}/bin" - export QT_MACOS_ROOT_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos" - bash deploy/build_macos_ne.sh - env: - APPSTORE_CONNECT_KEY_ID: ${{ secrets.APPSTORE_CONNECT_KEY_ID }} - APPSTORE_CONNECT_ISSUER_ID: ${{ secrets.APPSTORE_CONNECT_ISSUER_ID }} - APPSTORE_CONNECT_PRIVATE_KEY: ${{ secrets.APPSTORE_CONNECT_PRIVATE_KEY }} - MAC_TRUST_CERT_BASE64: ${{ secrets.IOS_TRUST_CERT_BASE64 }} - MAC_SIGNING_CERT_BASE64: ${{ secrets.IOS_SIGNING_CERT_BASE64 }} - MAC_SIGNING_CERT_PASSWORD: ${{ secrets.IOS_SIGNING_CERT_PASSWORD }} + # - name: 'Build and deploy macOS NE' + # run: | + # export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin" + # export QIF_BIN_DIR="${{ runner.temp }}/Qt/Tools/QtInstallerFramework/${{ env.QIF_VERSION }}/bin" + # export QT_MACOS_ROOT_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos" + # bash deploy/build_macos_ne.sh + # env: + # APPSTORE_CONNECT_KEY_ID: ${{ secrets.APPSTORE_CONNECT_KEY_ID }} + # APPSTORE_CONNECT_ISSUER_ID: ${{ secrets.APPSTORE_CONNECT_ISSUER_ID }} + # APPSTORE_CONNECT_PRIVATE_KEY: ${{ secrets.APPSTORE_CONNECT_PRIVATE_KEY }} + # MAC_TRUST_CERT_BASE64: ${{ secrets.IOS_TRUST_CERT_BASE64 }} + # MAC_SIGNING_CERT_BASE64: ${{ secrets.IOS_SIGNING_CERT_BASE64 }} + # MAC_SIGNING_CERT_PASSWORD: ${{ secrets.IOS_SIGNING_CERT_PASSWORD }} # ------------------------------------------------------ Build-Android: diff --git a/client/cmake/macos_ne.cmake b/client/cmake/macos_ne.cmake index 0a88c8b8..938e7706 100644 --- a/client/cmake/macos_ne.cmake +++ b/client/cmake/macos_ne.cmake @@ -68,7 +68,7 @@ set_target_properties(${PROJECT} PROPERTIES MACOSX_BUNDLE_LONG_VERSION_STRING "${APPLE_PROJECT_VERSION}-${CMAKE_PROJECT_VERSION_TWEAK}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${APPLE_PROJECT_VERSION}" XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${BUILD_IOS_APP_IDENTIFIER}" - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/macos/app/main.entitlements" + XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/ios/app/main.entitlements" XCODE_ATTRIBUTE_MARKETING_VERSION "${APPLE_PROJECT_VERSION}" XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION "${CMAKE_PROJECT_VERSION_TWEAK}" XCODE_ATTRIBUTE_PRODUCT_NAME "AmneziaVPN" @@ -116,13 +116,13 @@ target_sources(${PROJECT} PRIVATE ) target_sources(${PROJECT} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/macos/app/Media.xcassets - ${CMAKE_CURRENT_SOURCE_DIR}/macos/app/PrivacyInfo.xcprivacy + ${CMAKE_CURRENT_SOURCE_DIR}/ios/app/Media.xcassets + ${CMAKE_CURRENT_SOURCE_DIR}/ios/app/PrivacyInfo.xcprivacy ) set_property(TARGET ${PROJECT} APPEND PROPERTY RESOURCE - ${CMAKE_CURRENT_SOURCE_DIR}/macos/app/Media.xcassets - ${CMAKE_CURRENT_SOURCE_DIR}/macos/app/PrivacyInfo.xcprivacy + ${CMAKE_CURRENT_SOURCE_DIR}/ios/app/Media.xcassets + ${CMAKE_CURRENT_SOURCE_DIR}/ios/app/PrivacyInfo.xcprivacy ) add_subdirectory(macos/networkextension) diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/100.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/100.png deleted file mode 100644 index bbe3d546..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/100.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/1024.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/1024.png deleted file mode 100644 index 0f2ba915..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/1024.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/114.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/114.png deleted file mode 100644 index f88f66c7..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/114.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/120.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/120.png deleted file mode 100644 index 51829dc1..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/120.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/144.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/144.png deleted file mode 100644 index 0e28bd7b..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/144.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/152.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/152.png deleted file mode 100644 index 81066df7..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/152.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/167.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/167.png deleted file mode 100644 index 44858c5a..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/167.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/180.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/180.png deleted file mode 100644 index 911f5491..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/180.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/20.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/20.png deleted file mode 100644 index bb44c366..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/20.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/29.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/29.png deleted file mode 100644 index bf9a2c19..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/29.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/40.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/40.png deleted file mode 100644 index dbcf6fad..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/40.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/50.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/50.png deleted file mode 100644 index 83c3e6b7..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/50.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/57.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/57.png deleted file mode 100644 index f2a56e74..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/57.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/58.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/58.png deleted file mode 100644 index 2714c6bf..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/58.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/60.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/60.png deleted file mode 100644 index a7303586..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/60.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/72.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/72.png deleted file mode 100644 index d0f20363..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/72.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/76.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/76.png deleted file mode 100644 index ccf90ddc..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/76.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/80.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/80.png deleted file mode 100644 index 9f7b1037..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/80.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/87.png b/client/macos/app/Media.xcassets/AppIcon.appiconset/87.png deleted file mode 100644 index 918e04f6..00000000 Binary files a/client/macos/app/Media.xcassets/AppIcon.appiconset/87.png and /dev/null differ diff --git a/client/macos/app/Media.xcassets/AppIcon.appiconset/Contents.json b/client/macos/app/Media.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 3d771d98..00000000 --- a/client/macos/app/Media.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,290 +0,0 @@ -{ - "images" : [ - { - "filename" : "40.png", - "idiom" : "iphone", - "scale" : "2x", - "size" : "20x20" - }, - { - "filename" : "60.png", - "idiom" : "iphone", - "scale" : "3x", - "size" : "20x20" - }, - { - "filename" : "29.png", - "idiom" : "iphone", - "scale" : "1x", - "size" : "29x29" - }, - { - "filename" : "58.png", - "idiom" : "iphone", - "scale" : "2x", - "size" : "29x29" - }, - { - "filename" : "87.png", - "idiom" : "iphone", - "scale" : "3x", - "size" : "29x29" - }, - { - "filename" : "80.png", - "idiom" : "iphone", - "scale" : "2x", - "size" : "40x40" - }, - { - "filename" : "120.png", - "idiom" : "iphone", - "scale" : "3x", - "size" : "40x40" - }, - { - "filename" : "57.png", - "idiom" : "iphone", - "scale" : "1x", - "size" : "57x57" - }, - { - "filename" : "114.png", - "idiom" : "iphone", - "scale" : "2x", - "size" : "57x57" - }, - { - "filename" : "120.png", - "idiom" : "iphone", - "scale" : "2x", - "size" : "60x60" - }, - { - "filename" : "180.png", - "idiom" : "iphone", - "scale" : "3x", - "size" : "60x60" - }, - { - "filename" : "20.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "20x20" - }, - { - "filename" : "40.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "20x20" - }, - { - "filename" : "29.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "29x29" - }, - { - "filename" : "58.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "29x29" - }, - { - "filename" : "40.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "40x40" - }, - { - "filename" : "80.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "40x40" - }, - { - "filename" : "50.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "50x50" - }, - { - "filename" : "100.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "50x50" - }, - { - "filename" : "72.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "72x72" - }, - { - "filename" : "144.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "72x72" - }, - { - "filename" : "76.png", - "idiom" : "ipad", - "scale" : "1x", - "size" : "76x76" - }, - { - "filename" : "152.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "76x76" - }, - { - "filename" : "167.png", - "idiom" : "ipad", - "scale" : "2x", - "size" : "83.5x83.5" - }, - { - "filename" : "1024.png", - "idiom" : "ios-marketing", - "scale" : "1x", - "size" : "1024x1024" - }, - { - "idiom" : "watch", - "role" : "notificationCenter", - "scale" : "2x", - "size" : "24x24", - "subtype" : "38mm" - }, - { - "idiom" : "watch", - "role" : "notificationCenter", - "scale" : "2x", - "size" : "27.5x27.5", - "subtype" : "42mm" - }, - { - "idiom" : "watch", - "role" : "companionSettings", - "scale" : "2x", - "size" : "29x29" - }, - { - "idiom" : "watch", - "role" : "companionSettings", - "scale" : "3x", - "size" : "29x29" - }, - { - "idiom" : "watch", - "role" : "notificationCenter", - "scale" : "2x", - "size" : "33x33", - "subtype" : "45mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "40x40", - "subtype" : "38mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "44x44", - "subtype" : "40mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "46x46", - "subtype" : "41mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "50x50", - "subtype" : "44mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "51x51", - "subtype" : "45mm" - }, - { - "idiom" : "watch", - "role" : "appLauncher", - "scale" : "2x", - "size" : "54x54", - "subtype" : "49mm" - }, - { - "idiom" : "watch", - "role" : "quickLook", - "scale" : "2x", - "size" : "86x86", - "subtype" : "38mm" - }, - { - "idiom" : "watch", - "role" : "quickLook", - "scale" : "2x", - "size" : "98x98", - "subtype" : "42mm" - }, - { - "idiom" : "watch", - "role" : "quickLook", - "scale" : "2x", - "size" : "108x108", - "subtype" : "44mm" - }, - { - "idiom" : "watch", - "role" : "quickLook", - "scale" : "2x", - "size" : "117x117", - "subtype" : "45mm" - }, - { - "idiom" : "watch", - "role" : "quickLook", - "scale" : "2x", - "size" : "129x129", - "subtype" : "49mm" - }, - { - "idiom" : "watch-marketing", - "scale" : "1x", - "size" : "1024x1024" - }, - { - "idiom" : "car", - "scale" : "2x", - "size" : "60" - }, - { - "idiom" : "car", - "scale" : "3x", - "size" : "60" - }, - { - "idiom" : "watch", - "role" : "longLook", - "scale" : "2x", - "size" : "44x44", - "subtype" : "42mm" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/client/macos/app/Media.xcassets/Contents.json b/client/macos/app/Media.xcassets/Contents.json deleted file mode 100644 index 73c00596..00000000 --- a/client/macos/app/Media.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/client/macos/app/PrivacyInfo.xcprivacy b/client/macos/app/PrivacyInfo.xcprivacy deleted file mode 100644 index 24e32f37..00000000 --- a/client/macos/app/PrivacyInfo.xcprivacy +++ /dev/null @@ -1,33 +0,0 @@ - - - - - NSPrivacyAccessedAPITypes - - - NSPrivacyAccessedAPIType - NSPrivacyAccessedAPICategoryFileTimestamp - NSPrivacyAccessedAPITypeReasons - - C617.1 - - - - NSPrivacyAccessedAPIType - NSPrivacyAccessedAPICategoryUserDefaults - NSPrivacyAccessedAPITypeReasons - - 1C8F.1 - - - - NSPrivacyAccessedAPIType - NSPrivacyAccessedAPICategorySystemBootTime - NSPrivacyAccessedAPITypeReasons - - 35F9.1 - - - - - diff --git a/client/macos/app/launch.png b/client/macos/app/launch.png deleted file mode 100644 index 175b1afc..00000000 Binary files a/client/macos/app/launch.png and /dev/null differ diff --git a/client/macos/app/main.entitlements b/client/macos/app/main.entitlements deleted file mode 100644 index d9f00bb1..00000000 --- a/client/macos/app/main.entitlements +++ /dev/null @@ -1,20 +0,0 @@ - - - - - com.apple.developer.networking.networkextension - - packet-tunnel-provider - - com.apple.security.application-groups - - group.org.amnezia.AmneziaVPN - - com.apple.security.files.user-selected.read-write - - keychain-access-groups - - $(AppIdentifierPrefix)group.org.amnezia.AmneziaVPN - - - diff --git a/client/platforms/ios/PacketTunnelProvider+Xray.swift b/client/platforms/ios/PacketTunnelProvider+Xray.swift index ce1270be..648b3613 100644 --- a/client/platforms/ios/PacketTunnelProvider+Xray.swift +++ b/client/platforms/ios/PacketTunnelProvider+Xray.swift @@ -3,185 +3,185 @@ import NetworkExtension import WireGuardKitGo enum XrayErrors: Error { - case noXrayConfig - case xrayConfigIsWrong - case cantSaveXrayConfig - case cantParseListenAndPort - case cantSaveHevSocksConfig + case noXrayConfig + case xrayConfigIsWrong + case cantSaveXrayConfig + case cantParseListenAndPort + case cantSaveHevSocksConfig } extension Constants { - static let cachesDirectory: URL = { - if let cachesDirectoryURL = FileManager.default.urls(for: .cachesDirectory, - in: .userDomainMask).first { - return cachesDirectoryURL - } else { - fatalError("Unable to retrieve caches directory.") - } - }() + static let cachesDirectory: URL = { + if let cachesDirectoryURL = FileManager.default.urls(for: .cachesDirectory, + in: .userDomainMask).first { + return cachesDirectoryURL + } else { + fatalError("Unable to retrieve caches directory.") + } + }() } extension PacketTunnelProvider { - func startXray(completionHandler: @escaping (Error?) -> Void) { + func startXray(completionHandler: @escaping (Error?) -> Void) { - // Xray configuration - guard let protocolConfiguration = self.protocolConfiguration as? NETunnelProviderProtocol, - let providerConfiguration = protocolConfiguration.providerConfiguration, - let configData = providerConfiguration[Constants.xrayConfigKey] as? Data else { - xrayLog(.error, message: "Can't get xray configuration") - completionHandler(XrayErrors.noXrayConfig) - return - } + // Xray configuration + guard let protocolConfiguration = self.protocolConfiguration as? NETunnelProviderProtocol, + let providerConfiguration = protocolConfiguration.providerConfiguration, + let configData = providerConfiguration[Constants.xrayConfigKey] as? Data else { + xrayLog(.error, message: "Can't get xray configuration") + completionHandler(XrayErrors.noXrayConfig) + return + } - // Tunnel settings - let ipv6Enabled = false - let hideVPNIcon = false + // Tunnel settings + let ipv6Enabled = false + let hideVPNIcon = false - let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "254.1.1.1") - settings.mtu = 9000 + let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "254.1.1.1") + settings.mtu = 9000 - settings.ipv4Settings = { - let settings = NEIPv4Settings(addresses: ["198.18.0.1"], subnetMasks: ["255.255.0.0"]) - settings.includedRoutes = [NEIPv4Route.default()] - return settings - }() + settings.ipv4Settings = { + let settings = NEIPv4Settings(addresses: ["198.18.0.1"], subnetMasks: ["255.255.0.0"]) + settings.includedRoutes = [NEIPv4Route.default()] + return settings + }() - settings.ipv6Settings = { - guard ipv6Enabled else { - return nil - } - let settings = NEIPv6Settings(addresses: ["fd6e:a81b:704f:1211::1"], networkPrefixLengths: [64]) - settings.includedRoutes = [NEIPv6Route.default()] - if hideVPNIcon { - settings.excludedRoutes = [NEIPv6Route(destinationAddress: "::", networkPrefixLength: 128)] - } - return settings - }() + settings.ipv6Settings = { + guard ipv6Enabled else { + return nil + } + let settings = NEIPv6Settings(addresses: ["fd6e:a81b:704f:1211::1"], networkPrefixLengths: [64]) + settings.includedRoutes = [NEIPv6Route.default()] + if hideVPNIcon { + settings.excludedRoutes = [NEIPv6Route(destinationAddress: "::", networkPrefixLength: 128)] + } + return settings + }() - do { - let xrayConfig = try JSONDecoder().decode(XrayConfig.self, - from: configData) + do { + let xrayConfig = try JSONDecoder().decode(XrayConfig.self, + from: configData) - var dnsArray = [String]() - if let dns1 = xrayConfig.dns1 { - dnsArray.append(dns1) - } - if let dns2 = xrayConfig.dns2 { - dnsArray.append(dns2) - } + var dnsArray = [String]() + if let dns1 = xrayConfig.dns1 { + dnsArray.append(dns1) + } + if let dns2 = xrayConfig.dns2 { + dnsArray.append(dns2) + } - settings.dnsSettings = !dnsArray.isEmpty - ? NEDNSSettings(servers: dnsArray) - : NEDNSSettings(servers: ["1.1.1.1"]) + settings.dnsSettings = !dnsArray.isEmpty + ? NEDNSSettings(servers: dnsArray) + : NEDNSSettings(servers: ["1.1.1.1"]) - let xrayConfigData = xrayConfig.config.data(using: .utf8) + let xrayConfigData = xrayConfig.config.data(using: .utf8) - guard let xrayConfigData else { - xrayLog(.error, message: "Can't encode config to data") - completionHandler(XrayErrors.xrayConfigIsWrong) - return - } + guard let xrayConfigData else { + xrayLog(.error, message: "Can't encode config to data") + completionHandler(XrayErrors.xrayConfigIsWrong) + return + } - let jsonDict = try JSONSerialization.jsonObject(with: xrayConfigData, - options: []) as? [String: Any] + let jsonDict = try JSONSerialization.jsonObject(with: xrayConfigData, + options: []) as? [String: Any] - guard var jsonDict else { - xrayLog(.error, message: "Can't parse address and port for hevSocks") - completionHandler(XrayErrors.cantParseListenAndPort) - return - } + guard var jsonDict else { + xrayLog(.error, message: "Can't parse address and port for hevSocks") + completionHandler(XrayErrors.cantParseListenAndPort) + return + } - let port = 10808 - let address = "::1" + let port = 10808 + let address = "::1" - if var inboundsArray = jsonDict["inbounds"] as? [[String: Any]], !inboundsArray.isEmpty { - inboundsArray[0]["port"] = port - inboundsArray[0]["listen"] = address - jsonDict["inbounds"] = inboundsArray - } + if var inboundsArray = jsonDict["inbounds"] as? [[String: Any]], !inboundsArray.isEmpty { + inboundsArray[0]["port"] = port + inboundsArray[0]["listen"] = address + jsonDict["inbounds"] = inboundsArray + } - let updatedData = try JSONSerialization.data(withJSONObject: jsonDict, options: []) + let updatedData = try JSONSerialization.data(withJSONObject: jsonDict, options: []) - setTunnelNetworkSettings(settings) { [weak self] error in - if let error { - completionHandler(error) - return - } + setTunnelNetworkSettings(settings) { [weak self] error in + if let error { + completionHandler(error) + return + } - // Launch xray - self?.setupAndStartXray(configData: updatedData) { xrayError in - if let xrayError { - completionHandler(xrayError) - return - } + // Launch xray + self?.setupAndStartXray(configData: updatedData) { xrayError in + if let xrayError { + completionHandler(xrayError) + return + } - // Launch hevSocks - self?.setupAndRunTun2socks(configData: updatedData, - address: address, - port: port, - completionHandler: completionHandler) - } - } - } catch { - completionHandler(error) - return - } - } + // Launch hevSocks + self?.setupAndRunTun2socks(configData: updatedData, + address: address, + port: port, + completionHandler: completionHandler) + } + } + } catch { + completionHandler(error) + return + } + } - func stopXray(completionHandler: () -> Void) { - Socks5Tunnel.quit() - LibXrayStopXray() - completionHandler() - } + func stopXray(completionHandler: () -> Void) { + Socks5Tunnel.quit() + LibXrayStopXray() + completionHandler() + } - private func setupAndStartXray(configData: Data, - completionHandler: @escaping (Error?) -> Void) { - let path = Constants.cachesDirectory.appendingPathComponent("config.json", isDirectory: false).path - guard FileManager.default.createFile(atPath: path, contents: configData) else { - xrayLog(.error, message: "Can't save xray configuration") - completionHandler(XrayErrors.cantSaveXrayConfig) - return - } + private func setupAndStartXray(configData: Data, + completionHandler: @escaping (Error?) -> Void) { + let path = Constants.cachesDirectory.appendingPathComponent("config.json", isDirectory: false).path + guard FileManager.default.createFile(atPath: path, contents: configData) else { + xrayLog(.error, message: "Can't save xray configuration") + completionHandler(XrayErrors.cantSaveXrayConfig) + return + } - LibXrayRunXray(nil, - path, - Int64.max) + LibXrayRunXray(nil, + path, + Int64.max) - completionHandler(nil) - xrayLog(.info, message: "Xray started") - } + completionHandler(nil) + xrayLog(.info, message: "Xray started") + } - private func setupAndRunTun2socks(configData: Data, - address: String, - port: Int, - completionHandler: @escaping (Error?) -> Void) { - let config = """ - tunnel: - mtu: 9000 - socks5: - port: \(port) - address: \(address) - udp: 'udp' - misc: - task-stack-size: 20480 - connect-timeout: 5000 - read-write-timeout: 60000 - log-file: stderr - log-level: error - limit-nofile: 65535 - """ + private func setupAndRunTun2socks(configData: Data, + address: String, + port: Int, + completionHandler: @escaping (Error?) -> Void) { + let config = """ + tunnel: + mtu: 9000 + socks5: + port: \(port) + address: \(address) + udp: 'udp' + misc: + task-stack-size: 20480 + connect-timeout: 5000 + read-write-timeout: 60000 + log-file: stderr + log-level: error + limit-nofile: 65535 + """ - let configurationFilePath = Constants.cachesDirectory.appendingPathComponent("config.yml", isDirectory: false).path - guard FileManager.default.createFile(atPath: configurationFilePath, contents: config.data(using: .utf8)!) else { - xrayLog(.info, message: "Cant save hevSocks configuration") - completionHandler(XrayErrors.cantSaveHevSocksConfig) - return - } + let configurationFilePath = Constants.cachesDirectory.appendingPathComponent("config.yml", isDirectory: false).path + guard FileManager.default.createFile(atPath: configurationFilePath, contents: config.data(using: .utf8)!) else { + xrayLog(.info, message: "Cant save hevSocks configuration") + completionHandler(XrayErrors.cantSaveHevSocksConfig) + return + } - DispatchQueue.global().async { - xrayLog(.info, message: "Hev socks started") - completionHandler(nil) - Socks5Tunnel.run(withConfig: configurationFilePath) - } - } -} \ No newline at end of file + DispatchQueue.global().async { + xrayLog(.info, message: "Hev socks started") + completionHandler(nil) + Socks5Tunnel.run(withConfig: configurationFilePath) + } + } +}