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 Foundation
import Libbox import Libbox
import Library
import Network import Network
#if canImport(UIKit)
import UIKit
#endif
public class ProfileServer { public class ProfileServer {
private var listener: NWListener private var listener: NWListener
@@ -32,12 +36,21 @@ public class ProfileServer {
class ProfileConnection { class ProfileConnection {
private let connection: NWSocket private let connection: NWSocket
#if os(iOS)
private var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
#endif
init(_ connection: NWConnection) { init(_ connection: NWConnection) {
self.connection = NWSocket(connection) self.connection = NWSocket(connection)
} }
func process() async { func process() async {
#if os(iOS)
beginBackgroundTask()
defer {
endBackgroundTask()
}
#endif
do { do {
try await writeProfilePreviewList() try await writeProfilePreviewList()
} catch { } 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 { private func processMessage(_ data: Data) throws {
if data.count == 0 { if data.count == 0 {
return return
+6 -9
View File
@@ -23,6 +23,11 @@
</array> </array>
</dict> </dict>
</array> </array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>zh_CN</string>
</array>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
<array> <array>
<dict> <dict>
@@ -38,8 +43,6 @@
</array> </array>
</dict> </dict>
</array> </array>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>NSApplicationServices</key> <key>NSApplicationServices</key>
<dict> <dict>
<key>Advertises</key> <key>Advertises</key>
@@ -65,6 +68,7 @@
<key>UIBackgroundModes</key> <key>UIBackgroundModes</key>
<array> <array>
<string>fetch</string> <string>fetch</string>
<string>processing</string>
</array> </array>
<key>UTExportedTypeDeclarations</key> <key>UTExportedTypeDeclarations</key>
<array> <array>
@@ -116,12 +120,5 @@
</dict> </dict>
</dict> </dict>
</array> </array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>zh_CN</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
</dict> </dict>
</plist> </plist>
+2
View File
@@ -1960,6 +1960,7 @@
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist; INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box"; INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
@@ -2001,6 +2002,7 @@
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SFI/Info.plist; INFOPLIST_FILE = SFI/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "sing-box"; INFOPLIST_KEY_CFBundleDisplayName = "sing-box";
INFOPLIST_KEY_ITSAppUsesNonExemptEncryption = NO;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;