mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-16 17:04:54 +02:00
Fix persisting active config
This commit is contained in:
parent
f6c43e479d
commit
a7424cc428
3 changed files with 12 additions and 13 deletions
|
@ -40,7 +40,7 @@ public class AbsDatabase: CAPPlugin {
|
||||||
id = "\(address)@\(username)".toBase64()
|
id = "\(address)@\(username)".toBase64()
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = ServerConnectionConfig(id: id!, index: 0, name: name, address: address, userId: userId, username: username, token: token)
|
let config = ServerConnectionConfig(id: id!, index: 1, name: name, address: address, userId: userId, username: username, token: token)
|
||||||
|
|
||||||
Store.serverConfig = config
|
Store.serverConfig = config
|
||||||
call.resolve(convertServerConnectionConfigToJSON(config: config))
|
call.resolve(convertServerConnectionConfigToJSON(config: config))
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Unrealm
|
||||||
|
|
||||||
struct ServerConnectionConfig: Realmable {
|
struct ServerConnectionConfig: Realmable {
|
||||||
var id: String = UUID().uuidString
|
var id: String = UUID().uuidString
|
||||||
var index: Int = 0
|
var index: Int = 1
|
||||||
var name: String = ""
|
var name: String = ""
|
||||||
var address: String = ""
|
var address: String = ""
|
||||||
var userId: String = ""
|
var userId: String = ""
|
||||||
|
@ -30,6 +30,10 @@ struct ServerConnectionConfig: Realmable {
|
||||||
struct ServerConnectionConfigActiveIndex: Realmable {
|
struct ServerConnectionConfigActiveIndex: Realmable {
|
||||||
// This could overflow, but you really would have to try
|
// This could overflow, but you really would have to try
|
||||||
var index: Int?
|
var index: Int?
|
||||||
|
|
||||||
|
static func primaryKey() -> String? {
|
||||||
|
return "index"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertServerConnectionConfigToJSON(config: ServerConnectionConfig) -> Dictionary<String, Any> {
|
func convertServerConnectionConfigToJSON(config: ServerConnectionConfig) -> Dictionary<String, Any> {
|
||||||
|
|
|
@ -76,21 +76,16 @@ class Database {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setLastActiveConfigIndexToNil() {
|
private func setLastActiveConfigIndexToNil() {
|
||||||
Database.realmQueue.sync {
|
|
||||||
setLastActiveConfigIndex(index: nil)
|
setLastActiveConfigIndex(index: nil)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func setLastActiveConfigIndex(index: Int?) {
|
|
||||||
let existing = instance.objects(ServerConnectionConfigActiveIndex.self)
|
|
||||||
var obj = ServerConnectionConfigActiveIndex()
|
|
||||||
obj.index = index
|
|
||||||
|
|
||||||
|
private func setLastActiveConfigIndex(index: Int?) {
|
||||||
do {
|
do {
|
||||||
try instance.write {
|
try instance.write {
|
||||||
instance.delete(existing)
|
var existing = instance.objects(ServerConnectionConfigActiveIndex.self).last ?? ServerConnectionConfigActiveIndex(index: index)
|
||||||
instance.add(obj)
|
existing.index = index
|
||||||
|
instance.add(existing, update: .modified)
|
||||||
}
|
}
|
||||||
} catch(let exception) {
|
} catch(let exception) {
|
||||||
NSLog("failed to save server config active index")
|
NSLog("failed to save server config active index")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue