stat bar
This commit is contained in:
BIN
assets/chart_bar.png
Normal file
BIN
assets/chart_bar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 541 B |
BIN
assets/disconnect.png
Normal file
BIN
assets/disconnect.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 796 B |
72
main.go
72
main.go
@@ -32,6 +32,9 @@ var loadedConfig lambdaConfig
|
|||||||
|
|
||||||
var empty_dialog *gtk.Image
|
var empty_dialog *gtk.Image
|
||||||
|
|
||||||
|
var connectionStatus *gtk.Label
|
||||||
|
var pingStatus *gtk.Label
|
||||||
|
|
||||||
// var msgs *gtk.ListBox
|
// var msgs *gtk.ListBox
|
||||||
var content *gtk.Widgetter
|
var content *gtk.Widgetter
|
||||||
|
|
||||||
@@ -114,6 +117,14 @@ var largeGroupB64 string = base64.StdEncoding.EncodeToString(largeGroupBytes)
|
|||||||
var worldBytes []byte
|
var worldBytes []byte
|
||||||
var worldB64 string = base64.StdEncoding.EncodeToString(worldBytes)
|
var worldB64 string = base64.StdEncoding.EncodeToString(worldBytes)
|
||||||
|
|
||||||
|
//go:embed assets/disconnect.png
|
||||||
|
var disconnectBytes []byte
|
||||||
|
var disconnectB64 string = base64.StdEncoding.EncodeToString(disconnectBytes)
|
||||||
|
|
||||||
|
//go:embed assets/chart_bar.png
|
||||||
|
var barBytes []byte
|
||||||
|
var barB64 string = base64.StdEncoding.EncodeToString(barBytes)
|
||||||
|
|
||||||
var clientAssets map[string]gdk.Paintabler = make(map[string]gdk.Paintabler)
|
var clientAssets map[string]gdk.Paintabler = make(map[string]gdk.Paintabler)
|
||||||
var lockedJIDs map[string]bool = make(map[string]bool)
|
var lockedJIDs map[string]bool = make(map[string]bool)
|
||||||
|
|
||||||
@@ -240,6 +251,22 @@ func init() {
|
|||||||
loader.Close()
|
loader.Close()
|
||||||
|
|
||||||
clientAssets["world"] = gdk.NewTextureForPixbuf(loader.Pixbuf())
|
clientAssets["world"] = gdk.NewTextureForPixbuf(loader.Pixbuf())
|
||||||
|
|
||||||
|
loader = gdkpixbuf.NewPixbufLoader()
|
||||||
|
|
||||||
|
disconnectData, _ := base64.StdEncoding.DecodeString(disconnectB64)
|
||||||
|
loader.Write(disconnectData)
|
||||||
|
loader.Close()
|
||||||
|
|
||||||
|
clientAssets["disconnect"] = gdk.NewTextureForPixbuf(loader.Pixbuf())
|
||||||
|
|
||||||
|
loader = gdkpixbuf.NewPixbufLoader()
|
||||||
|
|
||||||
|
barData, _ := base64.StdEncoding.DecodeString(barB64)
|
||||||
|
loader.Write(barData)
|
||||||
|
loader.Close()
|
||||||
|
|
||||||
|
clientAssets["chart_bar"] = gdk.NewTextureForPixbuf(loader.Pixbuf())
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -510,6 +537,28 @@ func main() {
|
|||||||
|
|
||||||
cm := xmpp.NewStreamManager(c, func(c xmpp.Sender) {
|
cm := xmpp.NewStreamManager(c, func(c xmpp.Sender) {
|
||||||
fmt.Println("XMPP client connected")
|
fmt.Println("XMPP client connected")
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
before := time.Now()
|
||||||
|
iq := new(stanza.IQ)
|
||||||
|
iq.From = clientroot.Session.BindJid
|
||||||
|
iq.To = iq.From
|
||||||
|
iq.Type = "get"
|
||||||
|
|
||||||
|
ctx, _ := context.WithTimeout(context.Background(), 30 * time.Second)
|
||||||
|
mychan, err := client.SendIQ(ctx, iq)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
_ = <- mychan
|
||||||
|
|
||||||
|
pingStatus.SetText(fmt.Sprintf("%d ms", time.Since(before) / time.Millisecond))
|
||||||
|
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
connectionStatus.SetText(fmt.Sprintf("Connected as %s", JidMustParse(clientroot.Session.BindJid).Bare()))
|
||||||
|
// Join rooms in bookmarks
|
||||||
books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0)
|
books, err := stanza.NewItemsRequest("", "urn:xmpp:bookmarks:1", 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mychan, err := c.SendIQ(context.TODO(), books)
|
mychan, err := c.SendIQ(context.TODO(), books)
|
||||||
@@ -518,6 +567,7 @@ func main() {
|
|||||||
res, ok := result.Payload.(*stanza.PubSubGeneric)
|
res, ok := result.Payload.(*stanza.PubSubGeneric)
|
||||||
if ok {
|
if ok {
|
||||||
for _, item := range res.Items.List {
|
for _, item := range res.Items.List {
|
||||||
|
go func() {
|
||||||
jid := item.Id
|
jid := item.Id
|
||||||
node := item.Any
|
node := item.Any
|
||||||
autojoin := false
|
autojoin := false
|
||||||
@@ -549,6 +599,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
menu.Append(b)
|
menu.Append(b)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,6 +608,7 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
connectionStatus.SetText("Connecting...")
|
||||||
err = cm.Run()
|
err = cm.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
showErrorDialog(err)
|
showErrorDialog(err)
|
||||||
@@ -706,6 +758,26 @@ func activate(app *gtk.Application) {
|
|||||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||||
box.Append(the_menuBar)
|
box.Append(the_menuBar)
|
||||||
|
|
||||||
|
statBar := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||||
|
|
||||||
|
cBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||||
|
cBox.Append(gtk.NewImageFromPaintable(clientAssets["disconnect"]))
|
||||||
|
connectionStatus = gtk.NewLabel("Disconnected")
|
||||||
|
cBox.Append(connectionStatus)
|
||||||
|
statBar.Append(cBox)
|
||||||
|
|
||||||
|
|
||||||
|
pBox := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||||
|
pBox.SetTooltipText("Ping between you and your XMPP server")
|
||||||
|
i := (gtk.NewImageFromPaintable(clientAssets["chart_bar"]))
|
||||||
|
i.AddCSSClass("icon")
|
||||||
|
pBox.Append(i)
|
||||||
|
pingStatus = gtk.NewLabel("...")
|
||||||
|
pBox.Append(pingStatus)
|
||||||
|
statBar.Append(pBox)
|
||||||
|
|
||||||
|
box.Append(statBar)
|
||||||
|
|
||||||
// scroller.SetChild(empty_dialog)
|
// scroller.SetChild(empty_dialog)
|
||||||
scroller.SetChild(empty_dialog)
|
scroller.SetChild(empty_dialog)
|
||||||
menu_scroll := gtk.NewScrolledWindow()
|
menu_scroll := gtk.NewScrolledWindow()
|
||||||
|
|||||||
Reference in New Issue
Block a user