Skip to content

Commit

Permalink
Accept any XDG_ environment variable to determine desktop (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlsmaycon authored May 23, 2024
1 parent 89149dc commit 67e2185
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions client/cmd/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -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")
}
}

0 comments on commit 67e2185

Please sign in to comment.