️ Do not save config changes to disk immediately

This commit is contained in:
2024-12-16 21:29:51 +01:00
parent 35681102b4
commit 5122791f85
3 changed files with 64 additions and 13 deletions

40
api.go
View File

@ -123,7 +123,7 @@ func createPort(body CreatePortRequest) (gin.H, gin.H) {
registerPort(&newPort, "output")
portConfig.Output = append(portConfig.Output, newPort)
}
saveConfig("ports", &portConfig)
markConfig("ports")
onPortListChange()
return gin.H{"success": true, "UUID": id}, nil
}
@ -155,7 +155,7 @@ func deletePort(id string) gin.H {
// Unregister port
unregisterPort(port)
saveConfig("ports", &portConfig)
markConfig("ports")
onPortListChange()
return nil
}
@ -206,18 +206,25 @@ func setState(id string, body SetPortRequest) (gin.H, gin.H) {
return nil, gin.H{"success": false, "error": "Port with provided UUID does not exist!"}
}
if body.Mute != nil {
didChange := false
if body.Mute != nil && port.State.Mute != *body.Mute {
port.State.Mute = *body.Mute
didChange = true
}
if body.Volume != nil {
if body.Volume != nil && port.State.Volume != *body.Volume {
port.State.Volume = *body.Volume
didChange = true
}
if body.Balance != nil {
if body.Balance != nil && port.State.Balance != *body.Balance {
port.State.Balance = *body.Balance
didChange = true
}
saveConfig("ports", &portConfig)
if didChange {
markConfig("ports")
onPortChange(port)
}
return gin.H{"success": true, "state": port.State}, nil
}
@ -253,7 +260,7 @@ func editPort(id string, body EditPortRequest) (gin.H, gin.H) {
port.Name = *body.Name
}
saveConfig("ports", &portConfig)
markConfig("ports")
onPortChange(port)
return gin.H{"success": true, "port": port}, nil
}
@ -291,7 +298,7 @@ func createRoute(id string, body CreateRouteRequest) gin.H {
}
from.Route = append(from.Route, PortRoute{ToUUID: body.To, Mute: true, Volume: 0, Balance: 0})
saveConfig("ports", &portConfig)
markConfig("ports")
onPortChange(from)
return nil
}
@ -331,18 +338,25 @@ func setRoute(fromId string, toId string, body SetRouteRequest) (gin.H, gin.H) {
continue
}
if body.Mute != nil {
didChange := false
if body.Mute != nil && from.Route[i].Mute != *body.Mute {
from.Route[i].Mute = *body.Mute
didChange = true
}
if body.Volume != nil {
if body.Volume != nil && from.Route[i].Volume != *body.Volume {
from.Route[i].Volume = *body.Volume
didChange = true
}
if body.Balance != nil {
if body.Balance != nil && from.Route[i].Balance != *body.Balance {
from.Route[i].Balance = *body.Balance
didChange = true
}
saveConfig("ports", &portConfig)
if didChange {
markConfig("ports")
onPortChange(from)
}
return gin.H{"success": true, "state": from.Route[i]}, nil
}
@ -372,7 +386,7 @@ func deleteRoute(fromId string, toId string) gin.H {
}
from.Route = append(from.Route[:i], from.Route[i+1:]...)
saveConfig("ports", &portConfig)
markConfig("ports")
onPortListChange()
return nil
}