Skip to content

Commit

Permalink
feat: detect url on output
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Jan 28, 2024
1 parent 506d204 commit 36eecde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bluetooth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"errors"
"strings"

"github.com/mrmarble/improv/improv"
"tinygo.org/x/bluetooth"
Expand Down Expand Up @@ -150,10 +149,9 @@ func configureWIFI(args []string, errorHandler bluetooth.Characteristic, statusH
}
if output != "" {
infoln("Wifi command output:", output)
lines := strings.Split(output, "\n")
lastLine := lines[len(lines)-1]
if strings.HasPrefix(lastLine, "http") {
rpcResultHandler.Write(protocol.BuildImprovResponse(improv.COMMAND_WIFI_SETTINGS, []string{lastLine}))
url := findUrl(output)
if url != "" {
rpcResultHandler.Write(protocol.BuildImprovResponse(improv.COMMAND_WIFI_SETTINGS, []string{url}))
}
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ func debugln(args ...string) {
func errorln(args ...string) {
println("[ERROR]", strings.Join(args, " "))
}

func findUrl(str string) string {
for _, line := range strings.Split(str, "\n") {
if strings.HasPrefix(line, "http") {
return strings.TrimSpace(line)
}
}
return ""
}

0 comments on commit 36eecde

Please sign in to comment.