implement basic makoctl notification list

This commit is contained in:
Daylin Morgan 2024-06-01 01:25:29 -05:00
parent 372fd3b36f
commit a32a141867
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 72 additions and 38 deletions

View file

@ -1,20 +1,23 @@
package cmd
import (
"fmt"
"git.dayl.in/daylin/hyprman/internal"
"github.com/spf13/cobra"
// "git.dayl.in/daylin/hyprman/internal"
)
var makoCmd = &cobra.Command{
Use: "mako",
Short: "mako integration",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("hahah mako baby")
hyprman.ListNotifications(number)
},
}
var (
number int
)
func init() {
rootCmd.AddCommand(makoCmd)
makoCmd.Flags().IntVarP(&number, "number", "n", 10, "number of notifications")
}

View file

@ -138,6 +138,11 @@ func openWorkspaces(monitors []Monitor) []int {
}
func notify(message string) {
cmd := exec.Command("notify-send", "hyprman", message)
cmd := exec.Command(
"notify-send",
"--app-name=hyprman",
"--transient",
message,
)
cmd.Run()
}

View file

@ -1,35 +1,61 @@
package hyprman
// import (
// "log"
// "os/exec"
// )
//
// type MakoHistory struct {
// Type string `json:"type"`
// Data [][]MakoNotification `json:"data"`
// }
//
// type MakoNotification struct {
// AppName MakoNotificationData `json:"app-name"`
// // AppIcon MakoNotificationData `json:"app-icon"`
// // Category MakoNotificationData
// // DesktopEntry MakoNotificationData `json:"desktop-entry"`
// Summary MakoNotificationData `json:"summary"`
// Body MakoNotificationData
// // Id MakoNotificationData
// // Urgency MakoNotificationData
// // Actions MakoNotificationData
// }
//
// type MakoNotificationData struct {
// Type string `json:"type"`
// Data string `json:"data"`
// }
//
// func getHistory() MakoHistory {
// makoOutput, err := exec.Command("makoctl", "history").CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// }
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
}
}
}