mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-24 19:51:33 +02:00
feat: implement default profile and enhance profile management UI
This commit is contained in:
parent
7f899d5005
commit
b27ed5e0cf
@ -114,6 +114,8 @@ func (pm *ProfileManager) ListProfiles() ([]Profile, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var profiles []Profile
|
var profiles []Profile
|
||||||
|
// add default profile always
|
||||||
|
profiles = append(profiles, Profile{Name: "default", IsActive: activeProfName == "default"})
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
profileName := strings.TrimSuffix(filepath.Base(file), ".json")
|
profileName := strings.TrimSuffix(filepath.Base(file), ".json")
|
||||||
var isActive bool
|
var isActive bool
|
||||||
|
@ -221,11 +221,10 @@ type serviceClient struct {
|
|||||||
|
|
||||||
// systray menu items
|
// systray menu items
|
||||||
mStatus *systray.MenuItem
|
mStatus *systray.MenuItem
|
||||||
mProfileName *systray.MenuItem
|
|
||||||
mUp *systray.MenuItem
|
mUp *systray.MenuItem
|
||||||
mDown *systray.MenuItem
|
mDown *systray.MenuItem
|
||||||
mSettings *systray.MenuItem
|
mSettings *systray.MenuItem
|
||||||
mProfiles *systray.MenuItem
|
mProfile *profileMenu
|
||||||
mAbout *systray.MenuItem
|
mAbout *systray.MenuItem
|
||||||
mGitHub *systray.MenuItem
|
mGitHub *systray.MenuItem
|
||||||
mVersionUI *systray.MenuItem
|
mVersionUI *systray.MenuItem
|
||||||
@ -722,14 +721,12 @@ func (s *serviceClient) onTrayReady() {
|
|||||||
s.mStatus = systray.AddMenuItem("Disconnected", "Disconnected")
|
s.mStatus = systray.AddMenuItem("Disconnected", "Disconnected")
|
||||||
s.mStatus.SetIcon(s.icDisconnectedDot)
|
s.mStatus.SetIcon(s.icDisconnectedDot)
|
||||||
s.mStatus.Disable()
|
s.mStatus.Disable()
|
||||||
s.mProfileName = systray.AddMenuItem("hakan_work", "Selected Profile: Home")
|
|
||||||
systray.AddMenuItem("(hakan.@gmail.com)", "").Disable()
|
s.profileManager = profilemanager.NewProfileManager()
|
||||||
s.mProfiles = s.mProfileName
|
profileMenuItem := systray.AddMenuItem("", "")
|
||||||
s.mProfileName.AddSubMenuItem("hakan_work", "Selected Profile: Personal").Check()
|
emailMenuItem := systray.AddMenuItem("", "")
|
||||||
s.mProfileName.AddSubMenuItem("hakan_personal", "Selected Profile: Personal")
|
s.mProfile = newProfileMenu(s.profileManager, profileMenuItem, emailMenuItem)
|
||||||
s.mProfileName.AddSubMenuItem("common", "Selected Profile: Common")
|
|
||||||
s.mProfileName.AddSeparator()
|
|
||||||
s.mProfileName.AddSubMenuItem("Manage Profiles", "Selected Profile: Work")
|
|
||||||
systray.AddSeparator()
|
systray.AddSeparator()
|
||||||
s.mUp = systray.AddMenuItem("Connect", "Connect")
|
s.mUp = systray.AddMenuItem("Connect", "Connect")
|
||||||
s.mDown = systray.AddMenuItem("Disconnect", "Disconnect")
|
s.mDown = systray.AddMenuItem("Disconnect", "Disconnect")
|
||||||
|
@ -49,8 +49,6 @@ func (h *eventHandler) listen(ctx context.Context) {
|
|||||||
h.handleAdvancedSettingsClick()
|
h.handleAdvancedSettingsClick()
|
||||||
case <-h.client.mCreateDebugBundle.ClickedCh:
|
case <-h.client.mCreateDebugBundle.ClickedCh:
|
||||||
h.handleCreateDebugBundleClick()
|
h.handleCreateDebugBundleClick()
|
||||||
case <-h.client.mProfiles.ClickedCh:
|
|
||||||
h.handleProfilesClick()
|
|
||||||
case <-h.client.mQuit.ClickedCh:
|
case <-h.client.mQuit.ClickedCh:
|
||||||
h.handleQuitClick()
|
h.handleQuitClick()
|
||||||
return
|
return
|
||||||
@ -136,14 +134,6 @@ func (h *eventHandler) handleCreateDebugBundleClick() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *eventHandler) handleProfilesClick() {
|
|
||||||
h.client.mProfiles.Disable()
|
|
||||||
go func() {
|
|
||||||
defer h.client.mProfiles.Enable()
|
|
||||||
h.runSelfCommand("profiles", "true")
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *eventHandler) handleQuitClick() {
|
func (h *eventHandler) handleQuitClick() {
|
||||||
systray.Quit()
|
systray.Quit()
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,17 @@ import (
|
|||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"fyne.io/systray"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type profile struct {
|
||||||
|
name string
|
||||||
|
selected bool
|
||||||
|
}
|
||||||
|
|
||||||
// showProfilesUI creates and displays the Profiles window with a list of existing profiles,
|
// showProfilesUI creates and displays the Profiles window with a list of existing profiles,
|
||||||
// a button to add new profiles, allows removal, and lets the user switch the active profile.
|
// a button to add new profiles, allows removal, and lets the user switch the active profile.
|
||||||
func (s *serviceClient) showProfilesUI() {
|
func (s *serviceClient) showProfilesUI() {
|
||||||
@ -185,11 +191,6 @@ func (s *serviceClient) showProfilesUI() {
|
|||||||
s.wProfiles.Show()
|
s.wProfiles.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
type profile struct {
|
|
||||||
name string
|
|
||||||
selected bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// func (p *profileMenu) updateProfiles(ctx context.Context, conn proto.DaemonServiceClient) {
|
// func (p *profileMenu) updateProfiles(ctx context.Context, conn proto.DaemonServiceClient) {
|
||||||
// profiles, err := p.getProfiles(ctx, conn)
|
// profiles, err := p.getProfiles(ctx, conn)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
@ -243,3 +244,54 @@ func (s *serviceClient) getProfiles() ([]profilemanager.Profile, error) {
|
|||||||
}
|
}
|
||||||
return prof, nil
|
return prof, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type profileMenu struct {
|
||||||
|
profileManager *profilemanager.ProfileManager
|
||||||
|
profileMenuItem *systray.MenuItem
|
||||||
|
emailMenuItem *systray.MenuItem
|
||||||
|
profileItems []*systray.MenuItem
|
||||||
|
manageProfilesItem *systray.MenuItem
|
||||||
|
}
|
||||||
|
|
||||||
|
func newProfileMenu(profileManager *profilemanager.ProfileManager, profileMenuItem, emailMenuItem *systray.MenuItem) *profileMenu {
|
||||||
|
p := profileMenu{
|
||||||
|
profileManager: profileManager,
|
||||||
|
profileMenuItem: profileMenuItem,
|
||||||
|
emailMenuItem: emailMenuItem,
|
||||||
|
}
|
||||||
|
|
||||||
|
p.refresh()
|
||||||
|
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *profileMenu) refresh() {
|
||||||
|
profiles, err := p.profileManager.ListProfiles()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to list profiles: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear existing profile items
|
||||||
|
for _, item := range p.profileItems {
|
||||||
|
item.Remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.manageProfilesItem != nil {
|
||||||
|
// Remove the manage profiles item if it exists
|
||||||
|
p.manageProfilesItem.Remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, profile := range profiles {
|
||||||
|
item := p.profileMenuItem.AddSubMenuItem(profile.Name, "")
|
||||||
|
if profile.IsActive {
|
||||||
|
item.Check()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.profileItems = append(p.profileItems, item)
|
||||||
|
// TODO(hakan): handle switch profile
|
||||||
|
}
|
||||||
|
p.profileMenuItem.AddSeparator()
|
||||||
|
p.manageProfilesItem = p.profileMenuItem.AddSubMenuItem("Manage Profiles", "")
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user