Fix libbox connection

This commit is contained in:
世界
2025-11-26 22:25:48 +08:00
parent f5a02d9da0
commit ac620cfd3a
3 changed files with 28 additions and 10 deletions
+17
View File
@@ -11,6 +11,23 @@ class ApplicationDelegate: NSObject, UIApplicationDelegate {
options.basePath = FilePath.sharedDirectory.relativePath
options.workingPath = FilePath.workingDirectory.relativePath
options.tempPath = FilePath.cacheDirectory.relativePath
var port = SharedPreferences.commandServerPort.getBlocking()
var secret = SharedPreferences.commandServerSecret.getBlocking()
if port == 0 || secret.isEmpty {
var error: NSError?
LibboxAvailablePort(7990, &port, &error)
if let error {
port = 7990
NSLog("Failed to get available port for control server: \(error.localizedDescription)")
}
secret = LibboxRandomHex(16)!.value
Task {
await SharedPreferences.commandServerPort.set(port)
await SharedPreferences.commandServerSecret.set(secret)
}
}
options.commandServerListenPort = port
options.commandServerSecret = secret
var error: NSError?
LibboxSetup(options, &error)
LibboxSetLocale(Locale.current.identifier)