diff --git a/Makefile b/Makefile index 2758ea3..48198c5 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ get: go get github.com/dlasky/gotk3-layershell/layershell go get github.com/joshuarubin/go-sway go get github.com/allan-simon/go-singleinstance + go get "github.com/sirupsen/logrus" build: go build -o bin/nwg-drawer *.go diff --git a/bin/nwg-drawer b/bin/nwg-drawer index 6d5ccee..609d61b 100755 Binary files a/bin/nwg-drawer and b/bin/nwg-drawer differ diff --git a/go.mod b/go.mod index f46def1..3f18a8c 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,5 @@ require ( github.com/dlasky/gotk3-layershell v0.0.0-20210331230524-5cca0b819261 github.com/gotk3/gotk3 v0.6.0 github.com/joshuarubin/go-sway v0.0.4 + github.com/sirupsen/logrus v1.8.1 ) diff --git a/go.sum b/go.sum index 13253ab..43ae0c6 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,8 @@ github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37 h1:28uU3TtuvQ6KRndxg9TrC868jBWmSKgh0GTXkACCXmA= github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37/go.mod h1:6AXRstqK+32jeFmw89QGL2748+dj34Av4xc/I9oo9BY= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlasky/gotk3-layershell v0.0.0-20210331230524-5cca0b819261 h1:eoXn91ckLWKMXmQKX34UHEF2XMyQpRnnP80fDiu+kys= github.com/dlasky/gotk3-layershell v0.0.0-20210331230524-5cca0b819261/go.mod h1:d56Gslp3IaiT8lqxD/lO1Msz1wYgD8D/HTKHgSdg9tU= github.com/gotk3/gotk3 v0.5.3-0.20210223154815-289cfb6dbf32/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q= @@ -13,7 +14,10 @@ github.com/joshuarubin/lifecycle v1.0.0 h1:N/lPEC8f+dBZ1Tn99vShqp36LwB+LI7XNAiNa github.com/joshuarubin/lifecycle v1.0.0/go.mod h1:sRy++ATvR9Ee21tkRdFkQeywAWvDsue66V70K0Dnl54= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= @@ -22,3 +26,5 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= golang.org/x/sync v0.0.0-20190412183630-56d357773e84 h1:IqXQ59gzdXv58Jmm2xn0tSOR9i6HqroaOFRQ3wR/dJQ= golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go index f981dbb..8e756b6 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "log" "os" "os/signal" "path/filepath" @@ -12,6 +11,8 @@ import ( "syscall" "time" + log "github.com/sirupsen/logrus" + "github.com/allan-simon/go-singleinstance" "github.com/dlasky/gotk3-layershell/layershell" "github.com/gotk3/gotk3/gdk" @@ -141,7 +142,7 @@ func main() { for { s := <-signalChan if s == syscall.SIGTERM { - println("SIGTERM received, bye bye!") + log.Info("SIGTERM received, bye bye!") gtk.MainQuit() } } @@ -155,7 +156,7 @@ func main() { if err == nil { i, err := strconv.Atoi(pid) if err == nil { - println("Running instance found, sending SIGTERM and exiting...") + log.Info("Running instance found, sending SIGTERM and exiting...") syscall.Kill(i, syscall.SIGTERM) } } @@ -167,7 +168,7 @@ func main() { if *lang == "" && os.Getenv("LANG") != "" { *lang = strings.Split(os.Getenv("LANG"), ".")[0] } - println(fmt.Sprintf("lang: %s", *lang)) + log.Info(fmt.Sprintf("lang: %s", *lang)) // ENVIRONMENT configDirectory = configDir() @@ -187,7 +188,7 @@ func main() { if err != nil { pinned = nil } - println(fmt.Sprintf("Found %v pinned items", len(pinned))) + log.Info(fmt.Sprintf("Found %v pinned items", len(pinned))) cssFile := filepath.Join(configDirectory, *cssFileName) @@ -196,7 +197,7 @@ func main() { setUpCategories() desktopFiles := listDesktopFiles() - println(fmt.Sprintf("Found %v desktop files", len(desktopFiles))) + log.Info(fmt.Sprintf("Found %v desktop files", len(desktopFiles))) status = parseDesktopFiles(desktopFiles) @@ -205,9 +206,9 @@ func main() { paFile := filepath.Join(configDirectory, "preferred-apps.json") preferredApps, err = loadPreferredApps(paFile) if err != nil { - println(fmt.Sprintf("Custom associations file %s not found or invalid", paFile)) + log.Error(fmt.Sprintf("Custom associations file %s not found or invalid", paFile)) } else { - println(fmt.Sprintf("Found %v associations in %s", len(preferredApps), paFile)) + log.Info(fmt.Sprintf("Found %v associations in %s", len(preferredApps), paFile)) } // USER INTERFACE @@ -217,10 +218,10 @@ func main() { err = cssProvider.LoadFromPath(cssFile) if err != nil { - println(fmt.Sprintf("ERROR: %s css file not found or erroneous. Using GTK styling.", cssFile)) - println(fmt.Sprintf("%s", err)) + log.Errorf("ERROR: %s css file not found or erroneous. Using GTK styling.", cssFile) + log.Errorf("%s", err) } else { - println(fmt.Sprintf("Using style from %s", cssFile)) + log.Info(fmt.Sprintf("Using style from %s", cssFile)) screen, _ := gdk.ScreenGetDefault() gtk.AddProviderForScreen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) } @@ -242,7 +243,7 @@ func main() { layershell.SetMonitor(win, monitor) } else { - println(fmt.Sprintf("%s", err)) + log.Errorf("%s", err) } } @@ -307,7 +308,7 @@ func main() { This feature is not really supported and will stay undocumented. */ if !wayland() { - println("Not Wayland, oh really?") + log.Info("Not Wayland, oh really?") win.SetDecorated(false) win.Maximize() } @@ -400,6 +401,6 @@ func main() { } t := time.Now() - println(fmt.Sprintf("UI created in %v ms. Thank you for your patience.", t.Sub(timeStart).Milliseconds())) + log.Info(fmt.Sprintf("UI created in %v ms. Thank you for your patience.", t.Sub(timeStart).Milliseconds())) gtk.Main() } diff --git a/tools.go b/tools.go index 7726356..5e66e90 100644 --- a/tools.go +++ b/tools.go @@ -8,7 +8,6 @@ import ( "io" "io/fs" "io/ioutil" - "log" "os" "os/exec" "path/filepath" @@ -17,6 +16,8 @@ import ( "strings" "time" + log "github.com/sirupsen/logrus" + "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" @@ -49,7 +50,7 @@ func createPixbuf(icon string, size int) (*gdk.Pixbuf, error) { if strings.Contains(icon, "/") { pixbuf, err := gdk.PixbufNewFromFileAtSize(icon, size, size) if err != nil { - println(fmt.Sprintf("%s", err)) + log.Errorf("%s", err) return nil, err } return pixbuf, nil @@ -92,7 +93,7 @@ func mapXdgUserDirs() map[string]string { userDirsFile := filepath.Join(home, ".config/user-dirs.dirs") if pathExists(userDirsFile) { - println(fmt.Sprintf("Using XDG user dirs from %s", userDirsFile)) + log.Info(fmt.Sprintf("Using XDG user dirs from %s", userDirsFile)) lines, _ := loadTextFile(userDirsFile) for _, l := range lines { if strings.HasPrefix(l, "XDG_DOCUMENTS_DIR") { @@ -116,7 +117,7 @@ func mapXdgUserDirs() map[string]string { } } } else { - println(fmt.Sprintf("%s file not found, using defaults", userDirsFile)) + log.Warnf("%s file not found, using defaults", userDirsFile) } return result @@ -177,13 +178,13 @@ func createDir(dir string) { if _, err := os.Stat(dir); os.IsNotExist(err) { err := os.MkdirAll(dir, os.ModePerm) if err == nil { - fmt.Println("Creating dir:", dir) + log.Infof("Creating dir: %s", dir) } } } func copyFile(src, dst string) error { - fmt.Println("Copying file:", dst) + log.Infof("Copying file: %s", dst) var err error var srcfd *os.File @@ -378,7 +379,7 @@ func parseDesktopFiles(desktopFiles []string) string { return desktopEntries[i].NameLoc < desktopEntries[j].NameLoc }) summary := fmt.Sprintf("%v entries (+%v hidden)", len(desktopEntries)-hidden, hidden) - println(fmt.Sprintf("Skipped %v duplicates; %v .desktop entries hidden by \"NoDisplay=true\"", skipped, hidden)) + log.Infof("Skipped %v duplicates; %v .desktop entries hidden by \"NoDisplay=true\"", skipped, hidden) return summary } @@ -471,20 +472,20 @@ func loadTextFile(path string) ([]string, error) { func pinItem(itemID string) { for _, item := range pinned { if item == itemID { - println(item, "already pinned") + log.Warn(item, "already pinned") return } } pinned = append(pinned, itemID) savePinned() - println(itemID, "pinned") + log.Infof("%s pinned", itemID) } func unpinItem(itemID string) { if isIn(pinned, itemID) { pinned = remove(pinned, itemID) savePinned() - println(itemID, "unpinned") + log.Infof("%s unpinned", itemID) } } @@ -510,7 +511,7 @@ func savePinned() { _, err := f.WriteString(line + "\n") if err != nil { - println("Error saving pinned", err) + log.Errorf("Error saving pinned", err) } } } @@ -560,7 +561,7 @@ func launch(command string, terminal bool) { } msg := fmt.Sprintf("env vars: %s; command: '%s'; args: %s\n", envVars, elements[cmdIdx], elements[1+cmdIdx:]) - println(msg) + log.Info(msg) go cmd.Run()