mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
Move the handle idle command into the command queue
My theory is that it's ok to send the `noidle` synchronously but the subsequent handling of the idle response should be on the command queue. My hope is that this fixes issues with less than perfect network connections (and also very occasionally seen on good networks).
This commit is contained in:
parent
fdec6664d7
commit
ff88aa8f5e
@ -158,7 +158,7 @@ extension MPDClient {
|
||||
|
||||
let commandOperation = BlockOperation() { [unowned self] in
|
||||
self.sendCommand(command: command, userData: userData)
|
||||
|
||||
|
||||
if self.checkError() {
|
||||
self.idle(forceIdle)
|
||||
}
|
||||
|
||||
@ -12,50 +12,37 @@ import mpdclient
|
||||
extension MPDClient {
|
||||
func noIdle() {
|
||||
guard isConnected else { return }
|
||||
|
||||
do {
|
||||
idleLock.lock()
|
||||
defer { idleLock.unlock() }
|
||||
if isIdle {
|
||||
mpd_send_noidle(connection)
|
||||
isIdle = false
|
||||
}
|
||||
|
||||
if isIdle {
|
||||
mpd_send_noidle(connection)
|
||||
}
|
||||
}
|
||||
|
||||
func idle(_ force: Bool = false) {
|
||||
guard isConnected else { return }
|
||||
|
||||
let shouldIdle: Bool
|
||||
|
||||
do {
|
||||
idleLock.lock()
|
||||
defer { idleLock.unlock() }
|
||||
shouldIdle = (!isIdle && commandQueue.operationCount == 1) || force
|
||||
if shouldIdle {
|
||||
mpd_send_idle(connection)
|
||||
self.isIdle = true
|
||||
}
|
||||
}
|
||||
|
||||
let shouldIdle: Bool = (!isIdle && commandQueue.operationCount == 1) || force
|
||||
|
||||
if shouldIdle {
|
||||
let result = mpd_recv_idle(connection, true)
|
||||
handleIdleResult(result)
|
||||
self.isIdle = true
|
||||
mpd_send_idle(connection)
|
||||
|
||||
let handleIdleOperation = BlockOperation() { [unowned self] in
|
||||
self.handleIdleResult()
|
||||
}
|
||||
|
||||
handleIdleOperation.queuePriority = .high
|
||||
commandQueue.addOperation(handleIdleOperation)
|
||||
}
|
||||
}
|
||||
|
||||
func handleIdleResult(_ result: mpd_idle) {
|
||||
func handleIdleResult() {
|
||||
let result = mpd_recv_idle(connection, true)
|
||||
let mpdIdle = MPDIdle(rawValue: result.rawValue)
|
||||
let wasIdle: Bool
|
||||
|
||||
isIdle = false
|
||||
|
||||
do {
|
||||
idleLock.lock()
|
||||
defer { idleLock.unlock() }
|
||||
wasIdle = isIdle
|
||||
isIdle = false
|
||||
}
|
||||
|
||||
if checkError() && wasIdle {
|
||||
if checkError() {
|
||||
if mpdIdle.contains(.database) {
|
||||
self.fetchAllAlbums()
|
||||
}
|
||||
|
||||
@ -21,8 +21,6 @@ class MPDClient {
|
||||
var queue: [MPDSong] = []
|
||||
|
||||
let commandQueue = OperationQueue()
|
||||
|
||||
let idleLock = NSLock()
|
||||
|
||||
init(withDelegate delegate: MPDClientDelegate?) {
|
||||
commandQueue.maxConcurrentOperationCount = 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user