hyprman/internal/mako.go

83 lines
1.8 KiB
Go
Raw Normal View History

2024-05-21 15:41:20 -05:00
package hyprman
import (
"encoding/json"
"fmt"
"log"
"os/exec"
2024-06-06 13:11:21 -05:00
"github.com/charmbracelet/lipgloss"
)
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"`
}
2024-06-06 13:11:21 -05:00
// type Notifcation
// type History struct {
// notifications []Notifcation
// }
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
}
2024-06-06 13:11:21 -05:00
// TODO: replace with simple Render function
func displayNotification(n MakoNotification) {
2024-06-06 13:11:21 -05:00
appStyle := lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("3")).
PaddingTop(1)
textStyle := lipgloss.NewStyle().Width(80).PaddingLeft(2).
BorderStyle(lipgloss.ThickBorder()).
BorderLeft(true)
fmt.Println(appStyle.Render(n.AppName.Data))
if len(n.Summary.Data) > 0 {
2024-06-06 13:11:21 -05:00
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("14")).
Render(n.Summary.Data))
}
if len(n.Body.Data) > 0 {
2024-06-06 13:11:21 -05:00
fmt.Println(textStyle.
BorderForeground(lipgloss.Color("2")).
Render(n.Body.Data))
}
}
2024-06-06 13:11:21 -05:00
func ListNotifications(number int) {
history := getHistory()
for i, notification := range history.Data[0] {
displayNotification(notification)
if i > number-1 {
break
}
}
}