Skip to content

Commit

Permalink
add a fallback regex to check version
Browse files Browse the repository at this point in the history
  • Loading branch information
rajkumarGosavi committed Oct 7, 2023
1 parent 1b57a64 commit 6c01c6d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
var servername string
var servertype uint
var major, minor, patch int
var versionRegex *regexp.Regexp
var versionRegex, fallbackVersionRegex *regexp.Regexp
var versionString string

var outdatedPipeWire bool
Expand All @@ -255,15 +255,31 @@ func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
servername = "PulseAudio"
servertype = servertype_pulse
versionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+)\.(\d+).*?`)
fallbackVersionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+).*?`)
versionString = info.PackageVersion
log.Printf("Detected PulseAudio\n")
}

res := versionRegex.FindStringSubmatch(versionString)
if len(res) != 4 {
log.Printf("couldn't parse server version, regexp didn't match version: %s\n", versionString)
if fallbackVersionRegex == nil {
log.Printf("couldn't parse server version, regexp didn't match version: %s\n", versionString)
return audioserverinfo{servertype: servertype}, nil
}
}

// the server version did not match the standard `major.minor.patch` regex
// now trying with fallback regex of style `major.minor`

res = fallbackVersionRegex.FindStringSubmatch(versionString)
if len(res) != 3 {
log.Printf("couldn't parse server version, fallback regexp didn't match version: %s\n", versionString)
return audioserverinfo{servertype: servertype}, nil
} else {
// set patch number as `0` by default if patch is not provided by the server version
res = append(res, "0")
}

major, err = strconv.Atoi(res[1])
if err != nil {
return audioserverinfo{servertype: servertype}, err
Expand Down Expand Up @@ -330,7 +346,7 @@ func getDefaultSinkID(client *pulseaudio.Client) (string, error) {
return server.DefaultSink, nil
}

//this is disgusting
// this is disgusting
func fixWindowClass() {
xu, err := xgbutil.NewConn()
defer xu.Conn().Close()
Expand Down

0 comments on commit 6c01c6d

Please sign in to comment.