refactor: separate dbus functions from internal

This commit is contained in:
Viktor Varland 2025-04-03 09:48:29 +02:00
parent 549b520a4c
commit 1c1160eb00
Signed by: varl
GPG key ID: 7459F0B410115EE8

21
main.go
View file

@ -58,29 +58,30 @@ func (s notificationServer) Notify(appName string,
} }
defer func() { defer func() {
timeout, err := time.ParseDuration(fmt.Sprintf("%vms", n.ExpireTimeout))
if n.ExpireTimeout == -1 || err != nil {
timeout = time.Duration(5000 * time.Millisecond)
}
time.Sleep(timeout)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
go s.CloseNotification(n.ReplacesId) go clearNotification(n.ReplacesId, n.ExpireTimeout)
wg.Done() wg.Done()
}() }()
//const ClearLine = "\033[2K"
//fmt.Printf(ClearLine)
//fmt.Printf("\r")
fmt.Printf("%s\n", res) fmt.Printf("%s\n", res)
return 0, nil return 0, nil
} }
func (s notificationServer) CloseNotification(id uint32) { func clearNotification(id uint32, t int32) {
timeout, err := time.ParseDuration(fmt.Sprintf("%vms", t))
if t == -1 || err != nil {
timeout = time.Duration(5000 * time.Millisecond)
}
time.Sleep(timeout)
log.Println("close the notification", id) log.Println("close the notification", id)
fmt.Printf("\n") fmt.Printf("\n")
} }
func (s notificationServer) CloseNotification(id uint32) {
log.Println("dbus called CloseNotification", id)
}
func (s notificationServer) GetCapabilities() ([]string, *dbus.Error) { func (s notificationServer) GetCapabilities() ([]string, *dbus.Error) {
return []string{"action-icons", "actions", "body", "body-hyperlinks", "body-images", "body-markup", "icon-multi", "icon-static", "persistence", "sound"}, nil return []string{"action-icons", "actions", "body", "body-hyperlinks", "body-images", "body-markup", "icon-multi", "icon-static", "persistence", "sound"}, nil
} }