fix bad parsing

This commit is contained in:
2025-07-30 21:00:51 +02:00
parent a6584f366c
commit f388c3e6f3

11
main.go
View File

@@ -2,6 +2,7 @@ package main
import ( import (
_ "embed" _ "embed"
"fmt"
"os" "os"
"os/exec" "os/exec"
"regexp" "regexp"
@@ -39,14 +40,17 @@ func onReady() {
systray.SetIcon(icon) systray.SetIcon(icon)
for _, entry := range entries { for _, entry := range entries {
fmt.Println(entry.Attributes)
key := entry.Key key := entry.Key
uuid := entry.Attributes["identifier"]
if desc, ok := entry.Attributes["description"]; ok { if desc, ok := entry.Attributes["description"]; ok {
key = desc key = desc
} }
mCustom := systray.AddMenuItem(key, "Switch to"+key) mCustom := systray.AddMenuItem(key, "Switch to"+key)
go func() { go func() {
<-mCustom.ClickedCh <-mCustom.ClickedCh
reboot(entry.Attributes["identifier"]) fmt.Println(uuid)
reboot(uuid)
}() }()
} }
@@ -103,8 +107,11 @@ func parse(out string) []Entry {
} }
for _, l := range sec { for _, l := range sec {
l = strings.Join(strings.Fields(l), " ") l = strings.Join(strings.Fields(l), " ")
val := strings.SplitN(l, " ", 1) val := strings.Split(l, " ")
if len(val) != 2 { if len(val) != 2 {
if len(val) > 2 {
val[1] = strings.Join(val[1:], " ")
}
continue continue
} }
entry.Attributes[val[0]] = val[1] entry.Attributes[val[0]] = val[1]