2022-04-11 14:29:19 +00:00
|
|
|
//
|
|
|
|
|
// Store.swift
|
|
|
|
|
// App
|
|
|
|
|
//
|
|
|
|
|
// Created by Rasmus Krämer on 11.04.22.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import RealmSwift
|
|
|
|
|
|
|
|
|
|
class Store {
|
2022-04-15 08:16:11 +00:00
|
|
|
public static var serverConfig: ServerConnectionConfig? {
|
2022-04-11 14:29:19 +00:00
|
|
|
get {
|
2022-08-25 20:55:35 +00:00
|
|
|
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 14:29:19 +00:00
|
|
|
}
|
|
|
|
|
set(updated) {
|
2022-04-15 08:16:11 +00:00
|
|
|
if updated != nil {
|
2022-05-03 10:55:13 +00:00
|
|
|
Database.shared.setServerConnectionConfig(config: updated!)
|
2022-04-15 08:16:11 +00:00
|
|
|
} else {
|
2022-05-03 10:55:13 +00:00
|
|
|
Database.shared.setLastActiveConfigIndexToNil()
|
2022-04-15 08:16:11 +00:00
|
|
|
}
|
2022-04-11 14:29:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|