From a32a141867476033bfb477966daef86a6126752c Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sat, 1 Jun 2024 01:25:29 -0500 Subject: [PATCH] implement basic makoctl notification list --- cmd/mako.go | 11 ++++-- internal/hyprman.go | 7 +++- internal/mako.go | 92 +++++++++++++++++++++++++++++---------------- 3 files changed, 72 insertions(+), 38 deletions(-) diff --git a/cmd/mako.go b/cmd/mako.go index ee0c8fc..aaccd63 100644 --- a/cmd/mako.go +++ b/cmd/mako.go @@ -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") } diff --git a/internal/hyprman.go b/internal/hyprman.go index 96e7fd9..2d22f43 100644 --- a/internal/hyprman.go +++ b/internal/hyprman.go @@ -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() } diff --git a/internal/mako.go b/internal/mako.go index b6d5a63..25d5b6e 100644 --- a/internal/mako.go +++ b/internal/mako.go @@ -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 + } + } +}