Define the LANG variable when executing actions
This commit is contained in:
parent
ea1724e2ca
commit
37c951ef85
@ -95,7 +95,13 @@ func declareActionsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||||||
actionsRoutes.POST("/run", func(c *gin.Context) {
|
actionsRoutes.POST("/run", func(c *gin.Context) {
|
||||||
action := c.MustGet("action").(*reveil.Action)
|
action := c.MustGet("action").(*reveil.Action)
|
||||||
|
|
||||||
cmd, err := action.Launch()
|
settings, err := reveil.ReadSettings(cfg.SettingsFile)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to run the action: unable to read settings: %s", err.Error())})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd, err := action.Launch(settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to run the action: %s", err.Error())})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to run the action: %s", err.Error())})
|
||||||
return
|
return
|
||||||
|
@ -174,8 +174,9 @@ func (a *Action) Remove() error {
|
|||||||
return os.Remove(a.Path)
|
return os.Remove(a.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Action) Launch() (cmd *exec.Cmd, err error) {
|
func (a *Action) Launch(settings *Settings) (cmd *exec.Cmd, err error) {
|
||||||
cmd = exec.Command(a.fullPath)
|
cmd = exec.Command(a.fullPath)
|
||||||
|
cmd.Env = append(cmd.Environ(), fmt.Sprintf("LANG=%s", settings.Language))
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -148,9 +148,15 @@ func (a *Routine) Launch(cfg *config.Config) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settings, err := ReadSettings(cfg.SettingsFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Unable to read settings: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(s.Delay) * time.Second)
|
time.Sleep(time.Duration(s.Delay) * time.Second)
|
||||||
|
|
||||||
cmd, err := act.Launch()
|
cmd, err := act.Launch(settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to launch the action %q: %s", s.Action, err.Error())
|
log.Printf("Unable to launch the action %q: %s", s.Action, err.Error())
|
||||||
continue
|
continue
|
||||||
|
@ -120,8 +120,13 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error
|
|||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) launchAction(a *reveil.Action) (err error) {
|
func (p *Player) launchAction(cfg *config.Config, a *reveil.Action) (err error) {
|
||||||
p.currentCmd, err = a.Launch()
|
settings, err := reveil.ReadSettings(cfg.SettingsFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to read settings: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.currentCmd, err = a.Launch(settings)
|
||||||
log.Println("Running action ", a.Name)
|
log.Println("Running action ", a.Name)
|
||||||
|
|
||||||
err = p.currentCmd.Wait()
|
err = p.currentCmd.Wait()
|
||||||
@ -177,7 +182,7 @@ loop:
|
|||||||
log.Println("weather time!")
|
log.Println("weather time!")
|
||||||
p.dontUpdateVolume = true
|
p.dontUpdateVolume = true
|
||||||
p.hasSpokeWeather = true
|
p.hasSpokeWeather = true
|
||||||
go p.launchAction(p.weatherAction)
|
go p.launchAction(cfg, p.weatherAction)
|
||||||
} else {
|
} else {
|
||||||
p.dontUpdateVolume = false
|
p.dontUpdateVolume = false
|
||||||
p.volume = uint16(math.Log(1+float64(p.ntick)/8) * 9500)
|
p.volume = uint16(math.Log(1+float64(p.ntick)/8) * 9500)
|
||||||
|
Loading…
Reference in New Issue
Block a user