Skip to content

Commit

Permalink
Stop holding cached bluetooth devices on unpairing failure
Browse files Browse the repository at this point in the history
Keep on holding can be a problem in cases that bluetooth
device is powered off or even unreachable.
  • Loading branch information
rafael-santiago committed Nov 15, 2024
1 parent a3c1505 commit b2144ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/internal/actions/pair_bluetooth_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestPairBluetoothDevice(t *testing.T) {
} else if err.Error() != "exit status 1" {
t.Errorf("PairBluetoothDevice() has failed with unexpected error.\n")
}
if eutherpeVars.CachedDevices.BlueDevId != "Blue42" {
t.Errorf("PairBluetoothDevice() seems to be messing with cached device even when failing.\n")
if len(eutherpeVars.CachedDevices.BlueDevId) > 0 {
t.Errorf("PairBluetoothDevice() seems to be holding cached device when failing.\n")
}
}
28 changes: 14 additions & 14 deletions src/internal/actions/unpair_bluetooth_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ func UnpairBluetoothDevice(eutherpeVars *vars.EutherpeVars,
err := bluebraces.UnpairDevice(eutherpeVars.CachedDevices.BlueDevId, customPath)
if err == nil {
removeBluetoothDevice(&eutherpeVars.BluetoothDevices, eutherpeVars.CachedDevices.BlueDevId)
eutherpeVars.CachedDevices.BlueDevId = ""
eutherpeVars.CachedDevices.MixerControlName = ""
if len(customPath) == 0 {
// INFO(Rafael): Since user has chosen unpair the device let's save it asap. It can be
// meaningful when user is wanting to power-off her/his device
// but wants to unpair the bluetooth first. Withoout saving the session
// here, when power-on back again the device will try to pair with the
// recently unpaired bluetooth device. Because in normal situations the
// session is saved at each 42 secs. I believe that unpair is a special
// case that the decision must be saved just after to forwadly reflect
// the user intentions accordingly.
eutherpeVars.SaveSession()
}
}
return err
eutherpeVars.CachedDevices.BlueDevId = ""
eutherpeVars.CachedDevices.MixerControlName = ""
if len(customPath) == 0 {
// INFO(Rafael): Since user has chosen unpair the device let's save it asap. It can be
// meaningful when user is wanting to power-off her/his device
// but wants to unpair the bluetooth first. Without saving the session
// here, when power-on back again the device will try to pair with the
// recently unpaired bluetooth device. Because in normal situations the
// session is saved at each 42 secs. I believe that unpair is a special
// case that the decision must be saved just after to forwadly reflect
// the user intentions accordingly.
eutherpeVars.SaveSession()
}
return nil
}

func removeBluetoothDevice(blueDevs *[]bluebraces.BluetoothDevice, blueDevId string) {
Expand Down
8 changes: 4 additions & 4 deletions src/internal/actions/unpair_bluetooth_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func TestUnpairBluetoothDevice(t *testing.T) {
os.Setenv("BLUETOOTHCTL_MUST_FAIL", "1")
defer os.Unsetenv("BLUETOOTHCTL_MUST_FAIL")
err = UnpairBluetoothDevice(eutherpeVars, userData)
if err == nil {
t.Errorf("UnpairBluetoothDevice() has not failed when it should.\n")
} else if eutherpeVars.CachedDevices.BlueDevId != "SeiNaoSeiNao" {
t.Errorf("UnpairBluetoothDevice() seems to be clearing chached device even on error states.\n")
if err != nil {
t.Errorf("UnpairBluetoothDevice() has failed when it should.\n")
} else if len(eutherpeVars.CachedDevices.BlueDevId) > 0 {
t.Errorf("UnpairBluetoothDevice() is holding chached device on error states.\n")
}
}
1 change: 1 addition & 0 deletions src/web/js/eutherpe.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function closeWiFiCredentials() {
}

function closeAlbumCoverViewer() {
document.getElementById("enlargedAlbumCover").src = "";
document.getElementById("AlbumCoverViewer").style.display = "none";
document.getElementById("AlbumCoverDiv").style.display = "block";
}
Expand Down

0 comments on commit b2144ba

Please sign in to comment.