Add LaunchProgram provider

Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
akp 2022-06-09 13:32:35 +01:00
parent 3aa6de8e45
commit 6998dd456d
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
2 changed files with 44 additions and 0 deletions

View file

@ -45,6 +45,7 @@ func run() error {
// Blocks registered first will be the rightmost in the status bar.
b.RegisterBlockGenerator(
providers.NewLaunchProgram("MINI", "/home/akp/.local/bin/minisettings"),
providers.NewDateTime(),
providers.NewTimer(true),
providers.NewPulseaudioVolume(),

View file

@ -0,0 +1,43 @@
package providers
import (
"github.com/codemicro/bar/internal/i3bar"
"os"
"github.com/rs/zerolog/log"
)
type LaunchProgram struct {
Text string
Executable string
name string
}
func NewLaunchProgram(text string, executable string) i3bar.BlockGenerator {
return &LaunchProgram{
Text: text,
Executable: executable,
name: "launchProgram",
}
}
func (g *LaunchProgram) Block(*i3bar.ColorSet) (*i3bar.Block, error) {
return &i3bar.Block{
Name: g.name,
FullText: g.Text,
}, nil
}
func (g *LaunchProgram) GetNameAndInstance() (string, string) {
return g.name, ""
}
func (g *LaunchProgram) OnClick(event *i3bar.ClickEvent) bool {
process, err := os.StartProcess(g.Executable, []string{g.Executable}, &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}})
if err != nil {
log.Error().Err(err).Str("location", "launchProgram_onClick").Msg("Could not start process")
return false
}
_ = process.Release()
return false
}