advplyr.audiobookshelf-app/ios/App/Shared/util/Store.swift

33 lines
878 B
Swift
Raw Normal View History

2022-04-11 16:29:19 +02:00
//
// Store.swift
// App
//
// Created by Rasmus Krämer on 11.04.22.
//
import Foundation
import RealmSwift
class Store {
2022-04-15 10:16:11 +02:00
public static var serverConfig: ServerConnectionConfig? {
2022-04-11 16:29:19 +02:00
get {
do {
// Fetch each time, as holding onto a live or frozen realm object is bad
let index = Database.shared.getLastActiveConfigIndex()
let realm = try Realm()
return realm.objects(ServerConnectionConfig.self).first(where: { $0.index == index })
} catch {
debugPrint(error)
return nil
}
2022-04-11 16:29:19 +02:00
}
set(updated) {
2022-04-15 10:16:11 +02:00
if updated != nil {
2022-05-03 12:55:13 +02:00
Database.shared.setServerConnectionConfig(config: updated!)
2022-04-15 10:16:11 +02:00
} else {
2022-05-03 12:55:13 +02:00
Database.shared.setLastActiveConfigIndexToNil()
2022-04-15 10:16:11 +02:00
}
2022-04-11 16:29:19 +02:00
}
}
}