summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--statusbar.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/statusbar.go b/statusbar.go
index 73f3cb2..47b04f9 100644
--- a/statusbar.go
+++ b/statusbar.go
@@ -8,6 +8,7 @@ import (
"strconv"
"os"
"os/exec"
+ "os/signal"
"io/ioutil"
"time"
"flag"
@@ -17,6 +18,8 @@ import (
"github.com/google/shlex"
)
+var config Config
+
type MusicPlayer interface {
nowPlaying() string
status() int
@@ -396,8 +399,26 @@ func readConfig(configPath *string) ([]byte, error) {
return content, err
}
+func awaitSighup(configPath *string) {
+ for {
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, syscall.SIGHUP)
+ <-c
+ fmt.Fprintf(os.Stderr, "Reloading config...")
+ content, err := readConfig(configPath)
+ if err != nil {
+ panic(err)
+ }
+ _, err = toml.Decode(string(content), &config)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
func main() {
- configPath := flag.String("c", getDefaultConfigPath(), "The config path")
+ configPath := flag.String("c", getDefaultConfigPath(), "The config path.")
+ daemon := flag.Bool("d", false, "Whether to launch statusbar as a daemon process or not.")
flag.Parse()
if *configPath == "-" {
configPath = nil
@@ -406,11 +427,14 @@ func main() {
if err != nil {
panic(err)
}
- var config Config
+ //var config Config
_, err = toml.Decode(string(content), &config)
if err != nil {
panic(err)
}
+ if *daemon {
+ go awaitSighup(configPath)
+ }
for true {
var b strings.Builder
for i, section := range config.Sections {