Added simple tray icons and improved logging

This commit is contained in:
Uthman Fatih 2026-11-02 20:48:21 +00:00
parent 315e1672a3
commit 803ab765b9
5 changed files with 84 additions and 7 deletions

8
go.mod
View File

@ -3,3 +3,11 @@ module git.uthmn.com/boiabba/anical
go 1.27.3 go 1.27.3
require github.com/spf13/pflag v1.0.10 require github.com/spf13/pflag v1.0.10
require (
fyne.io/systray v1.12.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.28.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)

10
go.sum
View File

@ -1,2 +1,12 @@
fyne.io/systray v1.12.2 h1:Y8DZxgLHsVQt6rY9Zrkkg+j67S7vv/1F2viOWKPpVeA=
fyne.io/systray v1.12.2/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
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/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

32
internal/tray/tray.go Normal file
View File

@ -0,0 +1,32 @@
package tray
import (
"fmt"
"fyne.io/systray"
)
func Tray(iconData []byte) {
systray.Run(func() {
onReady(iconData)
}, onExit)
}
func onReady(iconData []byte) {
fmt.Println("Displaying tray icons")
systray.SetIcon(iconData)
systray.SetTitle("AniCal")
systray.SetTooltip("AniCal - Anime and Manga calendar")
mQuit := systray.AddMenuItem("Quit", "Quit AniCal")
go func() {
<-mQuit.ClickedCh
systray.Quit()
}()
}
func onExit() {
fmt.Println("AniCal has exited (via system tray)")
}

35
main.go
View File

@ -3,11 +3,19 @@ package main
import ( import (
"fmt" "fmt"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"git.uthmn.com/boiabba/anical/internal/debug" "git.uthmn.com/boiabba/anical/internal/debug"
"git.uthmn.com/boiabba/anical/internal/fetch" // "git.uthmn.com/boiabba/anical/internal/fetch"
_ "embed"
"git.uthmn.com/boiabba/anical/internal/tray"
) )
//go:embed assets/anical.png
var iconData []byte
func main() { func main() {
fmt.Print(` fmt.Print(`
::: :::: ::: ::::::::::: :::::::: ::: ::: ::: :::: ::: ::::::::::: :::::::: ::: :::
@ -19,13 +27,32 @@ func main() {
### ### ### #### ########### ######## ### ### ########## ### ### ### #### ########### ######## ### ### ##########
`) `)
config := zap.NewDevelopmentConfig()
config.Level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
var debugFlag = flag.BoolP("debug", "d", false, "Enable debug mode") var debugFlag = flag.BoolP("debug", "d", false, "Enable debug mode")
var trayDisabledFlag = flag.Bool("disable-tray", false, "Disable the system tray")
flag.Parse() flag.Parse()
if *debugFlag { if *debugFlag {
fmt.Println("Debug mode enabled") config.Level.SetLevel(zapcore.DebugLevel)
debug.GetInfo() debug.GetInfo()
} }
go func() {
if !*trayDisabledFlag {
tray.Tray(iconData)
}
}()
fmt.Println("== Fetch ==")
fetch.Sorry() logger, err := config.Build()
if err != nil {
panic(err)
}
defer logger.Sync()
log := logger.Sugar()
log.Debug("Debug logging enabled")
log.Infof("Starting AniCal")
} }

View File

@ -55,7 +55,7 @@ Running hooks and middleware is atomic so it never exits unfinished
## Folder structure ## Folder structure
``` ```text
assets/ assets/
├── anical.png ├── anical.png
└── banner.png └── banner.png