-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cmdline flags and some fixes to the IPC layer
- Loading branch information
Showing
8 changed files
with
185 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package backend | ||
|
||
import ( | ||
"flag" | ||
"strconv" | ||
) | ||
|
||
var ( | ||
VolumeCLIArg int = -1 | ||
SeekToCLIArg float64 = -1 | ||
|
||
FlagPlay = flag.Bool("play", false, "unpause or begin playback") | ||
FlagPause = flag.Bool("pause", false, "pause playback") | ||
FlagPlayPause = flag.Bool("play-pause", false, "toggle play/pause state") | ||
FlagPrevious = flag.Bool("previous", false, "seek to previous track or beginning of current") | ||
FlagNext = flag.Bool("next", false, "seek to next track") | ||
FlagVersion = flag.Bool("version", false, "print app version and exit") | ||
FlagHelp = flag.Bool("help", false, "print command line options and exit") | ||
) | ||
|
||
func init() { | ||
flag.Func("volume", "sets the playback volume (0-100)", func(s string) error { | ||
v, err := strconv.Atoi(s) | ||
VolumeCLIArg = v | ||
return err | ||
}) | ||
|
||
flag.Func("seek-to", "seeks to the given position in seconds in the current file (0.0 - <trackDur>)", func(s string) error { | ||
v, err := strconv.ParseFloat(s, 64) | ||
SeekToCLIArg = v | ||
return err | ||
}) | ||
} | ||
|
||
func HaveCommandLineOptions() bool { | ||
visitedAny := false | ||
flag.Visit(func(*flag.Flag) { | ||
visitedAny = true | ||
}) | ||
return visitedAny | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,29 @@ | ||
package ipc | ||
|
||
const ( | ||
// GET | ||
PingPath = "/ping" | ||
import "fmt" | ||
|
||
// POST | ||
PlayPath = "/transport/play" | ||
// POST | ||
const ( | ||
PingPath = "/ping" | ||
PlayPath = "/transport/play" | ||
PlayPausePath = "/transport/playpause" | ||
// POST | ||
PausePath = "/transport/pause" | ||
// POST | ||
StopPath = "/transport/stop" | ||
// POST | ||
PreviousPath = "/transport/previous" | ||
// POST | ||
NextPath = "/transport/next" | ||
// POST(TimePos) | ||
TimePosPath = "/transport/timepos" | ||
// POST to seek | ||
PlayTrackPath = "/queue/playtrack" | ||
// GET -> Volume | ||
// POST(Volume) | ||
VolumePath = "/volume" | ||
|
||
// POST | ||
ShowPath = "/window/show" | ||
// POST | ||
QuitPath = "/window/quit" | ||
PausePath = "/transport/pause" | ||
StopPath = "/transport/stop" | ||
PreviousPath = "/transport/previous" | ||
NextPath = "/transport/next" | ||
TimePosPath = "/transport/timepos" // ?s=<seconds> | ||
VolumePath = "/volume" // ?v=<vol> | ||
ShowPath = "/window/show" | ||
QuitPath = "/window/quit" | ||
) | ||
|
||
type TimePos struct { | ||
Seconds float64 `json:"seconds"` | ||
type Response struct { | ||
Error string `json:"error"` | ||
} | ||
|
||
type Volume struct { | ||
Volume int `json:"volume"` | ||
func SetVolumePath(vol int) string { | ||
return fmt.Sprintf("%s?v=%d", VolumePath, vol) | ||
} | ||
|
||
type Response struct { | ||
Error string `json:"error"` | ||
func SeekToSecondsPath(secs float64) string { | ||
return fmt.Sprintf("%s?s=%0.2f", TimePosPath, secs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.