Skip to content

Commit

Permalink
Avoid hanging when repairing with bluetooth device
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-santiago committed Sep 4, 2024
1 parent 88e0814 commit 0c8399a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/eutherpe.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func tryToPairWithPreviousBluetoothDevice(eutherpeVars *vars.EutherpeVars,
eutherpeVars.Unlock()
return
}
eutherpeVars.Unlock()
blueDevs, _ := bluebraces.ScanDevices(time.Duration(10 * time.Second))
found := false
for _, blueDev := range blueDevs {
Expand All @@ -109,23 +110,26 @@ func tryToPairWithPreviousBluetoothDevice(eutherpeVars *vars.EutherpeVars,
}
}
var err error
var mixerControlName string
if found {
err = bluebraces.PairDevice(previousDevice)
if err == nil {
err = bluebraces.ConnectDevice(previousDevice)
if err == nil {
eutherpeVars.CachedDevices.MixerControlName, err = bluebraces.GetBlueAlsaMixerControlName()
mixerControlName, err = bluebraces.GetBlueAlsaMixerControlName()
}
}
} else {
err = fmt.Errorf("Previous device powered off.")
}
shouldTryAgain := (err != nil)
eutherpeVars.Unlock()
if shouldTryAgain {
time.Sleep(10 * time.Second)
go tryToPairWithPreviousBluetoothDevice(eutherpeVars, previousDevice)
} else {
eutherpeVars.Lock()
defer eutherpeVars.Unlock()
eutherpeVars.CachedDevices.MixerControlName = mixerControlName
mplayer.SetVolume(int(eutherpeVars.Player.VolumeLevel),
eutherpeVars.CachedDevices.MixerControlName)
}
Expand Down

0 comments on commit 0c8399a

Please sign in to comment.