implement basic makoctl notification list
This commit is contained in:
parent
372fd3b36f
commit
fc532ebcf0
3 changed files with 72 additions and 38 deletions
11
cmd/mako.go
11
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")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue