mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-24 19:51:33 +02:00
refactor: remove unused profile-related messages and simplify profile switching logic
This commit is contained in:
parent
63a8ccc13a
commit
fee8051685
@ -126,6 +126,27 @@ func (pm *ProfileManager) ListProfiles() ([]Profile, error) {
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
// TODO(hakan): implement
|
||||
func (pm *ProfileManager) SwitchProfile(profileName string) error {
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
|
||||
// Check if the profile exists
|
||||
configDir, err := getConfigDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get config directory: %w", err)
|
||||
}
|
||||
|
||||
profPath := filepath.Join(configDir, profileName+".json")
|
||||
if !fileExists(profPath) {
|
||||
return ErrProfileNotFound
|
||||
}
|
||||
|
||||
// Set the active profile
|
||||
pm.activeProfile = &Profile{Name: profileName}
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanitazeUsername sanitizes the username by removing any invalid characters
|
||||
func sanitazeUsername(username string) string {
|
||||
// Remove invalid characters for a username in a file path
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -495,48 +495,3 @@ message GetEventsRequest {}
|
||||
message GetEventsResponse {
|
||||
repeated SystemEvent events = 1;
|
||||
}
|
||||
|
||||
|
||||
// Profiles
|
||||
message Profile {
|
||||
string name = 1;
|
||||
bool selected = 2;
|
||||
|
||||
}
|
||||
|
||||
message GetProfilesRequest {
|
||||
}
|
||||
|
||||
message GetProfilesResponse {
|
||||
repeated Profile profiles = 1;
|
||||
}
|
||||
|
||||
message CreateProfileRequest {
|
||||
string profile = 1;
|
||||
}
|
||||
|
||||
message CreateProfileResponse {
|
||||
bool success = 1;
|
||||
string error = 2;
|
||||
string profile = 3;
|
||||
}
|
||||
|
||||
message SwitchProfileRequest {
|
||||
string profile = 1;
|
||||
}
|
||||
|
||||
message SwitchProfileResponse {
|
||||
bool success = 1;
|
||||
string error = 2;
|
||||
string profile = 3;
|
||||
}
|
||||
|
||||
message RemoveProfileRequest {
|
||||
string profile = 1;
|
||||
}
|
||||
|
||||
message RemoveProfileResponse {
|
||||
bool success = 1;
|
||||
string error = 2;
|
||||
string profile = 3;
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@ -14,13 +12,11 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||
"github.com/netbirdio/netbird/client/proto"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func (s *serviceClient) showProfilesUI() {
|
||||
mProfiles := newProfileMenu()
|
||||
|
||||
profiles, err := s.getProfiles()
|
||||
if err != nil {
|
||||
@ -78,14 +74,8 @@ func (s *serviceClient) showProfilesUI() {
|
||||
if !confirm {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get client: %v", err)
|
||||
return
|
||||
}
|
||||
// switch
|
||||
err = mProfiles.switchProfile(s.ctx, conn, profile.Name)
|
||||
err = s.switchProfile(profile.Name)
|
||||
if err != nil {
|
||||
dialog.ShowError(fmt.Errorf("failed to select profile: %w", err), s.wProfiles)
|
||||
return
|
||||
@ -195,30 +185,11 @@ func (s *serviceClient) showProfilesUI() {
|
||||
s.wProfiles.Show()
|
||||
}
|
||||
|
||||
type profileMenu struct {
|
||||
mtx sync.Mutex
|
||||
profiles []*proto.Profile
|
||||
}
|
||||
|
||||
type profile struct {
|
||||
name string
|
||||
selected bool
|
||||
}
|
||||
|
||||
func newProfileMenu() *profileMenu {
|
||||
p := &profileMenu{
|
||||
profiles: make([]*proto.Profile, 0),
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *profileMenu) clearProfiles() {
|
||||
p.mtx.Lock()
|
||||
defer p.mtx.Unlock()
|
||||
|
||||
p.profiles = make([]*proto.Profile, 0)
|
||||
}
|
||||
|
||||
// func (p *profileMenu) updateProfiles(ctx context.Context, conn proto.DaemonServiceClient) {
|
||||
// profiles, err := p.getProfiles(ctx, conn)
|
||||
// if err != nil {
|
||||
@ -248,18 +219,11 @@ func (s *serviceClient) addProfile(profileName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *profileMenu) switchProfile(pCtx context.Context, conn proto.DaemonServiceClient, profileName string) error {
|
||||
ctx, cancel := context.WithTimeout(pCtx, defaultFailTimeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := conn.SwitchProfile(ctx, &proto.SwitchProfileRequest{Profile: profileName})
|
||||
func (s *serviceClient) switchProfile(profileName string) error {
|
||||
err := s.profileManager.SwitchProfile(profileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("switch profile: %v", err)
|
||||
return fmt.Errorf("switch profile: %w", err)
|
||||
}
|
||||
if !resp.Success {
|
||||
return fmt.Errorf("switch profile: %s", resp.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user