mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-21 23:53:14 +01:00
Accept any XDG_ environment variable to determine desktop (#2037)
This commit is contained in:
parent
89149dc6f4
commit
67e2185964
@ -219,5 +219,15 @@ func openURL(cmd *cobra.Command, verificationURIComplete, userCode string) {
|
||||
|
||||
// isLinuxRunningDesktop checks if a Linux OS is running desktop environment
|
||||
func isLinuxRunningDesktop() bool {
|
||||
return os.Getenv("DESKTOP_SESSION") != "" || os.Getenv("XDG_CURRENT_DESKTOP") != ""
|
||||
if os.Getenv("DESKTOP_SESSION") != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, env := range os.Environ() {
|
||||
if strings.HasPrefix(env, "XDG_") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -51,3 +52,16 @@ func TestLogin(t *testing.T) {
|
||||
t.Errorf("expected non empty Private key, got empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLinuxRunningDesktop(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skip("skipping test on non-linux platform")
|
||||
}
|
||||
|
||||
t.Setenv("XDG_FOO", "BAR")
|
||||
|
||||
isDesktop := isLinuxRunningDesktop()
|
||||
if !isDesktop {
|
||||
t.Errorf("expected desktop environment, got false")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user