mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +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_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);
|
||||
)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
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 []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue