Skip to content

Commit

Permalink
Send UI notification on peer connection session expiry (netbirdio#1646)
Browse files Browse the repository at this point in the history
notify the user when the peer connection session expires after it switches from connected 
to disconnected and the status is login required
  • Loading branch information
bcmmbaga authored Mar 1, 2024
1 parent c12b583 commit 84dde63
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions client/ui/client_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {

flag.Parse()

a := app.New()
a := app.NewWithID("NetBird")
a.SetIcon(fyne.NewStaticResource("netbird", iconDisconnectedPNG))

client := newServiceClient(daemonAddr, a, showSettings)
Expand Down Expand Up @@ -130,9 +130,10 @@ type serviceClient struct {
mQuit *systray.MenuItem

// application with main windows.
app fyne.App
wSettings fyne.Window
showSettings bool
app fyne.App
wSettings fyne.Window
showSettings bool
sendNotification bool

// input elements for settings form
iMngURL *widget.Entry
Expand All @@ -158,9 +159,10 @@ type serviceClient struct {
// This constructor also builds the UI elements for the settings window.
func newServiceClient(addr string, a fyne.App, showSettings bool) *serviceClient {
s := &serviceClient{
ctx: context.Background(),
addr: addr,
app: a,
ctx: context.Background(),
addr: addr,
app: a,
sendNotification: false,

showSettings: showSettings,
update: version.NewUpdate(),
Expand Down Expand Up @@ -377,9 +379,15 @@ func (s *serviceClient) updateStatus() error {
s.updateIndicationLock.Lock()
defer s.updateIndicationLock.Unlock()

// notify the user when the session has expired
if status.Status == string(internal.StatusNeedsLogin) {
s.onSessionExpire()
}

var systrayIconState bool
if status.Status == string(internal.StatusConnected) && !s.mUp.Disabled() {
s.connected = true
s.sendNotification = true
if s.isUpdateIconActive {
systray.SetIcon(s.icUpdateConnected)
} else {
Expand Down Expand Up @@ -630,6 +638,23 @@ func (s *serviceClient) onUpdateAvailable() {
}
}

// onSessionExpire sends a notification to the user when the session expires.
func (s *serviceClient) onSessionExpire() {
if s.sendNotification {
title := "Connection session expired"
if runtime.GOOS == "darwin" {
title = "NetBird connection session expired"
}
s.app.SendNotification(
fyne.NewNotification(
title,
"Please re-authenticate to connect to the network",
),
)
s.sendNotification = false
}
}

func openURL(url string) error {
var err error
switch runtime.GOOS {
Expand Down

0 comments on commit 84dde63

Please sign in to comment.