Implemented missing methods

This commit is contained in:
Rasmus Krämer 2022-04-11 18:50:25 +02:00
parent 6de4626239
commit 782f11ff28
No known key found for this signature in database
GPG key ID: EC9E510611BFDAA2
3 changed files with 31 additions and 14 deletions

View file

@ -11,5 +11,10 @@
CAP_PLUGIN(AbsDatabase, "AbsDatabase",
CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getDeviceData, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocalLibraryItems, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocalLibraryItem, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocalLibraryItemByLLId, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getLocalLibraryItemsInFolder, CAPPluginReturnPromise);
)

View file

@ -68,5 +68,17 @@ public class AbsDatabase: CAPPlugin {
}
}
// We have to send a empty array or the client will break
@objc func getLocalLibraryItems(_ call: CAPPluginCall) {
call.resolve([ "value": [] ])
}
@objc func getLocalLibraryItem(_ call: CAPPluginCall) {
call.resolve([ "value": [] ])
}
@objc func getLocalLibraryItemByLLId(_ call: CAPPluginCall) {
call.resolve([ "value": [] ])
}
@objc func getLocalLibraryItemsInFolder(_ call: CAPPluginCall) {
call.resolve([ "value": [] ])
}
}

View file

@ -10,32 +10,32 @@ import RealmSwift
class Database {
public static let realmQueue = DispatchQueue(label: "realm-queue")
// All DB releated actions must be executed on "realm-queue"
private static var instance: Realm = {
// TODO: handle thread errors
try! Realm(queue: realmQueue)
}()
public static func getActiveServerConfigIndex() -> Int {
let realm = try! Realm(queue: realmQueue)
guard let config = realm.objects(ServerConnectionConfig.self).first else {
guard let config = instance.objects(ServerConnectionConfig.self).first else {
return -1
}
return config.index
}
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
// TODO: handle thread errors
let realm = try! Realm(queue: realmQueue)
var existing: ServerConnectionConfig?
let existing: ServerConnectionConfig? = instance.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
if config.id != nil {
existing = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
}
try! realm.write {
try! instance.write {
if existing != nil {
realm.delete(existing!)
instance.delete(existing!)
}
realm.add(config)
instance.add(config)
}
}
public static func getServerConnectionConfigs() -> [ServerConnectionConfig] {
let realm = try! Realm(queue: realmQueue)
let configs = realm.objects(ServerConnectionConfig.self)
let configs = instance.objects(ServerConnectionConfig.self)
if configs.count <= 0 {
return []