Skip to content

Commit

Permalink
allow to get the name (device name) of the Librespot service
Browse files Browse the repository at this point in the history
  • Loading branch information
wdehoog committed Oct 12, 2018
1 parent 71aef83 commit 95303f1
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions qml/components/Librespot.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -21,7 +21,7 @@ Item {
}*/

DBusInterface {
id: librespotService
id: librespotUnit

property bool serviceRunning: false

Expand All @@ -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") {
Expand All @@ -52,6 +52,46 @@ Item {
}
}

function getName() {
return getEnvironmentVariable("DEVICE_NAME")
}

function getEnvironmentVariable(name) {
var i
if(!librespotService.environment)
return ""
for(i=0;i<librespotService.environment.length;i++) {
var s = librespotService.environment[i].split("=")
if(s[0] === name)
return s[1]
}
return ""
}

DBusInterface {
id: librespotService

property var environment: null

bus: DBus.SessionBus
service: "org.freedesktop.systemd1"
iface: "org.freedesktop.systemd1.Service"

function readServiceProperty(property) {
if (path !== "") {
environment = librespotService.getProperty(property)
console.log(JSON.stringify(environment))
}
}

onPathChanged: {
if(path !== "") {
//readServiceProperty("ExecStart")
readServiceProperty("Environment")
}
}
}

DBusInterface {
id: manager

Expand Down Expand Up @@ -116,7 +156,7 @@ Item {
}

function updateEnabled() {
typedCall("GetUnitFileState", [{"type": "s", "value": librespotService.serviceName}],
typedCall("GetUnitFileState", [{"type": "s", "value": librespotUnit.serviceName}],
function(state) {
// seems to be 'static'
if (state !== "disabled" && state !== "invalid") {
Expand All @@ -131,11 +171,13 @@ Item {
}

function updatePath() {
typedCall("GetUnit", [{ "type": "s", "value": librespotService.serviceName}],
typedCall("GetUnit", [{ "type": "s", "value": librespotUnit.serviceName}],
function(unit) {
librespotUnit.path = unit
librespotService.path = unit
},
function() {
librespotUnit.path = ""
librespotService.path = ""
})
}
Expand All @@ -158,18 +200,18 @@ Item {
signal jobRemoved(int id, string path, string unit, string result)
onJobRemoved: {
if(systemdJob === path)
librespotService.updateState()
librespotUnit.updateState()
console.log("onJobRemoved id:" + id + ", path:" + path + ", unit:" + unit + ", result:" + result)
}
}

function start() {
// when already running we still restart so Librespot will reregister at the Spotify servers
// so it hopefully appears in the list of available devices
manager.restartUnit(librespotService.serviceName)
manager.restartUnit(librespotUnit.serviceName)
}

function stop() {
manager.stopUnit(librespotService.serviceName)
manager.stopUnit(librespotUnit.serviceName)
}
}

0 comments on commit 95303f1

Please sign in to comment.