From 3e0b10a8f51a282b22a8cfc4e6a5342d4b741867 Mon Sep 17 00:00:00 2001 From: simonkellet Date: Fri, 16 Sep 2022 20:13:02 +0100 Subject: [PATCH] improvements --- config.go | 6 ++++++ go.mod | 9 +++++++++ go.sum | 13 +++++++++++++ main.go | 4 ++-- run.go | 37 ++++++++++++++++++++++++++++++++++--- tasks.go | 4 ---- tasks.json | 4 ++-- 7 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 go.sum diff --git a/config.go b/config.go index 9114ae1..112080a 100644 --- a/config.go +++ b/config.go @@ -27,3 +27,9 @@ func LoadConfig(filename string) (*Config, error) { } return config, nil } + +/* +func CreateSampleConfig() (*Config, error) { + return +} +*/ diff --git a/go.mod b/go.mod index 14cff5f..1271ef6 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3dce5b3 --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index a291ac2..7f1ca09 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/run.go b/run.go index b4dc975..2753c83 100644 --- a/run.go +++ b/run.go @@ -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 +} diff --git a/tasks.go b/tasks.go index e6affba..e9669e5 100644 --- a/tasks.go +++ b/tasks.go @@ -9,7 +9,3 @@ type Task struct { CMD string `json:"cmd"` Icon string `json:"icon"` } - -func (t *Task) PrintTask() { - -} diff --git a/tasks.json b/tasks.json index 147c859..bb968e4 100644 --- a/tasks.json +++ b/tasks.json @@ -4,8 +4,8 @@ { "taskname": "Example Task", "taskdesc": "This is placeholder", - "interval": -1, - "cmd": " ", + "interval": 100, + "cmd": "we" , "icon": " " },