Add LaunchProgram provider
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
3aa6de8e45
commit
6998dd456d
2 changed files with 44 additions and 0 deletions
|
@ -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(),
|
||||
|
|
43
internal/providers/launchProgram.go
Normal file
43
internal/providers/launchProgram.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue