2024-05-21 15:41:20 -05:00
|
|
|
package hyprman
|
|
|
|
|
2024-06-01 01:25:29 -05:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MakoHistory struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Data [][]MakoNotification `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MakoNotification struct {
|
|
|
|
AppName MakoNotificationData `json:"app-name"`
|
|
|
|
Summary MakoNotificationData
|
|
|
|
Body MakoNotificationData
|
|
|
|
// AppIcon MakoNotificationData `json:"app-icon"`
|
|
|
|
// Category MakoNotificationData
|
|
|
|
// DesktopEntry MakoNotificationData `json:"desktop-entry"`
|
|
|
|
// Id MakoNotificationData
|
|
|
|
// Urgency MakoNotificationData
|
|
|
|
// Actions MakoNotificationData
|
|
|
|
}
|
|
|
|
|
|
|
|
type MakoNotificationData struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Data string `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func getHistory() MakoHistory {
|
|
|
|
var history MakoHistory
|
|
|
|
makoOutput, err := exec.Command("makoctl", "history").CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
json.Unmarshal(makoOutput, &history)
|
|
|
|
return history
|
|
|
|
}
|
|
|
|
|
|
|
|
func displayNotification(n MakoNotification) {
|
|
|
|
fmt.Println("- ", n.AppName.Data)
|
|
|
|
if len(n.Summary.Data) > 0 {
|
|
|
|
fmt.Println(n.Summary.Data)
|
|
|
|
}
|
|
|
|
if len(n.Body.Data) > 0 {
|
|
|
|
fmt.Println(n.Body.Data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListNotifications(number int) {
|
|
|
|
history := getHistory()
|
|
|
|
// TODO: align output ? by app-name
|
|
|
|
for i, notification := range history.Data[0] {
|
|
|
|
displayNotification(notification)
|
|
|
|
if i > number-1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|