mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 07:09:53 +02:00
Implemented missing methods
This commit is contained in:
parent
6de4626239
commit
782f11ff28
3 changed files with 31 additions and 14 deletions
|
@ -11,5 +11,10 @@
|
||||||
CAP_PLUGIN(AbsDatabase, "AbsDatabase",
|
CAP_PLUGIN(AbsDatabase, "AbsDatabase",
|
||||||
CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise);
|
CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise);
|
||||||
CAP_PLUGIN_METHOD(getDeviceData, 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);
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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": [] ])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,32 +10,32 @@ import RealmSwift
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
public static let realmQueue = DispatchQueue(label: "realm-queue")
|
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 {
|
public static func getActiveServerConfigIndex() -> Int {
|
||||||
let realm = try! Realm(queue: realmQueue)
|
guard let config = instance.objects(ServerConnectionConfig.self).first else {
|
||||||
guard let config = realm.objects(ServerConnectionConfig.self).first else {
|
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return config.index
|
return config.index
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
|
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
|
||||||
// TODO: handle thread errors
|
let existing: ServerConnectionConfig? = instance.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
|
||||||
let realm = try! Realm(queue: realmQueue)
|
|
||||||
var existing: ServerConnectionConfig?
|
|
||||||
|
|
||||||
if config.id != nil {
|
try! instance.write {
|
||||||
existing = realm.object(ofType: ServerConnectionConfig.self, forPrimaryKey: config.id)
|
|
||||||
}
|
|
||||||
try! realm.write {
|
|
||||||
if existing != nil {
|
if existing != nil {
|
||||||
realm.delete(existing!)
|
instance.delete(existing!)
|
||||||
}
|
}
|
||||||
realm.add(config)
|
instance.add(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static func getServerConnectionConfigs() -> [ServerConnectionConfig] {
|
public static func getServerConnectionConfigs() -> [ServerConnectionConfig] {
|
||||||
let realm = try! Realm(queue: realmQueue)
|
let configs = instance.objects(ServerConnectionConfig.self)
|
||||||
let configs = realm.objects(ServerConnectionConfig.self)
|
|
||||||
|
|
||||||
if configs.count <= 0 {
|
if configs.count <= 0 {
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue