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 |
130
main.go
130
main.go
@@ -32,6 +32,9 @@ var loadedConfig lambdaConfig
|
||||
|
||||
var empty_dialog *gtk.Image
|
||||
|
||||
var connectionStatus *gtk.Label
|
||||
var pingStatus *gtk.Label
|
||||
|
||||
// var msgs *gtk.ListBox
|
||||
var content *gtk.Widgetter
|
||||
|
||||
@@ -114,6 +117,14 @@ var largeGroupB64 string = base64.StdEncoding.EncodeToString(largeGroupBytes)
|
||||
var worldBytes []byte
|
||||
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 lockedJIDs map[string]bool = make(map[string]bool)
|
||||
|
||||
@@ -240,6 +251,22 @@ func init() {
|
||||
loader.Close()
|
||||
|
||||
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() {
|
||||
@@ -510,6 +537,28 @@ func main() {
|
||||
|
||||
cm := xmpp.NewStreamManager(c, func(c xmpp.Sender) {
|
||||
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)
|
||||
if err == nil {
|
||||
mychan, err := c.SendIQ(context.TODO(), books)
|
||||
@@ -518,37 +567,39 @@ func main() {
|
||||
res, ok := result.Payload.(*stanza.PubSubGeneric)
|
||||
if ok {
|
||||
for _, item := range res.Items.List {
|
||||
jid := item.Id
|
||||
node := item.Any
|
||||
autojoin := false
|
||||
nick := loadedConfig.Nick
|
||||
for _, attr := range node.Attrs {
|
||||
if attr.Name.Local == "autojoin" {
|
||||
autojoin = attr.Value == "true"
|
||||
}
|
||||
}
|
||||
|
||||
for _, node := range node.Nodes {
|
||||
if node.XMLName.Local == "nick" {
|
||||
nick = node.Content
|
||||
}
|
||||
}
|
||||
|
||||
_, ok := tabs.Load(jid)
|
||||
if !ok && autojoin {
|
||||
err := joinMuc(client, clientroot.Session.BindJid, jid, nick)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
go func() {
|
||||
jid := item.Id
|
||||
node := item.Any
|
||||
autojoin := false
|
||||
nick := loadedConfig.Nick
|
||||
for _, attr := range node.Attrs {
|
||||
if attr.Name.Local == "autojoin" {
|
||||
autojoin = attr.Value == "true"
|
||||
}
|
||||
}
|
||||
|
||||
createTab(jid, true)
|
||||
b := gtk.NewButtonWithLabel(jid)
|
||||
b.ConnectClicked(func() {
|
||||
b.AddCSSClass("accent")
|
||||
switchToTab(jid, &window.Window)
|
||||
})
|
||||
menu.Append(b)
|
||||
}
|
||||
for _, node := range node.Nodes {
|
||||
if node.XMLName.Local == "nick" {
|
||||
nick = node.Content
|
||||
}
|
||||
}
|
||||
|
||||
_, ok := tabs.Load(jid)
|
||||
if !ok && autojoin {
|
||||
err := joinMuc(client, clientroot.Session.BindJid, jid, nick)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
createTab(jid, true)
|
||||
b := gtk.NewButtonWithLabel(jid)
|
||||
b.ConnectClicked(func() {
|
||||
b.AddCSSClass("accent")
|
||||
switchToTab(jid, &window.Window)
|
||||
})
|
||||
menu.Append(b)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,6 +608,7 @@ func main() {
|
||||
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
connectionStatus.SetText("Connecting...")
|
||||
err = cm.Run()
|
||||
if err != nil {
|
||||
showErrorDialog(err)
|
||||
@@ -706,6 +758,26 @@ func activate(app *gtk.Application) {
|
||||
box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
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)
|
||||
menu_scroll := gtk.NewScrolledWindow()
|
||||
|
||||
Reference in New Issue
Block a user