Improved realm thread and added http client

This commit is contained in:
Rasmus Krämer
2022-04-14 11:54:53 +02:00
parent 4abd1c8b49
commit 736af85855
14 changed files with 253 additions and 71 deletions
+34 -38
View File
@@ -28,47 +28,43 @@ extension String {
@objc(AbsDatabase)
public class AbsDatabase: CAPPlugin {
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
Database.realmQueue.sync {
var id = call.getString("id")
let address = call.getString("address", "")
let userId = call.getString("userId", "")
let username = call.getString("username", "")
let token = call.getString("token", "")
let name = "\(address) (\(username))"
let config = ServerConnectionConfig()
if id == nil {
id = "\(address)@\(username)".toBase64()
}
config.id = id!
config.name = name
config.address = address
config.userId = userId
config.username = username
config.token = token
Store.serverConfig = config
call.resolve(convertServerConnectionConfigToJSON(config: config))
var id = call.getString("id")
let address = call.getString("address", "")
let userId = call.getString("userId", "")
let username = call.getString("username", "")
let token = call.getString("token", "")
let name = "\(address) (\(username))"
let config = ServerConnectionConfig()
if id == nil {
id = "\(address)@\(username)".toBase64()
}
config.id = id!
config.name = name
config.address = address
config.userId = userId
config.username = username
config.token = token
Store.serverConfig = config
call.resolve(convertServerConnectionConfigToJSON(config: config))
}
@objc func getDeviceData(_ call: CAPPluginCall) {
Database.realmQueue.sync {
let configs = Database.getServerConnectionConfigs()
let index = Database.getActiveServerConfigIndex()
call.resolve([
"serverConnectionConfigs": configs.map { config in
return convertServerConnectionConfigToJSON(config: config)
},
"lastServerConnectionConfigId": index < 0 ? -1 : configs.first(where: {
(config: ServerConnectionConfig) -> Bool in
return config.index == index
})!.id,
"currentLocalPlaybackSession": nil, // Luckily this isn't implemented yet
])
}
let configs = Database.getServerConnectionConfigs()
let index = Database.getActiveServerConfigIndex()
call.resolve([
"serverConnectionConfigs": configs.map { config in
return convertServerConnectionConfigToJSON(config: config)
},
"lastServerConnectionConfigId": index < 0 ? -1 : configs.first(where: {
(config: ServerConnectionConfig) -> Bool in
return config.index == index
})!.id,
"currentLocalPlaybackSession": nil, // Luckily this isn't implemented yet
])
}
// We have to send a empty array or the client will break