mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-09-12 21:01:50 +02:00
Improved realm thread and added http client
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// AbsAudioPlayer.m
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 13.04.22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Capacitor/Capacitor.h>
|
||||
|
||||
CAP_PLUGIN(AbsAudioPlayer, "AbsAudioPlayer",
|
||||
CAP_PLUGIN_METHOD(prepareLibraryItem, CAPPluginReturnPromise);
|
||||
)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// AbsAudioPlayer.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 13.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Capacitor
|
||||
|
||||
@objc(AbsAudioPlayer)
|
||||
public class AbsAudioPlayer: CAPPlugin {
|
||||
@objc func prepareLibraryItem(_ call: CAPPluginCall) {
|
||||
let libraryItemId = call.getString("libraryItemId")
|
||||
let episodeId = call.getString("episodeId")
|
||||
let playWhenReady = call.getBool("playWhenReady", true)
|
||||
|
||||
if libraryItemId == nil {
|
||||
NSLog("provide library item id")
|
||||
return call.resolve()
|
||||
}
|
||||
if libraryItemId!.starts(with: "local") {
|
||||
NSLog("local items are not implemnted")
|
||||
return call.resolve()
|
||||
}
|
||||
|
||||
ApiClient.startPlaybackSession(libraryItemId: libraryItemId!, episodeId: episodeId) { session in
|
||||
NSLog(OperationQueue.current)
|
||||
PlayerHandler.startPlayback(session: session, playWhenReady: playWhenReady)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,47 +28,43 @@ extension String {
|
||||
@objc(AbsDatabase)
|
||||
public class AbsDatabase: CAPPlugin {
|
||||
@objc func setCurrentServerConnectionConfig(_ call: CAPPluginCall) {
|
||||
Database.realmQueue.sync {
|
||||
var id = call.getString("id")
|
||||
let address = call.getString("address", "")
|
||||
let userId = call.getString("userId", "")
|
||||
let username = call.getString("username", "")
|
||||
let token = call.getString("token", "")
|
||||
|
||||
let name = "\(address) (\(username))"
|
||||
let config = ServerConnectionConfig()
|
||||
|
||||
if id == nil {
|
||||
id = "\(address)@\(username)".toBase64()
|
||||
}
|
||||
|
||||
config.id = id!
|
||||
config.name = name
|
||||
config.address = address
|
||||
config.userId = userId
|
||||
config.username = username
|
||||
config.token = token
|
||||
|
||||
Store.serverConfig = config
|
||||
call.resolve(convertServerConnectionConfigToJSON(config: config))
|
||||
var id = call.getString("id")
|
||||
let address = call.getString("address", "")
|
||||
let userId = call.getString("userId", "")
|
||||
let username = call.getString("username", "")
|
||||
let token = call.getString("token", "")
|
||||
|
||||
let name = "\(address) (\(username))"
|
||||
let config = ServerConnectionConfig()
|
||||
|
||||
if id == nil {
|
||||
id = "\(address)@\(username)".toBase64()
|
||||
}
|
||||
|
||||
config.id = id!
|
||||
config.name = name
|
||||
config.address = address
|
||||
config.userId = userId
|
||||
config.username = username
|
||||
config.token = token
|
||||
|
||||
Store.serverConfig = config
|
||||
call.resolve(convertServerConnectionConfigToJSON(config: config))
|
||||
}
|
||||
@objc func getDeviceData(_ call: CAPPluginCall) {
|
||||
Database.realmQueue.sync {
|
||||
let configs = Database.getServerConnectionConfigs()
|
||||
let index = Database.getActiveServerConfigIndex()
|
||||
|
||||
call.resolve([
|
||||
"serverConnectionConfigs": configs.map { config in
|
||||
return convertServerConnectionConfigToJSON(config: config)
|
||||
},
|
||||
"lastServerConnectionConfigId": index < 0 ? -1 : configs.first(where: {
|
||||
(config: ServerConnectionConfig) -> Bool in
|
||||
return config.index == index
|
||||
})!.id,
|
||||
"currentLocalPlaybackSession": nil, // Luckily this isn't implemented yet
|
||||
])
|
||||
}
|
||||
let configs = Database.getServerConnectionConfigs()
|
||||
let index = Database.getActiveServerConfigIndex()
|
||||
|
||||
call.resolve([
|
||||
"serverConnectionConfigs": configs.map { config in
|
||||
return convertServerConnectionConfigToJSON(config: config)
|
||||
},
|
||||
"lastServerConnectionConfigId": index < 0 ? -1 : configs.first(where: {
|
||||
(config: ServerConnectionConfig) -> Bool in
|
||||
return config.index == index
|
||||
})!.id,
|
||||
"currentLocalPlaybackSession": nil, // Luckily this isn't implemented yet
|
||||
])
|
||||
}
|
||||
|
||||
// We have to send a empty array or the client will break
|
||||
|
||||
Reference in New Issue
Block a user