itd/cmd/itgui/notify.go

50 lines
1.1 KiB
Go
Raw Permalink Normal View History

2021-08-26 04:18:24 +00:00
package main
import (
"encoding/json"
"net"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"go.arsenm.dev/itd/internal/types"
)
func notifyTab(parent fyne.Window) *fyne.Container {
2021-08-26 15:47:17 +00:00
// Create new entry for notification title
2021-08-26 04:18:24 +00:00
titleEntry := widget.NewEntry()
titleEntry.SetPlaceHolder("Title")
2021-08-26 15:47:17 +00:00
// Create multiline entry for notification body
2021-08-26 04:18:24 +00:00
bodyEntry := widget.NewMultiLineEntry()
bodyEntry.SetPlaceHolder("Body")
2021-08-26 15:47:17 +00:00
// Create new button to send notification
2021-08-26 04:18:24 +00:00
sendBtn := widget.NewButton("Send", func() {
2021-08-26 15:47:17 +00:00
// Dial itd UNIX socket
2021-08-26 04:18:24 +00:00
conn, err := net.Dial("unix", SockPath)
if err != nil {
2021-08-27 15:47:24 +00:00
guiErr(err, "Error dialing socket", false, parent)
2021-08-26 04:18:24 +00:00
return
}
2021-08-26 15:47:17 +00:00
// Encode notify request on connection
2021-08-26 04:18:24 +00:00
json.NewEncoder(conn).Encode(types.Request{
Type: types.ReqTypeNotify,
Data: types.ReqDataNotify{
Title: titleEntry.Text,
Body: bodyEntry.Text,
},
})
})
2021-08-26 15:47:17 +00:00
// Return new container containing all elements
2021-08-26 04:18:24 +00:00
return container.NewVBox(
layout.NewSpacer(),
titleEntry,
bodyEntry,
sendBtn,
layout.NewSpacer(),
)
}