Skip to content

Commit

Permalink
Merge pull request #25 from nwg-piotr/logging
Browse files Browse the repository at this point in the history
Logging + 1 bug fixed
  • Loading branch information
nwg-piotr authored Sep 17, 2021
2 parents 6ca8e6a + 3768e21 commit 7b76c27
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified bin/nwg-drawer
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 7 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand All @@ -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=
31 changes: 16 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
Expand All @@ -12,14 +11,16 @@ 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"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)

const version = "0.1.10"
const version = "0.1.12"

var (
appDirs []string
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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)
}
}
Expand All @@ -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()
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -242,7 +243,7 @@ func main() {
layershell.SetMonitor(win, monitor)

} else {
println(fmt.Sprintf("%s", err))
log.Errorf("%s", err)
}
}

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
25 changes: 13 additions & 12 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"io/fs"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions uicomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
} else if btnEvent.Button() == 3 {
pinItem(ID)
pinnedFlowBox = setUpPinnedFlowBox()
return true
}
return false
})
Expand Down

0 comments on commit 7b76c27

Please sign in to comment.