mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
doctor: use dbus for checking on services (#1384)
* doctor: use dbus for checking on services * doctor: show docs URL for failed checks * core: remove unused function
This commit is contained in:
20
core/internal/utils/dbus.go
Normal file
20
core/internal/utils/dbus.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
func IsDBusServiceAvailable(busName string) bool {
|
||||
conn, err := dbus.ConnectSystemBus()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
obj := conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
||||
var owned bool
|
||||
if err := obj.Call("org.freedesktop.DBus.NameHasOwner", 0, busName).Store(&owned); err != nil {
|
||||
return false
|
||||
}
|
||||
return owned
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AppChecker interface {
|
||||
@@ -43,16 +42,3 @@ func AnyCommandExists(cmds ...string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsServiceActive(name string, userService bool) bool {
|
||||
if !CommandExists("systemctl") {
|
||||
return false
|
||||
}
|
||||
|
||||
args := []string{"is-active", name}
|
||||
if userService {
|
||||
args = []string{"--user", "is-active", name}
|
||||
}
|
||||
output, _ := exec.Command("systemctl", args...).Output()
|
||||
return strings.EqualFold(strings.TrimSpace(string(output)), "active")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user