mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 01:06:45 +00:00
Compare commits
2 Commits
fix/androi
...
fix/remove
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68996a1566 | ||
|
|
a03a6eb6f3 |
@@ -13,7 +13,6 @@ import (
|
|||||||
"fyne.io/systray"
|
"fyne.io/systray"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/proto"
|
|
||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -232,19 +231,3 @@ func (h *eventHandler) runSelfCommand(ctx context.Context, command, arg string)
|
|||||||
|
|
||||||
log.Printf("command '%s %s' completed successfully", command, arg)
|
log.Printf("command '%s %s' completed successfully", command, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *eventHandler) logout(ctx context.Context) error {
|
|
||||||
client, err := h.client.getSrvClient(defaultFailTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to get service client: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = client.Logout(ctx, &proto.LogoutRequest{})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("logout failed: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
h.client.getSrvConfig()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -40,13 +40,12 @@ func (s *serviceClient) showProfilesUI() {
|
|||||||
list := widget.NewList(
|
list := widget.NewList(
|
||||||
func() int { return len(profiles) },
|
func() int { return len(profiles) },
|
||||||
func() fyne.CanvasObject {
|
func() fyne.CanvasObject {
|
||||||
// Each item: Selected indicator, Name, spacer, Select, Logout & Remove buttons
|
// Each item: Selected indicator, Name, spacer, Select & Remove buttons
|
||||||
return container.NewHBox(
|
return container.NewHBox(
|
||||||
widget.NewLabel(""), // indicator
|
widget.NewLabel(""), // indicator
|
||||||
widget.NewLabel(""), // profile name
|
widget.NewLabel(""), // profile name
|
||||||
layout.NewSpacer(),
|
layout.NewSpacer(),
|
||||||
widget.NewButton("Select", nil),
|
widget.NewButton("Select", nil),
|
||||||
widget.NewButton("Deregister", nil),
|
|
||||||
widget.NewButton("Remove", nil),
|
widget.NewButton("Remove", nil),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -56,8 +55,7 @@ func (s *serviceClient) showProfilesUI() {
|
|||||||
indicator := row.Objects[0].(*widget.Label)
|
indicator := row.Objects[0].(*widget.Label)
|
||||||
nameLabel := row.Objects[1].(*widget.Label)
|
nameLabel := row.Objects[1].(*widget.Label)
|
||||||
selectBtn := row.Objects[3].(*widget.Button)
|
selectBtn := row.Objects[3].(*widget.Button)
|
||||||
logoutBtn := row.Objects[4].(*widget.Button)
|
removeBtn := row.Objects[4].(*widget.Button)
|
||||||
removeBtn := row.Objects[5].(*widget.Button)
|
|
||||||
|
|
||||||
profile := profiles[i]
|
profile := profiles[i]
|
||||||
// Show a checkmark if selected
|
// Show a checkmark if selected
|
||||||
@@ -127,12 +125,6 @@ func (s *serviceClient) showProfilesUI() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
logoutBtn.Show()
|
|
||||||
logoutBtn.SetText("Deregister")
|
|
||||||
logoutBtn.OnTapped = func() {
|
|
||||||
s.handleProfileLogout(profile.Name, refresh)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove profile
|
// Remove profile
|
||||||
removeBtn.SetText("Remove")
|
removeBtn.SetText("Remove")
|
||||||
removeBtn.OnTapped = func() {
|
removeBtn.OnTapped = func() {
|
||||||
@@ -332,52 +324,6 @@ func (s *serviceClient) getProfiles() ([]Profile, error) {
|
|||||||
return profiles, nil
|
return profiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *serviceClient) handleProfileLogout(profileName string, refreshCallback func()) {
|
|
||||||
dialog.ShowConfirm(
|
|
||||||
"Deregister",
|
|
||||||
fmt.Sprintf("Are you sure you want to deregister from '%s'?", profileName),
|
|
||||||
func(confirm bool) {
|
|
||||||
if !confirm {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to get service client: %v", err)
|
|
||||||
dialog.ShowError(fmt.Errorf("failed to connect to service"), s.wProfiles)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
currUser, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("failed to get current user: %v", err)
|
|
||||||
dialog.ShowError(fmt.Errorf("failed to get current user"), s.wProfiles)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
username := currUser.Username
|
|
||||||
_, err = conn.Logout(s.ctx, &proto.LogoutRequest{
|
|
||||||
ProfileName: &profileName,
|
|
||||||
Username: &username,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("logout failed: %v", err)
|
|
||||||
dialog.ShowError(fmt.Errorf("deregister failed"), s.wProfiles)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.ShowInformation(
|
|
||||||
"Deregistered",
|
|
||||||
fmt.Sprintf("Successfully deregistered from '%s'", profileName),
|
|
||||||
s.wProfiles,
|
|
||||||
)
|
|
||||||
|
|
||||||
refreshCallback()
|
|
||||||
},
|
|
||||||
s.wProfiles,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
type subItem struct {
|
type subItem struct {
|
||||||
*systray.MenuItem
|
*systray.MenuItem
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@@ -393,7 +339,6 @@ type profileMenu struct {
|
|||||||
emailMenuItem *systray.MenuItem
|
emailMenuItem *systray.MenuItem
|
||||||
profileSubItems []*subItem
|
profileSubItems []*subItem
|
||||||
manageProfilesSubItem *subItem
|
manageProfilesSubItem *subItem
|
||||||
logoutSubItem *subItem
|
|
||||||
profilesState []Profile
|
profilesState []Profile
|
||||||
downClickCallback func() error
|
downClickCallback func() error
|
||||||
upClickCallback func() error
|
upClickCallback func() error
|
||||||
@@ -600,30 +545,6 @@ func (p *profileMenu) refresh() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Add Logout menu item
|
|
||||||
ctx2, cancel2 := context.WithCancel(context.Background())
|
|
||||||
logoutItem := p.profileMenuItem.AddSubMenuItem("Deregister", "")
|
|
||||||
p.logoutSubItem = &subItem{logoutItem, ctx2, cancel2}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx2.Done():
|
|
||||||
return
|
|
||||||
case _, ok := <-logoutItem.ClickedCh:
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := p.eventHandler.logout(p.ctx); err != nil {
|
|
||||||
log.Errorf("logout failed: %v", err)
|
|
||||||
p.app.SendNotification(fyne.NewNotification("Error", "Failed to deregister"))
|
|
||||||
} else {
|
|
||||||
p.app.SendNotification(fyne.NewNotification("Success", "Deregistered successfully"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if activeProf.ProfileName == "default" || activeProf.Username == currUser.Username {
|
if activeProf.ProfileName == "default" || activeProf.Username == currUser.Username {
|
||||||
p.profileMenuItem.SetTitle(activeProf.ProfileName)
|
p.profileMenuItem.SetTitle(activeProf.ProfileName)
|
||||||
} else {
|
} else {
|
||||||
@@ -646,12 +567,6 @@ func (p *profileMenu) clear(profiles []Profile) {
|
|||||||
p.manageProfilesSubItem.cancel()
|
p.manageProfilesSubItem.cancel()
|
||||||
p.manageProfilesSubItem = nil
|
p.manageProfilesSubItem = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.logoutSubItem != nil {
|
|
||||||
p.logoutSubItem.Remove()
|
|
||||||
p.logoutSubItem.cancel()
|
|
||||||
p.logoutSubItem = nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *profileMenu) updateMenu() {
|
func (p *profileMenu) updateMenu() {
|
||||||
|
|||||||
Reference in New Issue
Block a user