From 60ffe0dc872b23595cdd0f6f69f3fa56ed56cf2f Mon Sep 17 00:00:00 2001
From: hakansa <43675540+hakansa@users.noreply.github.com>
Date: Tue, 4 Mar 2025 18:29:29 +0300
Subject: [PATCH] [client] UI Refactor Icon Paths (#3420)
[client] UI Refactor Icon Paths (#3420)
---
.github/workflows/release.yml | 4 +-
.goreleaser_ui.yaml | 8 +-
client/installer.nsis | 4 +-
client/netbird.wxs | 2 +-
client/resources.rc | 2 +-
.../netbird-systemtray-connected-dark.ico | Bin
.../netbird-systemtray-connected-dark.png | Bin
.../netbird-systemtray-connected-macos.png | Bin
.../netbird-systemtray-connected.ico | Bin
.../netbird-systemtray-connected.png | Bin
.../netbird-systemtray-connecting-dark.ico | Bin
.../netbird-systemtray-connecting-dark.png | Bin
.../netbird-systemtray-connecting-macos.png | Bin
.../netbird-systemtray-connecting.ico | Bin
.../netbird-systemtray-connecting.png | Bin
.../netbird-systemtray-disconnected-macos.png | Bin
.../netbird-systemtray-disconnected.ico | Bin
.../netbird-systemtray-disconnected.png | Bin
.../netbird-systemtray-error-dark.ico | Bin
.../netbird-systemtray-error-dark.png | Bin
.../netbird-systemtray-error-macos.png | Bin
.../{ => assets}/netbird-systemtray-error.ico | Bin
.../{ => assets}/netbird-systemtray-error.png | Bin
...tbird-systemtray-update-connected-dark.ico | Bin
...tbird-systemtray-update-connected-dark.png | Bin
...bird-systemtray-update-connected-macos.png | Bin
.../netbird-systemtray-update-connected.ico | Bin
.../netbird-systemtray-update-connected.png | Bin
...rd-systemtray-update-disconnected-dark.ico | Bin
...rd-systemtray-update-disconnected-dark.png | Bin
...d-systemtray-update-disconnected-macos.png | Bin
...netbird-systemtray-update-disconnected.ico | Bin
...netbird-systemtray-update-disconnected.png | Bin
client/ui/{ => assets}/netbird.ico | Bin
client/ui/{ => assets}/netbird.png | Bin
client/ui/{ => build}/banner.bmp | Bin
client/ui/{ => build}/build-ui-linux.sh | 0
client/ui/{ => build}/netbird.desktop | 0
client/ui/client_ui.go | 189 ++++++++++--------
client/ui/const.go | 15 ++
client/ui/icons.go | 24 +--
client/ui/icons_windows.go | 26 +--
client/ui/network.go | 2 +-
client/ui/{ => process}/process.go | 4 +-
client/ui/{ => process}/process_nonwindows.go | 2 +-
client/ui/{ => process}/process_windows.go | 2 +-
46 files changed, 160 insertions(+), 124 deletions(-)
rename client/ui/{ => assets}/netbird-systemtray-connected-dark.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-connected-dark.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-connected-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-connected.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-connected.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-connecting-dark.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-connecting-dark.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-connecting-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-connecting.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-connecting.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-disconnected-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-disconnected.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-disconnected.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-error-dark.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-error-dark.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-error-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-error.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-error.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-connected-dark.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-connected-dark.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-connected-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-connected.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-connected.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-disconnected-dark.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-disconnected-dark.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-disconnected-macos.png (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-disconnected.ico (100%)
rename client/ui/{ => assets}/netbird-systemtray-update-disconnected.png (100%)
rename client/ui/{ => assets}/netbird.ico (100%)
rename client/ui/{ => assets}/netbird.png (100%)
rename client/ui/{ => build}/banner.bmp (100%)
rename client/ui/{ => build}/build-ui-linux.sh (100%)
rename client/ui/{ => build}/netbird.desktop (100%)
create mode 100644 client/ui/const.go
rename client/ui/{ => process}/process.go (90%)
rename client/ui/{ => process}/process_nonwindows.go (96%)
rename client/ui/{ => process}/process_windows.go (96%)
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 04874bdf4..919351f18 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -71,7 +71,7 @@ jobs:
- name: Install goversioninfo
run: go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@233067e
- name: Generate windows syso amd64
- run: goversioninfo -icon client/ui/netbird.ico -manifest client/manifest.xml -product-name ${{ env.PRODUCT_NAME }} -copyright "${{ env.COPYRIGHT }}" -ver-major ${{ steps.semver_parser.outputs.major }} -ver-minor ${{ steps.semver_parser.outputs.minor }} -ver-patch ${{ steps.semver_parser.outputs.patch }} -ver-build 0 -file-version ${{ steps.semver_parser.outputs.fullversion }}.0 -product-version ${{ steps.semver_parser.outputs.fullversion }}.0 -o client/resources_windows_amd64.syso
+ run: goversioninfo -icon client/ui/assets/netbird.ico -manifest client/manifest.xml -product-name ${{ env.PRODUCT_NAME }} -copyright "${{ env.COPYRIGHT }}" -ver-major ${{ steps.semver_parser.outputs.major }} -ver-minor ${{ steps.semver_parser.outputs.minor }} -ver-patch ${{ steps.semver_parser.outputs.patch }} -ver-build 0 -file-version ${{ steps.semver_parser.outputs.fullversion }}.0 -product-version ${{ steps.semver_parser.outputs.fullversion }}.0 -o client/resources_windows_amd64.syso
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
@@ -150,7 +150,7 @@ jobs:
- name: Install goversioninfo
run: go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@233067e
- name: Generate windows syso amd64
- run: goversioninfo -64 -icon client/ui/netbird.ico -manifest client/ui/manifest.xml -product-name ${{ env.PRODUCT_NAME }}-"UI" -copyright "${{ env.COPYRIGHT }}" -ver-major ${{ steps.semver_parser.outputs.major }} -ver-minor ${{ steps.semver_parser.outputs.minor }} -ver-patch ${{ steps.semver_parser.outputs.patch }} -ver-build 0 -file-version ${{ steps.semver_parser.outputs.fullversion }}.0 -product-version ${{ steps.semver_parser.outputs.fullversion }}.0 -o client/ui/resources_windows_amd64.syso
+ run: goversioninfo -64 -icon client/ui/assets/netbird.ico -manifest client/ui/manifest.xml -product-name ${{ env.PRODUCT_NAME }}-"UI" -copyright "${{ env.COPYRIGHT }}" -ver-major ${{ steps.semver_parser.outputs.major }} -ver-minor ${{ steps.semver_parser.outputs.minor }} -ver-patch ${{ steps.semver_parser.outputs.patch }} -ver-build 0 -file-version ${{ steps.semver_parser.outputs.fullversion }}.0 -product-version ${{ steps.semver_parser.outputs.fullversion }}.0 -o client/ui/resources_windows_amd64.syso
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
diff --git a/.goreleaser_ui.yaml b/.goreleaser_ui.yaml
index 1dd649d1b..459f204d3 100644
--- a/.goreleaser_ui.yaml
+++ b/.goreleaser_ui.yaml
@@ -53,9 +53,9 @@ nfpms:
scripts:
postinstall: "release_files/ui-post-install.sh"
contents:
- - src: client/ui/netbird.desktop
+ - src: client/ui/build/netbird.desktop
dst: /usr/share/applications/netbird.desktop
- - src: client/ui/netbird.png
+ - src: client/ui/assets/netbird.png
dst: /usr/share/pixmaps/netbird.png
dependencies:
- netbird
@@ -72,9 +72,9 @@ nfpms:
scripts:
postinstall: "release_files/ui-post-install.sh"
contents:
- - src: client/ui/netbird.desktop
+ - src: client/ui/build/netbird.desktop
dst: /usr/share/applications/netbird.desktop
- - src: client/ui/netbird.png
+ - src: client/ui/assets/netbird.png
dst: /usr/share/pixmaps/netbird.png
dependencies:
- netbird
diff --git a/client/installer.nsis b/client/installer.nsis
index af942a868..743c81a6d 100644
--- a/client/installer.nsis
+++ b/client/installer.nsis
@@ -6,8 +6,8 @@
!define DESCRIPTION "A WireGuard®-based mesh network that connects your devices into a single private network"
!define INSTALLER_NAME "netbird-installer.exe"
!define MAIN_APP_EXE "Netbird"
-!define ICON "ui\\netbird.ico"
-!define BANNER "ui\\banner.bmp"
+!define ICON "ui\\assets\\netbird.ico"
+!define BANNER "ui\\build\\banner.bmp"
!define LICENSE_DATA "..\\LICENSE"
!define INSTALL_DIR "$PROGRAMFILES64\${APP_NAME}"
diff --git a/client/netbird.wxs b/client/netbird.wxs
index ee9ab667f..5e03a014d 100644
--- a/client/netbird.wxs
+++ b/client/netbird.wxs
@@ -71,7 +71,7 @@
-
+
diff --git a/client/resources.rc b/client/resources.rc
index ac411245e..696fd0dfa 100644
--- a/client/resources.rc
+++ b/client/resources.rc
@@ -5,5 +5,5 @@
#define STRINGIZE(x) #x
#define EXPAND(x) STRINGIZE(x)
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST manifest.xml
-7 ICON ui/netbird.ico
+7 ICON ui/assets/netbird.ico
wintun.dll RCDATA wintun.dll
diff --git a/client/ui/netbird-systemtray-connected-dark.ico b/client/ui/assets/netbird-systemtray-connected-dark.ico
similarity index 100%
rename from client/ui/netbird-systemtray-connected-dark.ico
rename to client/ui/assets/netbird-systemtray-connected-dark.ico
diff --git a/client/ui/netbird-systemtray-connected-dark.png b/client/ui/assets/netbird-systemtray-connected-dark.png
similarity index 100%
rename from client/ui/netbird-systemtray-connected-dark.png
rename to client/ui/assets/netbird-systemtray-connected-dark.png
diff --git a/client/ui/netbird-systemtray-connected-macos.png b/client/ui/assets/netbird-systemtray-connected-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-connected-macos.png
rename to client/ui/assets/netbird-systemtray-connected-macos.png
diff --git a/client/ui/netbird-systemtray-connected.ico b/client/ui/assets/netbird-systemtray-connected.ico
similarity index 100%
rename from client/ui/netbird-systemtray-connected.ico
rename to client/ui/assets/netbird-systemtray-connected.ico
diff --git a/client/ui/netbird-systemtray-connected.png b/client/ui/assets/netbird-systemtray-connected.png
similarity index 100%
rename from client/ui/netbird-systemtray-connected.png
rename to client/ui/assets/netbird-systemtray-connected.png
diff --git a/client/ui/netbird-systemtray-connecting-dark.ico b/client/ui/assets/netbird-systemtray-connecting-dark.ico
similarity index 100%
rename from client/ui/netbird-systemtray-connecting-dark.ico
rename to client/ui/assets/netbird-systemtray-connecting-dark.ico
diff --git a/client/ui/netbird-systemtray-connecting-dark.png b/client/ui/assets/netbird-systemtray-connecting-dark.png
similarity index 100%
rename from client/ui/netbird-systemtray-connecting-dark.png
rename to client/ui/assets/netbird-systemtray-connecting-dark.png
diff --git a/client/ui/netbird-systemtray-connecting-macos.png b/client/ui/assets/netbird-systemtray-connecting-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-connecting-macos.png
rename to client/ui/assets/netbird-systemtray-connecting-macos.png
diff --git a/client/ui/netbird-systemtray-connecting.ico b/client/ui/assets/netbird-systemtray-connecting.ico
similarity index 100%
rename from client/ui/netbird-systemtray-connecting.ico
rename to client/ui/assets/netbird-systemtray-connecting.ico
diff --git a/client/ui/netbird-systemtray-connecting.png b/client/ui/assets/netbird-systemtray-connecting.png
similarity index 100%
rename from client/ui/netbird-systemtray-connecting.png
rename to client/ui/assets/netbird-systemtray-connecting.png
diff --git a/client/ui/netbird-systemtray-disconnected-macos.png b/client/ui/assets/netbird-systemtray-disconnected-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-disconnected-macos.png
rename to client/ui/assets/netbird-systemtray-disconnected-macos.png
diff --git a/client/ui/netbird-systemtray-disconnected.ico b/client/ui/assets/netbird-systemtray-disconnected.ico
similarity index 100%
rename from client/ui/netbird-systemtray-disconnected.ico
rename to client/ui/assets/netbird-systemtray-disconnected.ico
diff --git a/client/ui/netbird-systemtray-disconnected.png b/client/ui/assets/netbird-systemtray-disconnected.png
similarity index 100%
rename from client/ui/netbird-systemtray-disconnected.png
rename to client/ui/assets/netbird-systemtray-disconnected.png
diff --git a/client/ui/netbird-systemtray-error-dark.ico b/client/ui/assets/netbird-systemtray-error-dark.ico
similarity index 100%
rename from client/ui/netbird-systemtray-error-dark.ico
rename to client/ui/assets/netbird-systemtray-error-dark.ico
diff --git a/client/ui/netbird-systemtray-error-dark.png b/client/ui/assets/netbird-systemtray-error-dark.png
similarity index 100%
rename from client/ui/netbird-systemtray-error-dark.png
rename to client/ui/assets/netbird-systemtray-error-dark.png
diff --git a/client/ui/netbird-systemtray-error-macos.png b/client/ui/assets/netbird-systemtray-error-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-error-macos.png
rename to client/ui/assets/netbird-systemtray-error-macos.png
diff --git a/client/ui/netbird-systemtray-error.ico b/client/ui/assets/netbird-systemtray-error.ico
similarity index 100%
rename from client/ui/netbird-systemtray-error.ico
rename to client/ui/assets/netbird-systemtray-error.ico
diff --git a/client/ui/netbird-systemtray-error.png b/client/ui/assets/netbird-systemtray-error.png
similarity index 100%
rename from client/ui/netbird-systemtray-error.png
rename to client/ui/assets/netbird-systemtray-error.png
diff --git a/client/ui/netbird-systemtray-update-connected-dark.ico b/client/ui/assets/netbird-systemtray-update-connected-dark.ico
similarity index 100%
rename from client/ui/netbird-systemtray-update-connected-dark.ico
rename to client/ui/assets/netbird-systemtray-update-connected-dark.ico
diff --git a/client/ui/netbird-systemtray-update-connected-dark.png b/client/ui/assets/netbird-systemtray-update-connected-dark.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-connected-dark.png
rename to client/ui/assets/netbird-systemtray-update-connected-dark.png
diff --git a/client/ui/netbird-systemtray-update-connected-macos.png b/client/ui/assets/netbird-systemtray-update-connected-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-connected-macos.png
rename to client/ui/assets/netbird-systemtray-update-connected-macos.png
diff --git a/client/ui/netbird-systemtray-update-connected.ico b/client/ui/assets/netbird-systemtray-update-connected.ico
similarity index 100%
rename from client/ui/netbird-systemtray-update-connected.ico
rename to client/ui/assets/netbird-systemtray-update-connected.ico
diff --git a/client/ui/netbird-systemtray-update-connected.png b/client/ui/assets/netbird-systemtray-update-connected.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-connected.png
rename to client/ui/assets/netbird-systemtray-update-connected.png
diff --git a/client/ui/netbird-systemtray-update-disconnected-dark.ico b/client/ui/assets/netbird-systemtray-update-disconnected-dark.ico
similarity index 100%
rename from client/ui/netbird-systemtray-update-disconnected-dark.ico
rename to client/ui/assets/netbird-systemtray-update-disconnected-dark.ico
diff --git a/client/ui/netbird-systemtray-update-disconnected-dark.png b/client/ui/assets/netbird-systemtray-update-disconnected-dark.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-disconnected-dark.png
rename to client/ui/assets/netbird-systemtray-update-disconnected-dark.png
diff --git a/client/ui/netbird-systemtray-update-disconnected-macos.png b/client/ui/assets/netbird-systemtray-update-disconnected-macos.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-disconnected-macos.png
rename to client/ui/assets/netbird-systemtray-update-disconnected-macos.png
diff --git a/client/ui/netbird-systemtray-update-disconnected.ico b/client/ui/assets/netbird-systemtray-update-disconnected.ico
similarity index 100%
rename from client/ui/netbird-systemtray-update-disconnected.ico
rename to client/ui/assets/netbird-systemtray-update-disconnected.ico
diff --git a/client/ui/netbird-systemtray-update-disconnected.png b/client/ui/assets/netbird-systemtray-update-disconnected.png
similarity index 100%
rename from client/ui/netbird-systemtray-update-disconnected.png
rename to client/ui/assets/netbird-systemtray-update-disconnected.png
diff --git a/client/ui/netbird.ico b/client/ui/assets/netbird.ico
similarity index 100%
rename from client/ui/netbird.ico
rename to client/ui/assets/netbird.ico
diff --git a/client/ui/netbird.png b/client/ui/assets/netbird.png
similarity index 100%
rename from client/ui/netbird.png
rename to client/ui/assets/netbird.png
diff --git a/client/ui/banner.bmp b/client/ui/build/banner.bmp
similarity index 100%
rename from client/ui/banner.bmp
rename to client/ui/build/banner.bmp
diff --git a/client/ui/build-ui-linux.sh b/client/ui/build/build-ui-linux.sh
similarity index 100%
rename from client/ui/build-ui-linux.sh
rename to client/ui/build/build-ui-linux.sh
diff --git a/client/ui/netbird.desktop b/client/ui/build/netbird.desktop
similarity index 100%
rename from client/ui/netbird.desktop
rename to client/ui/build/netbird.desktop
diff --git a/client/ui/client_ui.go b/client/ui/client_ui.go
index 889db70d6..914d4f3b9 100644
--- a/client/ui/client_ui.go
+++ b/client/ui/client_ui.go
@@ -35,7 +35,9 @@ import (
"github.com/netbirdio/netbird/client/proto"
"github.com/netbirdio/netbird/client/ui/desktop"
"github.com/netbirdio/netbird/client/ui/event"
+ "github.com/netbirdio/netbird/client/ui/process"
"github.com/netbirdio/netbird/util"
+
"github.com/netbirdio/netbird/version"
)
@@ -44,94 +46,125 @@ const (
failFastTimeout = time.Second
)
+const (
+ censoredPreSharedKey = "**********"
+)
+
func main() {
- var daemonAddr string
-
- defaultDaemonAddr := "unix:///var/run/netbird.sock"
- if runtime.GOOS == "windows" {
- defaultDaemonAddr = "tcp://127.0.0.1:41731"
- }
-
- flag.StringVar(
- &daemonAddr, "daemon-addr",
- defaultDaemonAddr,
- "Daemon service address to serve CLI requests [unix|tcp]://[path|host:port]")
-
- var showSettings bool
- flag.BoolVar(&showSettings, "settings", false, "run settings windows")
- var showRoutes bool
- flag.BoolVar(&showRoutes, "networks", false, "run networks windows")
- var errorMSG string
- flag.StringVar(&errorMSG, "error-msg", "", "displays a error message window")
-
- tmpDir := "/tmp"
- if runtime.GOOS == "windows" {
- tmpDir = os.TempDir()
- }
-
- var saveLogsInFile bool
- flag.BoolVar(&saveLogsInFile, "use-log-file", false, fmt.Sprintf("save logs in a file: %s/netbird-ui-PID.log", tmpDir))
-
- flag.Parse()
+ daemonAddr, showSettings, showNetworks, errorMsg, saveLogsInFile := parseFlags()
+ // Initialize file logging if needed.
if saveLogsInFile {
- logFile := path.Join(tmpDir, fmt.Sprintf("netbird-ui-%d.log", os.Getpid()))
- err := util.InitLog("trace", logFile)
- if err != nil {
+ if err := initLogFile(); err != nil {
log.Errorf("error while initializing log: %v", err)
return
}
}
+ // Create the Fyne application.
a := app.NewWithID("NetBird")
a.SetIcon(fyne.NewStaticResource("netbird", iconDisconnected))
- if errorMSG != "" {
- showErrorMSG(errorMSG)
+ // Show error message window if needed.
+ if errorMsg != "" {
+ showErrorMessage(errorMsg)
return
}
- client := newServiceClient(daemonAddr, a, showSettings, showRoutes)
+ // Create the service client (this also builds the settings or networks UI if requested).
+ client := newServiceClient(daemonAddr, a, showSettings, showNetworks)
+
+ // Watch for theme/settings changes to update the icon.
+ go watchSettingsChanges(a, client)
+
+ // Run in window mode if any UI flag was set.
+ if showSettings || showNetworks {
+ a.Run()
+ return
+ }
+
+ // Check for another running process.
+ running, err := process.IsAnotherProcessRunning()
+ if err != nil {
+ log.Errorf("error while checking process: %v", err)
+ return
+ }
+ if running {
+ log.Warn("another process is running")
+ return
+ }
+
+ client.setDefaultFonts()
+ systray.Run(client.onTrayReady, client.onTrayExit)
+}
+
+// parseFlags reads and returns all needed command-line flags.
+func parseFlags() (daemonAddr string, showSettings, showNetworks bool, errorMsg string, saveLogsInFile bool) {
+ defaultDaemonAddr := "unix:///var/run/netbird.sock"
+ if runtime.GOOS == "windows" {
+ defaultDaemonAddr = "tcp://127.0.0.1:41731"
+ }
+ flag.StringVar(&daemonAddr, "daemon-addr", defaultDaemonAddr, "Daemon service address to serve CLI requests [unix|tcp]://[path|host:port]")
+ flag.BoolVar(&showSettings, "settings", false, "run settings window")
+ flag.BoolVar(&showNetworks, "networks", false, "run networks window")
+ flag.StringVar(&errorMsg, "error-msg", "", "displays an error message window")
+
+ tmpDir := "/tmp"
+ if runtime.GOOS == "windows" {
+ tmpDir = os.TempDir()
+ }
+ flag.BoolVar(&saveLogsInFile, "use-log-file", false, fmt.Sprintf("save logs in a file: %s/netbird-ui-PID.log", tmpDir))
+ flag.Parse()
+ return
+}
+
+// initLogFile initializes logging into a file.
+func initLogFile() error {
+ tmpDir := "/tmp"
+ if runtime.GOOS == "windows" {
+ tmpDir = os.TempDir()
+ }
+ logFile := path.Join(tmpDir, fmt.Sprintf("netbird-ui-%d.log", os.Getpid()))
+ return util.InitLog("trace", logFile)
+}
+
+// watchSettingsChanges listens for Fyne theme/settings changes and updates the client icon.
+func watchSettingsChanges(a fyne.App, client *serviceClient) {
settingsChangeChan := make(chan fyne.Settings)
a.Settings().AddChangeListener(settingsChangeChan)
- go func() {
- for range settingsChangeChan {
- client.updateIcon()
- }
- }()
-
- if showSettings || showRoutes {
- a.Run()
- } else {
- running, err := isAnotherProcessRunning()
- if err != nil {
- log.Errorf("error while checking process: %v", err)
- }
- if running {
- log.Warn("another process is running")
- return
- }
- client.setDefaultFonts()
- systray.Run(client.onTrayReady, client.onTrayExit)
+ for range settingsChangeChan {
+ client.updateIcon()
}
}
-//go:embed netbird-systemtray-connected-macos.png
+// showErrorMessage displays an error message in a simple window.
+func showErrorMessage(msg string) {
+ a := app.New()
+ w := a.NewWindow("NetBird Error")
+ label := widget.NewLabel(msg)
+ label.Wrapping = fyne.TextWrapWord
+ w.SetContent(label)
+ w.Resize(fyne.NewSize(400, 100))
+ w.Show()
+ a.Run()
+}
+
+//go:embed assets/netbird-systemtray-connected-macos.png
var iconConnectedMacOS []byte
-//go:embed netbird-systemtray-disconnected-macos.png
+//go:embed assets/netbird-systemtray-disconnected-macos.png
var iconDisconnectedMacOS []byte
-//go:embed netbird-systemtray-update-disconnected-macos.png
+//go:embed assets/netbird-systemtray-update-disconnected-macos.png
var iconUpdateDisconnectedMacOS []byte
-//go:embed netbird-systemtray-update-connected-macos.png
+//go:embed assets/netbird-systemtray-update-connected-macos.png
var iconUpdateConnectedMacOS []byte
-//go:embed netbird-systemtray-connecting-macos.png
+//go:embed assets/netbird-systemtray-connecting-macos.png
var iconConnectingMacOS []byte
-//go:embed netbird-systemtray-error-macos.png
+//go:embed assets/netbird-systemtray-error-macos.png
var iconErrorMacOS []byte
type serviceClient struct {
@@ -301,18 +334,6 @@ func (s *serviceClient) showSettingsUI() {
s.wSettings.Show()
}
-// showErrorMSG opens a fyne app window to display the supplied message
-func showErrorMSG(msg string) {
- app := app.New()
- w := app.NewWindow("NetBird Error")
- content := widget.NewLabel(msg)
- content.Wrapping = fyne.TextWrapWord
- w.SetContent(content)
- w.Resize(fyne.NewSize(400, 100))
- w.Show()
- app.Run()
-}
-
// getSettingsForm to embed it into settings window.
func (s *serviceClient) getSettingsForm() *widget.Form {
return &widget.Form{
@@ -328,7 +349,7 @@ func (s *serviceClient) getSettingsForm() *widget.Form {
},
SubmitText: "Save",
OnSubmit: func() {
- if s.iPreSharedKey.Text != "" && s.iPreSharedKey.Text != "**********" {
+ if s.iPreSharedKey.Text != "" && s.iPreSharedKey.Text != censoredPreSharedKey {
// validate preSharedKey if it added
if _, err := wgtypes.ParseKey(s.iPreSharedKey.Text); err != nil {
dialog.ShowError(fmt.Errorf("Invalid Pre-shared Key Value"), s.wSettings)
@@ -366,7 +387,7 @@ func (s *serviceClient) getSettingsForm() *widget.Form {
WireguardPort: &port,
}
- if s.iPreSharedKey.Text != "**********" {
+ if s.iPreSharedKey.Text != censoredPreSharedKey {
loginRequest.OptionalPreSharedKey = &s.iPreSharedKey.Text
}
@@ -588,21 +609,21 @@ func (s *serviceClient) onTrayReady() {
s.mAdminPanel = systray.AddMenuItem("Admin Panel", "Netbird Admin Panel")
systray.AddSeparator()
- s.mSettings = systray.AddMenuItem("Settings", "Settings of the application")
- s.mAllowSSH = s.mSettings.AddSubMenuItemCheckbox("Allow SSH", "Allow SSH connections", false)
- s.mAutoConnect = s.mSettings.AddSubMenuItemCheckbox("Connect on Startup", "Connect automatically when the service starts", false)
- s.mEnableRosenpass = s.mSettings.AddSubMenuItemCheckbox("Enable Quantum-Resistance", "Enable post-quantum security via Rosenpass", false)
- s.mNotifications = s.mSettings.AddSubMenuItemCheckbox("Notifications", "Enable notifications", false)
- s.mAdvancedSettings = s.mSettings.AddSubMenuItem("Advanced Settings", "Advanced settings of the application")
- s.mCreateDebugBundle = s.mSettings.AddSubMenuItem("Create Debug Bundle", "Create and open debug information bundle")
+ s.mSettings = systray.AddMenuItem("Settings", settingsMenuDescr)
+ s.mAllowSSH = s.mSettings.AddSubMenuItemCheckbox("Allow SSH", allowSSHMenuDescr, false)
+ s.mAutoConnect = s.mSettings.AddSubMenuItemCheckbox("Connect on Startup", autoConnectMenuDescr, false)
+ s.mEnableRosenpass = s.mSettings.AddSubMenuItemCheckbox("Enable Quantum-Resistance", quantumResistanceMenuDescr, false)
+ s.mNotifications = s.mSettings.AddSubMenuItemCheckbox("Notifications", notificationsMenuDescr, false)
+ s.mAdvancedSettings = s.mSettings.AddSubMenuItem("Advanced Settings", advancedSettingsMenuDescr)
+ s.mCreateDebugBundle = s.mSettings.AddSubMenuItem("Create Debug Bundle", debugBundleMenuDescr)
s.loadSettings()
s.exitNodeMu.Lock()
- s.mExitNode = systray.AddMenuItem("Exit Node", "Select exit node for routing traffic")
+ s.mExitNode = systray.AddMenuItem("Exit Node", exitNodeMenuDescr)
s.mExitNode.Disable()
s.exitNodeMu.Unlock()
- s.mNetworks = systray.AddMenuItem("Networks", "Open the networks management window")
+ s.mNetworks = systray.AddMenuItem("Networks", networksMenuDescr)
s.mNetworks.Disable()
systray.AddSeparator()
@@ -619,11 +640,11 @@ func (s *serviceClient) onTrayReady() {
s.mVersionDaemon.Disable()
s.mVersionDaemon.Hide()
- s.mUpdate = s.mAbout.AddSubMenuItem("Download latest version", "Download latest version")
+ s.mUpdate = s.mAbout.AddSubMenuItem("Download latest version", latestVersionMenuDescr)
s.mUpdate.Hide()
systray.AddSeparator()
- s.mQuit = systray.AddMenuItem("Quit", "Quit the client app")
+ s.mQuit = systray.AddMenuItem("Quit", quitMenuDescr)
// update exit node menu in case service is already connected
go s.updateExitNodes()
diff --git a/client/ui/const.go b/client/ui/const.go
new file mode 100644
index 000000000..0253750d1
--- /dev/null
+++ b/client/ui/const.go
@@ -0,0 +1,15 @@
+package main
+
+const (
+ settingsMenuDescr = "Settings of the application"
+ allowSSHMenuDescr = "Allow SSH connections"
+ autoConnectMenuDescr = "Connect automatically when the service starts"
+ quantumResistanceMenuDescr = "Enable post-quantum security via Rosenpass"
+ notificationsMenuDescr = "Enable notifications"
+ advancedSettingsMenuDescr = "Advanced settings of the application"
+ debugBundleMenuDescr = "Create and open debug information bundle"
+ exitNodeMenuDescr = "Select exit node for routing traffic"
+ networksMenuDescr = "Open the networks management window"
+ latestVersionMenuDescr = "Download latest version"
+ quitMenuDescr = "Quit the client app"
+)
diff --git a/client/ui/icons.go b/client/ui/icons.go
index 6f3a9dbc9..e88fb9378 100644
--- a/client/ui/icons.go
+++ b/client/ui/icons.go
@@ -6,38 +6,38 @@ import (
_ "embed"
)
-//go:embed netbird.png
+//go:embed assets/netbird.png
var iconAbout []byte
-//go:embed netbird-systemtray-connected.png
+//go:embed assets/netbird-systemtray-connected.png
var iconConnected []byte
-//go:embed netbird-systemtray-connected-dark.png
+//go:embed assets/netbird-systemtray-connected-dark.png
var iconConnectedDark []byte
-//go:embed netbird-systemtray-disconnected.png
+//go:embed assets/netbird-systemtray-disconnected.png
var iconDisconnected []byte
-//go:embed netbird-systemtray-update-disconnected.png
+//go:embed assets/netbird-systemtray-update-disconnected.png
var iconUpdateDisconnected []byte
-//go:embed netbird-systemtray-update-disconnected-dark.png
+//go:embed assets/netbird-systemtray-update-disconnected-dark.png
var iconUpdateDisconnectedDark []byte
-//go:embed netbird-systemtray-update-connected.png
+//go:embed assets/netbird-systemtray-update-connected.png
var iconUpdateConnected []byte
-//go:embed netbird-systemtray-update-connected-dark.png
+//go:embed assets/netbird-systemtray-update-connected-dark.png
var iconUpdateConnectedDark []byte
-//go:embed netbird-systemtray-connecting.png
+//go:embed assets/netbird-systemtray-connecting.png
var iconConnecting []byte
-//go:embed netbird-systemtray-connecting-dark.png
+//go:embed assets/netbird-systemtray-connecting-dark.png
var iconConnectingDark []byte
-//go:embed netbird-systemtray-error.png
+//go:embed assets/netbird-systemtray-error.png
var iconError []byte
-//go:embed netbird-systemtray-error-dark.png
+//go:embed assets/netbird-systemtray-error-dark.png
var iconErrorDark []byte
diff --git a/client/ui/icons_windows.go b/client/ui/icons_windows.go
index a2a924763..2107d3852 100644
--- a/client/ui/icons_windows.go
+++ b/client/ui/icons_windows.go
@@ -1,41 +1,41 @@
package main
import (
- _ "embed"
+ _ "embed"
)
-//go:embed netbird.ico
+//go:embed assets/netbird.ico
var iconAbout []byte
-//go:embed netbird-systemtray-connected.ico
+//go:embed assets/netbird-systemtray-connected.ico
var iconConnected []byte
-//go:embed netbird-systemtray-connected-dark.ico
+//go:embed assets/netbird-systemtray-connected-dark.ico
var iconConnectedDark []byte
-//go:embed netbird-systemtray-disconnected.ico
+//go:embed assets/netbird-systemtray-disconnected.ico
var iconDisconnected []byte
-//go:embed netbird-systemtray-update-disconnected.ico
+//go:embed assets/netbird-systemtray-update-disconnected.ico
var iconUpdateDisconnected []byte
-//go:embed netbird-systemtray-update-disconnected-dark.ico
+//go:embed assets/netbird-systemtray-update-disconnected-dark.ico
var iconUpdateDisconnectedDark []byte
-//go:embed netbird-systemtray-update-connected.ico
+//go:embed assets/netbird-systemtray-update-connected.ico
var iconUpdateConnected []byte
-//go:embed netbird-systemtray-update-connected-dark.ico
+//go:embed assets/netbird-systemtray-update-connected-dark.ico
var iconUpdateConnectedDark []byte
-//go:embed netbird-systemtray-connecting.ico
+//go:embed assets/netbird-systemtray-connecting.ico
var iconConnecting []byte
-//go:embed netbird-systemtray-connecting-dark.ico
+//go:embed assets/netbird-systemtray-connecting-dark.ico
var iconConnectingDark []byte
-//go:embed netbird-systemtray-error.ico
+//go:embed assets/netbird-systemtray-error.ico
var iconError []byte
-//go:embed netbird-systemtray-error-dark.ico
+//go:embed assets/netbird-systemtray-error-dark.ico
var iconErrorDark []byte
diff --git a/client/ui/network.go b/client/ui/network.go
index 750788cf3..b21554f09 100644
--- a/client/ui/network.go
+++ b/client/ui/network.go
@@ -363,7 +363,7 @@ func (s *serviceClient) recreateExitNodeMenu(exitNodes []*proto.Network) {
if runtime.GOOS == "linux" || runtime.GOOS == "freebsd" {
s.mExitNode.Remove()
- s.mExitNode = systray.AddMenuItem("Exit Node", "Select exit node for routing traffic")
+ s.mExitNode = systray.AddMenuItem("Exit Node", exitNodeMenuDescr)
}
for _, node := range exitNodes {
diff --git a/client/ui/process.go b/client/ui/process/process.go
similarity index 90%
rename from client/ui/process.go
rename to client/ui/process/process.go
index bcb3dd879..f9a8a4fe9 100644
--- a/client/ui/process.go
+++ b/client/ui/process/process.go
@@ -1,4 +1,4 @@
-package main
+package process
import (
"os"
@@ -8,7 +8,7 @@ import (
"github.com/shirou/gopsutil/v3/process"
)
-func isAnotherProcessRunning() (bool, error) {
+func IsAnotherProcessRunning() (bool, error) {
processes, err := process.Processes()
if err != nil {
return false, err
diff --git a/client/ui/process_nonwindows.go b/client/ui/process/process_nonwindows.go
similarity index 96%
rename from client/ui/process_nonwindows.go
rename to client/ui/process/process_nonwindows.go
index 0d17be2be..cf9f6443d 100644
--- a/client/ui/process_nonwindows.go
+++ b/client/ui/process/process_nonwindows.go
@@ -1,6 +1,6 @@
//go:build !windows
-package main
+package process
import (
"os"
diff --git a/client/ui/process_windows.go b/client/ui/process/process_windows.go
similarity index 96%
rename from client/ui/process_windows.go
rename to client/ui/process/process_windows.go
index b15b0ed24..2d211d1a4 100644
--- a/client/ui/process_windows.go
+++ b/client/ui/process/process_windows.go
@@ -1,4 +1,4 @@
-package main
+package process
import (
"os/user"