Fix tvOS profile import

This commit is contained in:
世界
2025-11-26 22:25:49 +08:00
parent 2491cd87dd
commit ec0ed8344e
4 changed files with 41 additions and 9 deletions
@@ -1,6 +1,10 @@
import Foundation
import Libbox
import Library
import Network
#if canImport(UIKit)
import UIKit
#endif
public class ProfileServer {
private var listener: NWListener
@@ -32,12 +36,21 @@ public class ProfileServer {
class ProfileConnection {
private let connection: NWSocket
#if os(iOS)
private var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
#endif
init(_ connection: NWConnection) {
self.connection = NWSocket(connection)
}
func process() async {
#if os(iOS)
beginBackgroundTask()
defer {
endBackgroundTask()
}
#endif
do {
try await writeProfilePreviewList()
} catch {
@@ -56,6 +69,26 @@ public class ProfileServer {
}
}
#if os(iOS)
private func beginBackgroundTask() {
backgroundTaskID = UIApplication.shared.beginBackgroundTask { [weak self] in
NSLog("profile server: background task expiring, cleaning up connection")
self?.connection.cancel()
self?.endBackgroundTask()
}
if backgroundTaskID != .invalid {
NSLog("profile server: background task started")
}
}
private func endBackgroundTask() {
guard backgroundTaskID != .invalid else { return }
NSLog("profile server: background task ended")
UIApplication.shared.endBackgroundTask(backgroundTaskID)
backgroundTaskID = .invalid
}
#endif
private func processMessage(_ data: Data) throws {
if data.count == 0 {
return
+6 -9
View File
@@ -23,6 +23,11 @@
</array>
</dict>
</array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>zh_CN</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
@@ -38,8 +43,6 @@
</array>
</dict>
</array>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>NSApplicationServices</key>
<dict>
<key>Advertises</key>
@@ -65,6 +68,7 @@
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
@@ -116,12 +120,5 @@
</dict>
</dict>
</array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>zh_CN</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
</dict>
</plist>
+2
View File
@@ -1960,6 +1960,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
@@ -2001,6 +2002,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;