improvements

main
simonkellet 2 years ago
parent f85131b80a
commit 3e0b10a8f5
  1. 6
      config.go
  2. 9
      go.mod
  3. 13
      go.sum
  4. 4
      main.go
  5. 37
      run.go
  6. 4
      tasks.go
  7. 4
      tasks.json

@ -27,3 +27,9 @@ func LoadConfig(filename string) (*Config, error) {
}
return config, nil
}
/*
func CreateSampleConfig() (*Config, error) {
return
}
*/

@ -1,3 +1,12 @@
module go-taskrem
go 1.19
require (
github.com/gen2brain/beeep v0.0.0-20220909211152-5a9ec94374f6 // indirect
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
)

@ -0,0 +1,13 @@
github.com/gen2brain/beeep v0.0.0-20220909211152-5a9ec94374f6 h1:jFEK/SA/7E8lg9T33+y8D4Z0I782+bbiEjmyyklRzRQ=
github.com/gen2brain/beeep v0.0.0-20220909211152-5a9ec94374f6/go.mod h1:/WeFVhhxMOGypVKS0w8DUJxUBbHypnWkUVnW7p5c9Pw=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

@ -16,8 +16,8 @@ func main() {
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot load config file: %s\n\t%s\n", configFlag, err)
}
//fmt.Println(config.Tasks[0].TaskName)
TaskRun(*config)
//exampleoutput := TaskCMD(*config)
//fmt.Printf("%s", exampleoutput)
}

@ -1,11 +1,42 @@
package main
import "fmt"
import (
"fmt"
"os"
"os/exec"
"github.com/gen2brain/beeep"
)
// Run will take the config file and for each task, run a go routine
func TaskRun(c Config) {
for i, v := range c.Tasks {
fmt.Printf("%d, %s", i, v)
for i := range c.Tasks {
title := c.Tasks[i].TaskName
desc := c.Tasks[i].TaskDesc
err := beeep.Notify(title, desc, "")
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: could not display \"%s\":\n\t%s\n", title, err)
}
}
}
// TaskCMD will take the config struct and run all the "CMD" fields with "bash -c [command]" and return the output
func TaskCMD(c Config) (output string) {
for i := range c.Tasks {
command := c.Tasks[i].CMD
if command == " " {
fmt.Printf("INFO: Task %s has the cmd section empty. Will just return...\n", c.Tasks[i].TaskName)
return
}
out, err := exec.Command("bash", "-c", command).Output()
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: could not run command \"%s\":\n\t%s\n", command, err)
}
//fmt.Printf("Output:\n%s\n", out)
return string(out)
}
return
}

@ -9,7 +9,3 @@ type Task struct {
CMD string `json:"cmd"`
Icon string `json:"icon"`
}
func (t *Task) PrintTask() {
}

@ -4,8 +4,8 @@
{
"taskname": "Example Task",
"taskdesc": "This is placeholder",
"interval": -1,
"cmd": " ",
"interval": 100,
"cmd": "we" ,
"icon": " "
},

Loading…
Cancel
Save