app: handle launch method in New function

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-09-12 20:53:33 +09:00
parent 8223a9ee66
commit b0aff89166
6 changed files with 125 additions and 52 deletions

12
internal/util/early.go Normal file
View File

@@ -0,0 +1,12 @@
package util
import "fmt"
var SdBootedV = func() bool {
if v, err := SdBooted(); err != nil {
fmt.Println("warn: read systemd marker:", err)
return false
} else {
return v
}
}()

View File

@@ -8,7 +8,6 @@ import (
"path"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/system"
)
const (
@@ -22,19 +21,16 @@ const (
)
// SdBooted implements https://www.freedesktop.org/software/systemd/man/sd_booted.html
func SdBooted() bool {
func SdBooted() (bool, error) {
_, err := os.Stat(systemdCheckPath)
if err != nil {
if system.V.Verbose {
if errors.Is(err, fs.ErrNotExist) {
fmt.Println("System not booted through systemd")
} else {
fmt.Println("Error accessing", systemdCheckPath+":", err.Error())
}
if errors.Is(err, fs.ErrNotExist) {
err = nil
}
return false
return false, err
}
return true
return true, nil
}
// DiscoverPulseCookie try various standard methods to discover the current user's PulseAudio authentication cookie