Reorganize and clean code

This commit is contained in:
Elara 2021-12-17 00:31:05 -08:00
parent 23b9cfe8a3
commit e88dea40fb

46
main.go
View File

@ -37,28 +37,6 @@ var (
updateFS = false updateFS = false
) )
func onReqPasskey() (uint32, error) {
var out uint32
if isatty.IsTerminal(os.Stdin.Fd()) {
fmt.Print("Passkey: ")
_, err := fmt.Scanln(&out)
if err != nil {
return 0, err
}
} else {
passkey, ok, err := dlgs.Entry("Pairing", "Enter the passkey displayed on your watch.", "")
if err != nil {
return 0, err
}
if !ok {
return 0, nil
}
passkeyInt, err := strconv.Atoi(passkey)
return uint32(passkeyInt), err
}
return out, nil
}
func main() { func main() {
infinitime.Init() infinitime.Init()
// Cleanly exit after function // Cleanly exit after function
@ -130,7 +108,7 @@ func main() {
// Start control socket // Start control socket
err = initCallNotifs(dev) err = initCallNotifs(dev)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error starting socket") log.Error().Err(err).Msg("Error initializing call notifications")
} }
// Initialize notification relay // Initialize notification relay
@ -148,3 +126,25 @@ func main() {
// Block forever // Block forever
select {} select {}
} }
func onReqPasskey() (uint32, error) {
var out uint32
if isatty.IsTerminal(os.Stdin.Fd()) {
fmt.Print("Passkey: ")
_, err := fmt.Scanln(&out)
if err != nil {
return 0, err
}
} else {
passkey, ok, err := dlgs.Entry("Pairing", "Enter the passkey displayed on your watch.", "")
if err != nil {
return 0, err
}
if !ok {
return 0, nil
}
passkeyInt, err := strconv.Atoi(passkey)
return uint32(passkeyInt), err
}
return out, nil
}