mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 07:07:22 +02:00
Improved realm thread and added http client
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user