From 67e21859644e04e771075f704084b3748c565c5b Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Thu, 23 May 2024 12:34:19 +0200 Subject: [PATCH] Accept any XDG_ environment variable to determine desktop (#2037) --- client/cmd/login.go | 12 +++++++++++- client/cmd/login_test.go | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/client/cmd/login.go b/client/cmd/login.go index 14c973d91..065f8553a 100644 --- a/client/cmd/login.go +++ b/client/cmd/login.go @@ -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 } diff --git a/client/cmd/login_test.go b/client/cmd/login_test.go index 6bb7eff4f..45f342b9d 100644 --- a/client/cmd/login_test.go +++ b/client/cmd/login_test.go @@ -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") + } +}