implement basic makoctl notification list

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

View file

@ -1,20 +1,23 @@
package cmd package cmd
import ( import (
"fmt" "git.dayl.in/daylin/hyprman/internal"
"github.com/spf13/cobra" "github.com/spf13/cobra"
// "git.dayl.in/daylin/hyprman/internal"
) )
var makoCmd = &cobra.Command{ var makoCmd = &cobra.Command{
Use: "mako", Use: "mako",
Short: "mako integration", Short: "mako integration",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("hahah mako baby") hyprman.ListNotifications(number)
}, },
} }
var (
number int
)
func init() { func init() {
rootCmd.AddCommand(makoCmd) 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) { func notify(message string) {
cmd := exec.Command("notify-send", "hyprman", message) cmd := exec.Command(
"notify-send",
"--app-name=hyprman",
"--transient",
message,
)
cmd.Run() cmd.Run()
} }

View file

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