diff --git a/api/actions.go b/api/actions.go index b552f86..5863e0d 100644 --- a/api/actions.go +++ b/api/actions.go @@ -95,7 +95,13 @@ func declareActionsRoutes(cfg *config.Config, router *gin.RouterGroup) { actionsRoutes.POST("/run", func(c *gin.Context) { 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 { c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to run the action: %s", err.Error())}) return diff --git a/model/action.go b/model/action.go index 7a0a744..1790fde 100644 --- a/model/action.go +++ b/model/action.go @@ -174,8 +174,9 @@ func (a *Action) Remove() error { 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.Env = append(cmd.Environ(), fmt.Sprintf("LANG=%s", settings.Language)) err = cmd.Start() return } diff --git a/model/routine.go b/model/routine.go index e1c6ba0..f518934 100644 --- a/model/routine.go +++ b/model/routine.go @@ -148,9 +148,15 @@ func (a *Routine) Launch(cfg *config.Config) error { 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) - cmd, err := act.Launch() + cmd, err := act.Launch(settings) if err != nil { log.Printf("Unable to launch the action %q: %s", s.Action, err.Error()) continue diff --git a/player/player.go b/player/player.go index 4b10afe..25bc2d1 100644 --- a/player/player.go +++ b/player/player.go @@ -120,8 +120,13 @@ func NewPlayer(cfg *config.Config, routines []reveil.Identifier) (*Player, error return &p, nil } -func (p *Player) launchAction(a *reveil.Action) (err error) { - p.currentCmd, err = a.Launch() +func (p *Player) launchAction(cfg *config.Config, a *reveil.Action) (err error) { + 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) err = p.currentCmd.Wait() @@ -177,7 +182,7 @@ loop: log.Println("weather time!") p.dontUpdateVolume = true p.hasSpokeWeather = true - go p.launchAction(p.weatherAction) + go p.launchAction(cfg, p.weatherAction) } else { p.dontUpdateVolume = false p.volume = uint16(math.Log(1+float64(p.ntick)/8) * 9500)