From 17eec0861543489ad4519eef974c65d2a159244d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 3 May 2024 17:15:01 +0800 Subject: [PATCH] Fix `Read iCloud profile before starting` --- .../Service/UIProfileUpdateTask.swift | 2 +- .../Views/Dashboard/StartStopButton.swift | 1 - .../Views/Setting/ServiceLogView.swift | 2 +- Library/Network/ExtensionProfile.swift | 11 +++++++++ sing-box.xcodeproj/project.pbxproj | 24 +++++++++---------- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/ApplicationLibrary/Service/UIProfileUpdateTask.swift b/ApplicationLibrary/Service/UIProfileUpdateTask.swift index 239aedf..ea2269d 100644 --- a/ApplicationLibrary/Service/UIProfileUpdateTask.swift +++ b/ApplicationLibrary/Service/UIProfileUpdateTask.swift @@ -54,7 +54,7 @@ import Library if profiles.isEmpty { return } - await ProfileUpdateTask.updateProfiles(profiles) + _ = await ProfileUpdateTask.updateProfiles(profiles) } private nonisolated static func getAndUpdateProfiles(_ task: BGTask) async { diff --git a/ApplicationLibrary/Views/Dashboard/StartStopButton.swift b/ApplicationLibrary/Views/Dashboard/StartStopButton.swift index c3cc5d1..dd781b9 100644 --- a/ApplicationLibrary/Views/Dashboard/StartStopButton.swift +++ b/ApplicationLibrary/Views/Dashboard/StartStopButton.swift @@ -77,7 +77,6 @@ public struct StartStopButton: View { private nonisolated func switchProfile(_ isEnabled: Bool) async { do { if isEnabled { - try await profile.read() try await profile.start() await environments.logClient.connect() } else { diff --git a/ApplicationLibrary/Views/Setting/ServiceLogView.swift b/ApplicationLibrary/Views/Setting/ServiceLogView.swift index 7215c07..9df8639 100644 --- a/ApplicationLibrary/Views/Setting/ServiceLogView.swift +++ b/ApplicationLibrary/Views/Setting/ServiceLogView.swift @@ -87,7 +87,7 @@ public struct ServiceLogView: View { guard let value = element.value as? Int8, value != 0 else { return identifier } return identifier + String(UnicodeScalar(UInt8(value))) } - var deviceInfo = await "Machine: " + machineName + "\n" + var deviceInfo = "Machine: " + machineName + "\n" #if os(iOS) await deviceInfo += "System: " + (UIDevice.current.systemName) + " " + (UIDevice.current.systemVersion) + "\n" #elseif os(macOS) diff --git a/Library/Network/ExtensionProfile.swift b/Library/Network/ExtensionProfile.swift index e0f82f3..c738111 100644 --- a/Library/Network/ExtensionProfile.swift +++ b/Library/Network/ExtensionProfile.swift @@ -50,6 +50,7 @@ public class ExtensionProfile: ObservableObject { } public func start() async throws { + await fetchProfile() manager.isEnabled = true if await SharedPreferences.alwaysOn.get() { manager.isOnDemandEnabled = true @@ -76,6 +77,16 @@ public class ExtensionProfile: ObservableObject { try manager.connection.startVPNTunnel() } + public func fetchProfile() async { + do { + if let profile = try await ProfileManager.get(Int64(SharedPreferences.selectedProfileID.get())) { + if profile.type == .icloud { + _ = try profile.read() + } + } + } catch {} + } + public func stop() async throws { if manager.isOnDemandEnabled { manager.isOnDemandEnabled = false diff --git a/sing-box.xcodeproj/project.pbxproj b/sing-box.xcodeproj/project.pbxproj index b6c07e3..f23a33a 100644 --- a/sing-box.xcodeproj/project.pbxproj +++ b/sing-box.xcodeproj/project.pbxproj @@ -2010,7 +2010,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; SDKROOT = appletvos; @@ -2044,7 +2044,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; SDKROOT = appletvos; @@ -2282,7 +2282,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; OTHER_CODE_SIGN_FLAGS = "--deep"; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; @@ -2322,7 +2322,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; OTHER_CODE_SIGN_FLAGS = "--deep"; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; @@ -2345,7 +2345,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 213; + CURRENT_PROJECT_VERSION = 221; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = Z56Z6NYZN2; ENABLE_HARDENED_RUNTIME = YES; @@ -2361,7 +2361,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; OTHER_CODE_SIGN_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; @@ -2383,7 +2383,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 213; + CURRENT_PROJECT_VERSION = 221; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = Z56Z6NYZN2; ENABLE_HARDENED_RUNTIME = YES; @@ -2399,7 +2399,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; OTHER_CODE_SIGN_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa; PRODUCT_NAME = "sing-box"; @@ -2541,7 +2541,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system; PRODUCT_NAME = "$(inherited)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2577,7 +2577,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.system; PRODUCT_NAME = "$(inherited)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2617,7 +2617,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent; PRODUCT_NAME = SFM; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2656,7 +2656,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 1.8.11; + MARKETING_VERSION = 1.8.13; PRODUCT_BUNDLE_IDENTIFIER = io.nekohasekai.sfa.independent; PRODUCT_NAME = SFM; PROVISIONING_PROFILE_SPECIFIER = "";