added build tag for gui

This commit is contained in:
0xdcarns 2022-05-05 11:11:37 -04:00
parent 7a1b719a91
commit 81ab4f76bb
5 changed files with 36 additions and 22 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/gravitl/netmaker/netclient/config"
"github.com/gravitl/netmaker/netclient/daemon"
"github.com/gravitl/netmaker/netclient/functions"
"github.com/gravitl/netmaker/netclient/gui"
"github.com/gravitl/netmaker/netclient/ncutils"
"github.com/gravitl/netmaker/tls"
)
@ -143,12 +142,3 @@ func Daemon() error {
err := functions.Daemon()
return err
}
// Gui - runs the netclient gui
func Gui() error {
currNets, err := ncutils.GetSystemNetworks()
if err != nil {
return err
}
return gui.Run(currNets)
}

View file

@ -8,6 +8,13 @@ import (
"github.com/gravitl/netmaker/models"
)
var (
// GuiActive - indicates if gui is active or not
GuiActive = false
// GuiRun - holds function for main to call
GuiRun interface{}
)
// ParseAccessToken - used to parse the base64 encoded access token
func ParseAccessToken(token string) (*models.AccessToken, error) {
tokenbytes, err := base64.StdEncoding.DecodeString(token)

View file

@ -1,7 +1,11 @@
//go:build gui
// +build gui
package gui
import (
"embed"
"fmt"
"image/color"
"fyne.io/fyne/v2"
@ -10,6 +14,7 @@ import (
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/config"
"github.com/gravitl/netmaker/netclient/functions"
"github.com/gravitl/netmaker/netclient/gui/components"
"github.com/gravitl/netmaker/netclient/gui/components/views"
@ -19,6 +24,20 @@ import (
//go:embed nm-logo-sm.png
var logoContent embed.FS
func init() {
fmt.Println("got in here")
config.GuiActive = true
config.GuiRun = func() {
networks, err := ncutils.GetSystemNetworks()
if err != nil {
networks = []string{}
}
Run(networks)
}
}
// Run - run's the netclient GUI
func Run(networks []string) error {
a := app.New()
window := a.NewWindow("Netclient")
@ -69,9 +88,6 @@ func Run(networks []string) error {
})
views.RefreshComponent(views.Confirm, confirmView)
views.ShowView(views.Confirm)
// TODO:
// - call uninstall
// - Refresh networks view when finished
}, components.Red_color),
))

View file

@ -3,12 +3,13 @@
package main
import (
"fmt"
"log"
"os"
"runtime/debug"
"github.com/gravitl/netmaker/netclient/cli_options"
"github.com/gravitl/netmaker/netclient/gui"
"github.com/gravitl/netmaker/netclient/config"
"github.com/gravitl/netmaker/netclient/ncutils"
"github.com/gravitl/netmaker/netclient/ncwindows"
"github.com/urfave/cli/v2"
@ -36,12 +37,10 @@ func main() {
ncutils.CheckWG()
}
if len(os.Args) <= 1 {
networks, err := ncutils.GetSystemNetworks()
if err != nil {
networks = []string{}
}
gui.Run(networks)
fmt.Printf("%d \n %v \n", len(os.Args), config.GuiActive)
if len(os.Args) <= 1 && config.GuiActive {
config.GuiRun.(func())()
} else {
err := app.Run(os.Args)
if err != nil {

View file

@ -24,8 +24,10 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
// Version - version of the netclient
var Version = "dev"
var (
// Version - version of the netclient
Version = "dev"
)
// MAX_NAME_LENGTH - maximum node name length
const MAX_NAME_LENGTH = 62