Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
undg committed Feb 10, 2025
1 parent f97871b commit 55ad586
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var AvailableCommands = []Action{
// Message is an request from the client
type Message struct {
// Actions listed in availableCommands slice
Action Action `json:"action" doc:"Action to perform fe. GetVolume, SetVolume, SetMute..."enum:"GetStatus,GetBuildInfo,SetSinkVolume,SetSinkMuted,SetSinkInputVolume,SetSinkInputMuted,MoveSinkInput,SetSourceVolume,SetSourceMuted,SetSourceInputVolume,SetSourceInputMuted,MoveSourceOutput"`
Action Action `json:"action" doc:"Action to perform fe. GetVolume, SetVolume, SetMute..." enum:"GetStatus,GetBuildInfo,SetSinkVolume,SetSinkMuted,SetSinkInputVolume,SetSinkInputMuted,MoveSinkInput,SetSourceVolume,SetSourceMuted,SetSourceInputVolume,SetSourceInputMuted,MoveSourceOutput"`
// Paylod send with Set* actions if necessary
Payload interface{} `json:"payload,omitempty" doc:"Paylod send with Set* actions if necessary"`
}
Expand Down
22 changes: 11 additions & 11 deletions pactl/setVolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ import (
//
// Parameters:
// - kind: device type ("sink", "sink-input", "source", "source-input")
// - nameOrId: name for sinks/sources, numeric ID for inputs
// - nameOrID: name for sinks/sources, numeric ID for inputs
// - volume: volume level
func setVolume(kind string, nameOrId string, volume string) {
errPrefix := "ERROR [setVolume(" + kind + ", " + nameOrId + ", " + volume + ")]"
func setVolume(kind string, nameOrID string, volume string) {
errPrefix := "ERROR [setVolume(" + kind + ", " + nameOrID + ", " + volume + ")]"
volumeInPercent := fmt.Sprint(volume) + "%"

cmd := exec.Command("pactl", "set-"+kind+"-volume", nameOrId, volumeInPercent)
cmd := exec.Command("pactl", "set-"+kind+"-volume", nameOrID, volumeInPercent)
_, err := cmd.Output()
if err != nil {
log.Printf("%s $> pactl set-"+kind+"-volume"+nameOrId+" "+volumeInPercent+": %s\n", errPrefix, err)
log.Printf("%s $> pactl set-"+kind+"-volume"+nameOrID+" "+volumeInPercent+": %s\n", errPrefix, err)
}
}

// setMuted adjusts mute state for PulseAudio devices.
//
// Parameters:
// - kind: device type ("sink", "sink-input", "source", "source-input")
// - nameOrId: name for sinks/sources, numeric ID for inputs
// - nameOrID: name for sinks/sources, numeric ID for inputs
// - muted: muted state
func setMuted(kind string, nameOrId string, muted bool) {
func setMuted(kind string, nameOrID string, muted bool) {
mutedStr := strconv.FormatBool(muted)
errPrefix := "ERROR [setMuted(" + kind + ", " + nameOrId + ", " + mutedStr + ")]"
errPrefix := "ERROR [setMuted(" + kind + ", " + nameOrID + ", " + mutedStr + ")]"

cmd := exec.Command("pactl", "set-"+kind+"-mute", nameOrId, mutedStr)
cmd := exec.Command("pactl", "set-"+kind+"-mute", nameOrID, mutedStr)

_, err := cmd.Output()
if err != nil {
log.Printf("%s $> pactl set-"+kind+"-mute "+nameOrId+" "+mutedStr+": %s\n", errPrefix, err)
log.Printf("%s $> pactl set-"+kind+"-mute "+nameOrID+" "+mutedStr+": %s\n", errPrefix, err)
}
}

// moveApp moves input or output app between sink/source devices
//
// Parameters:
// - kind: device type ("sink-input", "source-output")
// - appId: sink-input ID or source-output ID
// - appID: sink-input ID or source-output ID
// - deviceName: sink name or source name
func moveApp(kind string, appID string, deviceName string) {
errPrefix := "ERROR [moveApp(" + kind + ", " + appID + ", " + deviceName + ")]"
Expand Down
2 changes: 1 addition & 1 deletion ws/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func BroadcastUpdates() {
updatedClients := 0
for conn := range clients {
conn.SetWriteDeadline(time.Now().Add(writeWait))
err := safeWriteJson(conn, res)
err := safeWriteJSON(conn, res)
if err != nil {
log.Printf("Error broadcast VOLUME update to client: %v\n", err)
conn.Close()
Expand Down
4 changes: 2 additions & 2 deletions ws/handleWebSocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func HandleWebSocket(w http.ResponseWriter, r *http.Request) {
Payload: status,
}

if err := safeWriteJson(conn, initialResponse); err != nil {
if err := safeWriteJSON(conn, initialResponse); err != nil {
log.Printf("Error sending initial sinks data: %v\n", err)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ func HandleWebSocket(w http.ResponseWriter, r *http.Request) {

handleServerLog(&msg, &res)

if err := safeWriteJson(conn, res); err != nil {
if err := safeWriteJSON(conn, res); err != nil {
log.Printf("Error writing JSON: %v\n", err)
break
}
Expand Down
2 changes: 1 addition & 1 deletion ws/safeWriteJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
writeMutex sync.Mutex
)

func safeWriteJson(conn *websocket.Conn, v interface{}) error {
func safeWriteJSON(conn *websocket.Conn, v interface{}) error {
writeMutex.Lock()
defer writeMutex.Unlock()
return conn.WriteJSON(v)
Expand Down

0 comments on commit 55ad586

Please sign in to comment.