mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
In order to avoid getting disconnected from the server, it is necessary to send an "idle" command once you are connected. This tells the server that the client is going to wait for a status change message from the server. In the meantime if the client needs to send another command, it must first send "noidle", then send the command, then send "idle" once more. If the command results in a status change, the "idle" will return immediately, which must be dealt with and then the "idle" command must be sent once more. Phew!
49 lines
1000 B
Swift
49 lines
1000 B
Swift
//
|
|
// WindowController.swift
|
|
// Persephone
|
|
//
|
|
// Created by Daniel Barber on 2019/1/11.
|
|
// Copyright © 2019 Dan Barber. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class WindowController: NSWindowController {
|
|
enum TransportAction: Int {
|
|
case prevTrack = 0
|
|
case playPause = 1
|
|
case stop = 2
|
|
case nextTrack = 3
|
|
}
|
|
var mpdClient: MPDClient?
|
|
|
|
override func windowDidLoad() {
|
|
super.windowDidLoad()
|
|
window?.titleVisibility = .hidden
|
|
|
|
mpdInit()
|
|
}
|
|
|
|
func mpdInit() {
|
|
mpdClient = MPDClient()
|
|
mpdClient?.idle()
|
|
// let state = mpdClient?.getState()
|
|
}
|
|
|
|
@IBAction func handleTransportControl(_ sender: NSSegmentedControl) {
|
|
guard let transportAction = TransportAction(rawValue: sender.selectedSegment)
|
|
else { return }
|
|
|
|
switch transportAction {
|
|
case .prevTrack:
|
|
mpdClient?.prevTrack()
|
|
case .playPause:
|
|
mpdClient?.playPause()
|
|
case .stop:
|
|
mpdClient?.stop()
|
|
case .nextTrack:
|
|
mpdClient?.nextTrack()
|
|
}
|
|
}
|
|
}
|