From 95303f1cf096ecef237934f6dd54c1b30fc8e382 Mon Sep 17 00:00:00 2001 From: wdehoog Date: Fri, 12 Oct 2018 21:14:19 +0200 Subject: [PATCH 1/2] allow to get the name (device name) of the Librespot service --- qml/components/Librespot.qml | 60 ++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/qml/components/Librespot.qml b/qml/components/Librespot.qml index ce844d0..2a024f6 100644 --- a/qml/components/Librespot.qml +++ b/qml/components/Librespot.qml @@ -11,7 +11,7 @@ import org.nemomobile.dbus 2.0 Item { property alias serviceEnabled: manager.librespotServiceEnabled - property alias serviceRunning: librespotService.serviceRunning + property alias serviceRunning: librespotUnit.serviceRunning /*onLibrespotServiceEnabled: { console.log("onLibrespotServiceEnabled: " + librespotServiceEnabled) @@ -21,7 +21,7 @@ Item { }*/ DBusInterface { - id: librespotService + id: librespotUnit property bool serviceRunning: false @@ -32,9 +32,9 @@ Item { signalsEnabled: true function updateState() { - console.log("librespotService.updateState: path=" + path) + console.log("librespotUnit.updateState: path=" + path) if (path !== "") { - var activeState = librespotService.getProperty("ActiveState") + var activeState = librespotUnit.getProperty("ActiveState") if (activeState === "active") { serviceRunning = true } else if(activeState === "inactive") { @@ -52,6 +52,46 @@ Item { } } + function getName() { + return getEnvironmentVariable("DEVICE_NAME") + } + + function getEnvironmentVariable(name) { + var i + if(!librespotService.environment) + return "" + for(i=0;i Date: Fri, 12 Oct 2018 21:15:01 +0200 Subject: [PATCH 2/2] try to detect at start if Librespot is known by Spotify and restart it if not --- qml/components/SpotifyController.qml | 8 ++++++-- qml/hutspot.qml | 30 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/qml/components/SpotifyController.qml b/qml/components/SpotifyController.qml index 9b2ed43..2b538b0 100644 --- a/qml/components/SpotifyController.qml +++ b/qml/components/SpotifyController.qml @@ -59,14 +59,14 @@ Item { } } - Connections { + /*Connections { target: app onStateChanged: { if (app.state === Qt.ApplicationActive) { app.controller.reloadDevices(); } } - } + }*/ Connections { target: spotify @@ -100,6 +100,8 @@ Item { }) } + signal devicesReloaded() + function reloadDevices() { Spotify.getMyDevices(function(error, data) { if (data) { @@ -107,10 +109,12 @@ Item { 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) } diff --git a/qml/hutspot.qml b/qml/hutspot.qml index c6a728a..3a743ac 100644 --- a/qml/hutspot.qml +++ b/qml/hutspot.qml @@ -45,6 +45,7 @@ ApplicationWindow { property alias queue: queue property alias playingPage: playingPage + property alias librespot: librespot allowedOrientations: defaultAllowedOrientations @@ -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