added removeServerConnectionConfig method

This commit is contained in:
Rasmus Krämer 2022-04-15 13:01:58 +02:00
parent 363bfd206c
commit 03c3f37e1e
No known key found for this signature in database
GPG key ID: EC9E510611BFDAA2
5 changed files with 35 additions and 12 deletions

View file

@ -10,6 +10,8 @@
CAP_PLUGIN(AbsDatabase, "AbsDatabase",
CAP_PLUGIN_METHOD(setCurrentServerConnectionConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(removeServerConnectionConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(logout, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getDeviceData, CAPPluginReturnPromise);

View file

@ -51,6 +51,12 @@ public class AbsDatabase: CAPPlugin {
Store.serverConfig = config
call.resolve(convertServerConnectionConfigToJSON(config: config))
}
@objc func removeServerConnectionConfig(_ call: CAPPluginCall) {
let id = call.getString("serverConnectionConfigId", "")
Database.deleteServerConnectionConfig(id: id)
call.resolve()
}
@objc func logout(_ call: CAPPluginCall) {
Store.serverConfig = nil
call.resolve()

View file

@ -57,7 +57,6 @@ class AudioPlayer: NSObject {
playerItem.addObserver(self, forKeyPath: #keyPath(AVPlayerItem.status), options: .new, context: &playerItemContext)
self.audioPlayer.replaceCurrentItem(with: playerItem)
seek(playbackSession.currentTime)
NSLog("Audioplayer ready")
}
@ -259,6 +258,8 @@ class AudioPlayer: NSObject {
self.playWhenReady = false
self.play()
}
seek(playbackSession.currentTime)
}
}
} else if context == &playerContext {

View file

@ -12,7 +12,7 @@ class PlayerHandler {
private static var session: PlaybackSession?
private static var timer: Timer?
private static var listningTimePassedSinceLastSync = 0.0
private static var listeningTimePassedSinceLastSync = 0.0
public static func startPlayback(session: PlaybackSession, playWhenReady: Bool) {
if player != nil {
@ -101,10 +101,10 @@ class PlayerHandler {
private static func tick() {
if !paused() {
listningTimePassedSinceLastSync += 1
listeningTimePassedSinceLastSync += 1
}
if listningTimePassedSinceLastSync > 3 {
if listeningTimePassedSinceLastSync > 3 {
syncProgress()
}
}
@ -113,10 +113,10 @@ class PlayerHandler {
return
}
let report = PlaybackReport(currentTime: player!.getCurrentTime(), duration: player!.getDuration(), timeListened: listningTimePassedSinceLastSync)
let report = PlaybackReport(currentTime: player!.getCurrentTime(), duration: player!.getDuration(), timeListened: listeningTimePassedSinceLastSync)
session!.currentTime = player!.getCurrentTime()
listningTimePassedSinceLastSync = 0
listeningTimePassedSinceLastSync = 0
// TODO: check if online
NSLog("sending playback report")

View file

@ -11,9 +11,7 @@ import RealmSwift
class Database {
// All DB releated actions must be executed on "realm-queue"
public static let realmQueue = DispatchQueue(label: "realm-queue")
private static var instance: Realm = {
try! Realm(queue: realmQueue)
}()
private static var instance: Realm = try! Realm(queue: realmQueue)
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
var refrence: ThreadSafeReference<ServerConnectionConfig>?
@ -57,6 +55,22 @@ class Database {
setLastActiveConfigIndex(index: config.index)
}
}
public static func deleteServerConnectionConfig(id: String) {
realmQueue.sync {
let config = instance.object(ofType: ServerConnectionConfig.self, forPrimaryKey: id)
do {
try instance.write {
if config != nil {
instance.delete(config!)
}
}
} catch(let exception) {
NSLog("failed to delete server config")
debugPrint(exception)
}
}
}
public static func getServerConnectionConfigs() -> [ServerConnectionConfig] {
var refrences: [ThreadSafeReference<ServerConnectionConfig>] = []