mirror of
https://github.com/UnnoTed/wireguird
synced 2025-02-05 09:25:29 +00:00
Update gui with wireguard state on every tick
By updating the gui on every tick, changes from `wg-quick` commands ran by the user outside of wireguird will be reflected in the wireguird interface.
This commit is contained in:
parent
b48fc7aa1b
commit
0b7aca734e
@ -833,10 +833,36 @@ func (t *Tunnels) Create() error {
|
||||
for {
|
||||
<-t.ticker.C
|
||||
|
||||
if !window.HasToplevelFocus() {
|
||||
// update tray icon
|
||||
activeNames := t.ActiveDeviceName()
|
||||
if len(activeNames) == 0 {
|
||||
indicator.SetIcon("wireguard_off")
|
||||
} else {
|
||||
indicator.SetIcon("wg_connected")
|
||||
}
|
||||
|
||||
if !window.IsVisible() {
|
||||
continue
|
||||
}
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
// update list icons
|
||||
for name := range t.icons {
|
||||
if dry.StringListContains(activeNames, name) {
|
||||
t.icons[name].SetFromPixbuf(t.greenIcon.GetPixbuf())
|
||||
} else {
|
||||
t.icons[name].SetFromPixbuf(t.grayIcon.GetPixbuf())
|
||||
}
|
||||
}
|
||||
|
||||
// update header label with tunnel names
|
||||
if len(activeNames) == 0 {
|
||||
header.SetSubtitle("Not connected!")
|
||||
} else {
|
||||
header.SetSubtitle("Connected to " + strings.Join(activeNames, ", "))
|
||||
}
|
||||
})
|
||||
|
||||
row := tl.GetSelectedRow()
|
||||
if row == nil {
|
||||
t.UnknownLabels()
|
||||
@ -849,7 +875,15 @@ func (t *Tunnels) Create() error {
|
||||
continue
|
||||
}
|
||||
|
||||
if !dry.StringListContains(t.ActiveDeviceName(), name) {
|
||||
if !dry.StringListContains(activeNames, name) {
|
||||
glib.IdleAdd(func() {
|
||||
t.Interface.Status.SetText("Inactive")
|
||||
t.Interface.PublicKey.SetText("unknown")
|
||||
t.Interface.ListenPort.SetText("unknown")
|
||||
t.ButtonChangeState.SetLabel("Activate")
|
||||
t.Peer.LatestHandshake.SetText("unknown")
|
||||
t.Peer.Transfer.SetText("unknown")
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
@ -859,16 +893,18 @@ func (t *Tunnels) Create() error {
|
||||
continue
|
||||
}
|
||||
|
||||
glib.IdleAdd(func() {
|
||||
t.Interface.Status.SetText("Active")
|
||||
t.Interface.PublicKey.SetText(d.PublicKey.String())
|
||||
t.Interface.ListenPort.SetText(strconv.Itoa(d.ListenPort))
|
||||
t.ButtonChangeState.SetLabel("Deactivate")
|
||||
|
||||
for _, p := range d.Peers {
|
||||
hs := humanize.Time(p.LastHandshakeTime)
|
||||
glib.IdleAdd(func() {
|
||||
t.Peer.LatestHandshake.SetText(hs)
|
||||
t.Peer.Transfer.SetText(humanize.Bytes(uint64(p.ReceiveBytes)) + " received, " + humanize.Bytes(uint64(p.TransmitBytes)) + " sent")
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user