Skip to content

Commit

Permalink
feat(init): remove desktop environment check
Browse files Browse the repository at this point in the history
  • Loading branch information
woshikedayaa committed Dec 27, 2024
1 parent 530dbb8 commit ee56611
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions cmd/internal/su.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func AutoSu() {
if os.Getuid() == 0 {
return
}
path, arg := tryDesktopSudo()
path, arg := tryPolkit()
if path == "" {
path, arg = trySudo()
}
Expand Down Expand Up @@ -57,21 +57,17 @@ func trySudo() (path string, arg []string) {
}
}

func tryDesktopSudo() (path string, arg []string) {
// https://specifications.freedesktop.org/desktop-entry-spec/latest
desktop := os.Getenv("XDG_CURRENT_DESKTOP")
if desktop != "" {
var possible = []string{"pkexec"}
for _, v := range possible {
path, err := exec.LookPath(v)
if err != nil {
continue
}
if isExistAndExecutable(path) {
switch v {
case "pkexec":
return path, []string{path, "--keep-cwd", "--user", "root"}
}
func tryPolkit() (path string, arg []string) {
var possible = []string{"pkexec"}
for _, v := range possible {
path, err := exec.LookPath(v)
if err != nil {
continue
}
if isExistAndExecutable(path) {
switch v {
case "pkexec":
return path, []string{path, "--keep-cwd", "--user", "root"}
}
}
}
Expand Down

0 comments on commit ee56611

Please sign in to comment.