Skip to content

Commit

Permalink
try to detect at start if Librespot is known by Spotify and restart i…
Browse files Browse the repository at this point in the history
…t if not
  • Loading branch information
wdehoog committed Oct 12, 2018
1 parent 95303f1 commit d3c1062
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions qml/components/SpotifyController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ Item {
}
}

Connections {
/*Connections {
target: app
onStateChanged: {
if (app.state === Qt.ApplicationActive) {
app.controller.reloadDevices();
}
}
}
}*/

Connections {
target: spotify
Expand Down Expand Up @@ -100,17 +100,21 @@ Item {
})
}

signal devicesReloaded()

function reloadDevices() {
Spotify.getMyDevices(function(error, data) {
if (data) {
try {
console.log("reloadDevices() #devices: " + data.devices.length)
devicesModel.clear();
for (var i=0; i < data.devices.length; i++) {
//console.log(JSON.stringify(data.devices[i]))
devicesModel.append(data.devices[i]);
if (data.devices[i].is_active)
playbackState.device = data.devices[i]
}
devicesReloaded()
} catch (err) {
console.log("reloadDevices() error: " + err)
}
Expand Down
30 changes: 30 additions & 0 deletions qml/hutspot.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ApplicationWindow {

property alias queue: queue
property alias playingPage: playingPage
property alias librespot: librespot

allowedOrientations: defaultAllowedOrientations

Expand Down Expand Up @@ -814,6 +815,35 @@ ApplicationWindow {
id: librespot
}

// check if the Librespot service is known to Spotify
function isLibrespotInDevicesList() {
var i
// we cannot determine the name if it is not running
if(!librespot.serviceRunning)
return false
var devName = librespot.getName()
if(devName.length === 0) // failed to determine the name
return false
for(i=0;i<spotifyController.devices.count;i++) {
var device = spotifyController.devices.get(i)
if(device.name === devName)
return true
}
return false
}

Connections {
target: spotifyController
onDevicesReloaded: {
// check if Librespot is known to Spotify and if not restart it
if(app.start_stop_librespot.value
&& !isLibrespotInDevicesList()) {
console.log("Librespot is not in the devices list so restart it")
librespot.start()
}
}
}

function getAppIconSource() {
return getAppIconSource2(Theme.iconSizeExtraLarge)
}
Expand Down

0 comments on commit d3c1062

Please sign in to comment.