diff --git a/c-binary/papctl.sh b/c-binary/papctl.sh index 8be2662..d4156f9 100755 --- a/c-binary/papctl.sh +++ b/c-binary/papctl.sh @@ -2,306 +2,333 @@ export HOME="/home/root" +# +# HELP FUNCTIONS +# + +get_vsink_id() { + case ${1} in + palerts) echo "0" ;; + pnotifications) echo "1" ;; + pfeedback) echo "2" ;; + pringtones) echo "3" ;; + pmedia) echo "4" ;; + pflash) echo "5" ;; + pnavigation) echo "6" ;; + pvoicedial) echo "7" ;; + pvvm) echo "8" ;; + pvoip) echo "9" ;; + pdefaultapp) echo "10" ;; + peffects) echo "11" ;; + pDTMF) echo "12" ;; + pcalendar) echo "13" ;; + palarm) echo "14" ;; + esac +} + +# +# MAIN FUNCTION +# + mkdir -p /home/root >/dev/null 2>&1 DIR=$(dirname ${0}) if [ -z "${1}" ]; then - exit 0 + exit 0 fi if [ -e /tmp/papctl-lock ]; then - exit 0 + exit 0 fi case ${1} in - reset) - touch /tmp/papctl-lock + reset) + touch /tmp/papctl-lock + + COUNT="0"; + + while [ ${COUNT} -lt 15 ]; do + ${DIR}/papctl "C ${COUNT} 0 0" + + let COUNT="${COUNT} + 1" + done + + if [ -e "/tmp/papctl-usbmod" ]; then + USB_MODULE=$(cat /tmp/papctl-usbmod) + + /usr/bin/pactl unload-module ${USB_MODULE} + fi + + if [ -e "/tmp/papctl-netmod" ]; then + NET_MODULE=$(cat /tmp/papctl-netmod) + + /usr/bin/pactl unload-module ${NET_MODULE} + fi + + if [ -e "/tmp/papctl-listen" ]; then + CUR_LISTEN=$(cat /tmp/papctl-listen) + + /usr/bin/pactl unload-module ${CUR_LISTEN} + fi + + sleep 3 + + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-usbmod >/dev/null 2>&1 + rm -f /tmp/papctl-netmod >/dev/null 2>&1 + rm -f /tmp/papctl-server >/dev/null 2>&1 + rm -f /tmp/papctl-listen >/dev/null 2>&1 + ;; + + usbon) + touch /tmp/papctl-lock + + VSINKS="${2}" + + if [ -e "/tmp/papctl-vsinks" ]; then + cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "C ${ID} 0 0" + fi + done + + sleep 1 + fi + + if [ -e "/tmp/papctl-usbmod" ]; then + USB_MODULE=$(cat /tmp/papctl-usbmod) + + /usr/bin/pactl unload-module ${USB_MODULE} + + sleep 2 + fi + + /usr/bin/pactl load-module module-alsa-sink device=hw:1 sink_name=usb mmap=1 tsched=1 channels=2 >/tmp/papctl-usbmod + + if [ "${?}" == "0" ]; then + sleep 2 + + echo ${VSINKS} >/tmp/papctl-vsinks + + echo ${VSINKS} | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "O ${ID} 2 0" + fi + done + else + echo "Module load error" + + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-usbmod >/dev/null 2>&1 + fi + ;; + + usboff) + touch /tmp/papctl-lock + + if [ -e "/tmp/papctl-vsinks" ]; then + if [ ! -e "/tmp/papctl-netmod" ]; then + cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "C ${ID} 0 0" + fi + done + fi + fi + + if [ -e "/tmp/papctl-usbmod" ]; then + USB_MODULE=$(cat /tmp/papctl-usbmod) + + /usr/bin/pactl unload-module ${USB_MODULE} + + sleep 2 + fi + + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-usbmod >/dev/null 2>&1 + ;; + + connect) + if [ -z "${2}" ]; then + exit 1 + fi + + touch /tmp/papctl-lock + + SERVER="${2}" ; VSINKS="${3}" + + CUR_SERVER="" ; NET_MODULE="" ; CUR_VSINKS="" + + if [ -e "/tmp/papctl-server" ]; then + CUR_SERVER=$(cat /tmp/papctl-server) + fi + + if [ -e "/tmp/papctl-netmod" ]; then + NET_MODULE=$(cat /tmp/papctl-netmod) + fi + + if [ -e "/tmp/papctl-vsinks" ]; then + CUR_VSINKS=$(cat /tmp/papctl-vsinks) + fi + + if [ "${SERVER}" != "${CUR_SERVER}" ]; then + echo "${SERVER}" >/tmp/papctl-server + + if [ -e "/tmp/papctl-vsinks" ]; then + cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "C ${ID} 0 0" + fi + done + + sleep 1 + fi + + if [ -e "/tmp/papctl-netmod" ]; then + /usr/bin/pactl unload-module ${NET_MODULE} + + sleep 2 + fi + + /usr/bin/pactl load-module module-tunnel-sink server=${SERVER} sink_name=wifi >/tmp/papctl-netmod + + if [ "${?}" == "0" ]; then + sleep 5 + + /usr/bin/pactl list | grep -q "wifi" + + if [ "${?}" == "0" ]; then + echo ${VSINKS} >/tmp/papctl-vsinks + + echo ${VSINKS} | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "O ${ID} 3 0" + fi + done + else + echo "Connection error" + + NET_MODULE=$(cat /tmp/papctl-netmod) + + /usr/bin/pactl unload-module ${NET_MODULE} + + sleep 2 + + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-netmod >/dev/null 2>&1 + rm -f /tmp/papctl-server >/dev/null 2>&1 + fi + else + echo "Module load error" + + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-netmod >/dev/null 2>&1 + rm -f /tmp/papctl-server >/dev/null 2>&1 + fi + elif [ "${VSINKS}" != "${CUR_VSINKS}" ]; then + if [ -e "/tmp/papctl-vsinks" ]; then + cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "C ${ID} 0 0" + fi + done + fi + + echo ${VSINKS} >/tmp/papctl-vsinks + + echo ${VSINKS} | sed s/","/"\n"/g >/tmp/papctl-list + + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) + + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "O ${ID} 3 0" + fi + done + fi + ;; + + disconnect) + touch /tmp/papctl-lock - COUNT="0"; + if [ -e "/tmp/papctl-vsinks" ]; then + if [ ! -e "/tmp/papctl-usbmod" ]; then + cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list - while [ ${COUNT} -lt 15 ]; do - ${DIR}/papctl "C ${COUNT} 0 0" + cat /tmp/papctl-list | while read SINK ; do + ID=$(get_vsink_id ${SINK}) - let COUNT="${COUNT} + 1" - done + if [ ! -z "${ID}" ]; then + ${DIR}/papctl "C ${ID} 0 0" + fi + done + fi + fi - if [ -e "/tmp/papctl-listen" ]; then - CUR_LISTEN=$(cat /tmp/papctl-listen) + if [ -e "/tmp/papctl-netmod" ]; then + NET_MODULE=$(cat /tmp/papctl-netmod) - /usr/bin/pactl unload-module ${CUR_LISTEN} - fi + /usr/bin/pactl unload-module ${NET_MODULE} - if [ -e "/tmp/papctl-module" ]; then - CUR_MODULE=$(cat /tmp/papctl-module) + sleep 2 + fi - /usr/bin/pactl unload-module ${CUR_MODULE} - fi + rm -f /tmp/papctl-vsinks >/dev/null 2>&1 + rm -f /tmp/papctl-netmod >/dev/null 2>&1 + rm -f /tmp/papctl-server >/dev/null 2>&1 + ;; - sleep 2 + enable) + touch /tmp/papctl-lock - rm -f /tmp/papctl-listen - rm -f /tmp/papctl-module - rm -f /tmp/papctl-server - rm -f /tmp/papctl-vsinks - ;; + if [ ! -e "/tmp/papctl-listen" ]; then + /usr/bin/pactl load-module module-native-protocol-tcp auth-anonymous=1 >/tmp/papctl-listen - connect) - if [ -z "${2}" ]; then - exit 1 - fi - - touch /tmp/papctl-lock + sleep 2 + fi + ;; - SERVER="${2}" ; VSINKS="${3}" + disable) + touch /tmp/papctl-lock - CUR_SERVER="" ; CUR_MODULE="" ; CUR_VSINKS="" + if [ -e "/tmp/papctl-listen" ]; then + CUR_LISTEN=$(cat /tmp/papctl-listen) - if [ -e "/tmp/papctl-server" ]; then - CUR_SERVER=$(cat /tmp/papctl-server) - fi + /usr/bin/pactl unload-module ${CUR_LISTEN} - if [ -e "/tmp/papctl-module" ]; then - CUR_MODULE=$(cat /tmp/papctl-module) - fi + sleep 2 + fi - if [ -e "/tmp/papctl-vsinks" ]; then - CUR_VSINKS=$(cat /tmp/papctl-vsinks) - fi - - if [ "${SERVER}" != "${CUR_SERVER}" ]; then - echo "${SERVER}" >/tmp/papctl-server - - if [ -e "/tmp/papctl-vsinks" ]; then - cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list - - cat /tmp/papctl-list | while read SINK ; do - NO="" - - case ${SINK} in - palerts) NO="0" ;; - pnotifications) NO="1" ;; - pfeedback) NO="2" ;; - pringtones) NO="3" ;; - pmedia) NO="4" ;; - pflash) NO="5" ;; - pnavigation) NO="6" ;; - pvoicedial) NO="7" ;; - pvvm) NO="8" ;; - pvoip) NO="9" ;; - pdefaultapp) NO="10" ;; - peffects) NO="11" ;; - pDTMF) NO="12" ;; - pcalendar) NO="13" ;; - palarm) NO="14" ;; - esac - - if [ ! -z "${NO}" ]; then - ${DIR}/papctl "C ${NO} 0 0" - fi - done - fi - - sleep 1 - - if [ -e "/tmp/papctl-module" ]; then - /usr/bin/pactl unload-module ${CUR_MODULE} - - sleep 2 - fi - - /usr/bin/pactl load-module module-tunnel-sink server=${SERVER} sink_name=wifi >/tmp/papctl-module - - if [ "${?}" == "0" ]; then - sleep 5 - - /usr/bin/pactl list | grep -q "wifi" - - if [ "${?}" == "0" ]; then - echo ${VSINKS} >/tmp/papctl-vsinks - - echo ${VSINKS} | sed s/","/"\n"/g >/tmp/papctl-list - - cat /tmp/papctl-list | while read SINK ; do - NO="" - - case ${SINK} in - palerts) NO="0" ;; - pnotifications) NO="1" ;; - pfeedback) NO="2" ;; - pringtones) NO="3" ;; - pmedia) NO="4" ;; - pflash) NO="5" ;; - pnavigation) NO="6" ;; - pvoicedial) NO="7" ;; - pvvm) NO="8" ;; - pvoip) NO="9" ;; - pdefaultapp) NO="10" ;; - peffects) NO="11" ;; - pDTMF) NO="12" ;; - pcalendar) NO="13" ;; - palarm) NO="14" ;; - esac - - if [ ! -z "${NO}" ]; then - ${DIR}/papctl "O ${NO} 3 0" - fi - done - else - echo "Connection error" - - CUR_MODULE=$(cat /tmp/papctl-module) - - /usr/bin/pactl unload-module ${CUR_MODULE} - - sleep 2 - - rm -f /tmp/papctl-module - rm -f /tmp/papctl-server - rm -f /tmp/papctl-vsinks - fi - else - echo "Module load error" - - rm -f /tmp/papctl-module - rm -f /tmp/papctl-server - rm -f /tmp/papctl-vsinks - fi - elif [ "${VSINKS}" != "${CUR_VSINKS}" ]; then - if [ -e "/tmp/papctl-vsinks" ]; then - cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list - - cat /tmp/papctl-list | while read SINK ; do - NO="" - - case ${SINK} in - palerts) NO="0" ;; - pnotifications) NO="1" ;; - pfeedback) NO="2" ;; - pringtones) NO="3" ;; - pmedia) NO="4" ;; - pflash) NO="5" ;; - pnavigation) NO="6" ;; - pvoicedial) NO="7" ;; - pvvm) NO="8" ;; - pvoip) NO="9" ;; - pdefaultapp) NO="10" ;; - peffects) NO="11" ;; - pDTMF) NO="12" ;; - pcalendar) NO="13" ;; - palarm) NO="14" ;; - esac - - if [ ! -z "${NO}" ]; then - ${DIR}/papctl "C ${NO} 0 0" - fi - done - fi - - echo ${VSINKS} >/tmp/papctl-vsinks - - echo ${VSINKS} | sed s/","/"\n"/g >/tmp/papctl-list - - cat /tmp/papctl-list | while read SINK ; do - NO="" - - case ${SINK} in - palerts) NO="0" ;; - pnotifications) NO="1" ;; - pfeedback) NO="2" ;; - pringtones) NO="3" ;; - pmedia) NO="4" ;; - pflash) NO="5" ;; - pnavigation) NO="6" ;; - pvoicedial) NO="7" ;; - pvvm) NO="8" ;; - pvoip) NO="9" ;; - pdefaultapp) NO="10" ;; - peffects) NO="11" ;; - pDTMF) NO="12" ;; - pcalendar) NO="13" ;; - palarm) NO="14" ;; - esac - - if [ ! -z "${NO}" ]; then - ${DIR}/papctl "O ${NO} 3 0" - fi - done - fi - ;; - - disconnect) - touch /tmp/papctl-lock - - if [ -e "/tmp/papctl-vsinks" ]; then - cat /tmp/papctl-vsinks | sed s/","/"\n"/g >/tmp/papctl-list - - cat /tmp/papctl-list | while read SINK ; do - NO="" - - case ${SINK} in - palerts) NO="0" ;; - pnotifications) NO="1" ;; - pfeedback) NO="2" ;; - pringtones) NO="3" ;; - pmedia) NO="4" ;; - pflash) NO="5" ;; - pnavigation) NO="6" ;; - pvoicedial) NO="7" ;; - pvvm) NO="8" ;; - pvoip) NO="9" ;; - pdefaultapp) NO="10" ;; - peffects) NO="11" ;; - pDTMF) NO="12" ;; - pcalendar) NO="13" ;; - palarm) NO="14" ;; - esac - - if [ ! -z "${NO}" ]; then - ${DIR}/papctl "C ${NO} 0 0" - fi - done - fi - - if [ -e "/tmp/papctl-module" ]; then - CUR_MODULE=$(cat /tmp/papctl-module) - - /usr/bin/pactl unload-module ${CUR_MODULE} - - sleep 2 - - rm -f /tmp/papctl-module - rm -f /tmp/papctl-server - rm -f /tmp/papctl-vsinks - fi - ;; - - enable) - touch /tmp/papctl-lock - - if [ ! -e "/tmp/papctl-listen" ]; then - /usr/bin/pactl load-module module-native-protocol-tcp auth-anonymous=1 >/tmp/papctl-listen - - sleep 2 - fi - ;; - - disable) - touch /tmp/papctl-lock - - if [ -e "/tmp/papctl-listen" ]; then - CUR_LISTEN=$(cat /tmp/papctl-listen) - - /usr/bin/pactl unload-module ${CUR_LISTEN} - - rm -f /tmp/papctl-listen - - sleep 2 - fi - ;; + rm -f /tmp/papctl-listen >/dev/null 2>&1 + ;; esac rm -f /tmp/papctl-list >/dev/null 2>&1 rm -f /tmp/papctl-lock >/dev/null 2>&1 -exit 0 \ No newline at end of file +exit 0 diff --git a/control/postinst b/control/postinst index 15a2c5c..5854106 100755 --- a/control/postinst +++ b/control/postinst @@ -1,16 +1,61 @@ #!/bin/sh +SID="org.webosinternals.pulsecontrol.srv" + +APPS="/media/cryptofs/apps" + +SDIR="${APPS}/usr/palm/services/${SID}" + # Handle execution as pmPostInstall.script -if [ -z "$IPKG_OFFLINE_ROOT" ]; then + +if [ ! -d ${APPS} ]; then + echo "Requires webOS 1.3.5 or later" + exit 1 +fi + +if [ -z "${IPKG_OFFLINE_ROOT}" ]; then IPKG_OFFLINE_ROOT=/media/cryptofs/apps mount -o remount,rw / fi -SRV_ID=org.webosinternals.pulsecontrol.srv -SRV_DIR=/media/cryptofs/apps/usr/palm/services/${SRV_ID} +# Remove the upstart configuration + +rm -f /var/palm/event.d/${SID} + +# Remove the ls2 configuration + +rm -f /var/palm/ls2/roles/prv/${SID}.json +rm -f /var/palm/ls2/roles/pub/${SID}.json + +# Remove the dbus service configuration + +rm -f /var/palm/ls2/services/prv/${SID}.service +rm -f /var/palm/ls2/services/pub/${SID}.service + +# Install the upstart configuration mkdir -p /var/palm/event.d -cp -f ${SRV_DIR}/configuration/event.d/${SRV_ID} /var/palm/event.d/ +cp -f ${SDIR}/configuration/event.d/${SID} /var/palm/event.d/ + +# Install the ls2 roles configuration + +mkdir -p /var/palm/ls2/roles/prv /var/palm/ls2/roles/pub + +cp ${SDIR}/${SID}.json /var/palm/ls2/roles/prv/${SID}.json +cp ${SDIR}/${SID}.json /var/palm/ls2/roles/pub/${SID}.json + +# Install the dbus service configuration + +mkdir -p /var/palm/ls2/services/prv /var/palm/ls2/services/pub + +cp ${SDIR}/${SID}.service /var/palm/ls2/services/prv/${SID}.service +cp ${SDIR}/${SID}.service /var/palm/ls2/services/pub/${SID}.service + +# Stop the JS service if running + +/usr/bin/luna-send -n 1 palm://${SID}/__quit '{}' /usr/bin/ls-control scan-services || true + +exit 0 diff --git a/control/prerm b/control/prerm index 4f74ee1..463fe2c 100755 --- a/control/prerm +++ b/control/prerm @@ -1,18 +1,49 @@ #!/bin/sh -# Handle execution as pmPostInstall.script -if [ -z "$IPKG_OFFLINE_ROOT" ]; then +SID="org.webosinternals.pulsecontrol.srv" + +APPS="/media/cryptofs/apps" + +SDIR="${APPS}/usr/palm/services/${SID}" + +# Handle execution as pmPreRemove.script + +if [ ! -d ${APPS} ]; then + echo "Requires webOS 1.3.5 or later" + exit 1 +fi + +if [ -z "${IPKG_OFFLINE_ROOT}" ]; then IPKG_OFFLINE_ROOT=/media/cryptofs/apps mount -o remount,rw / fi -SRV_ID=org.webosinternals.pulsecontrol.srv -SRV_DIR=/media/cryptofs/apps/usr/palm/services/${SRV_ID} +# Remove the upstart configuration + +rm -f /var/palm/event.d/${SID} + +# Remove the ls2 configuration + +rm -f /var/palm/ls2/roles/prv/${SID}.json +rm -f /var/palm/ls2/roles/pub/${SID}.json + +# Remove the dbus service configuration + +rm -f /var/palm/ls2/services/prv/${SID}.service +rm -f /var/palm/ls2/services/pub/${SID}.service + +# Stop the JS service if running + +/usr/bin/luna-send -n 1 palm://${SID}/__quit '{}' + +# +# Cleanup the JS service here due to WebOS bugs +# -rm -f /var/cache/configurator/_media_cryptofs_apps_usr_palm_services_${SRV_ID}_configuration_db_permissions_${SRV_ID} +rm -f /var/cache/configurator/*webosinternals.pulsecontrol* -rm -f /var/palm/event.d/${SRV_ID} +rm -f /var/palm/ls2/roles/*/*webosinternals.pulsecontrol* -#/usr/bin/pkill switcher.srv.js || true +rm -f /var/palm/ls2/services/*/*webosinternals.pulsecontrol* -/usr/bin/ls-control scan-services || true +exit 0 diff --git a/enyo-app/appinfo.json b/enyo-app/appinfo.json index 8612bac..1c371d1 100644 --- a/enyo-app/appinfo.json +++ b/enyo-app/appinfo.json @@ -1,7 +1,7 @@ { "title": "PulseAudio Settings", "id": "org.webosinternals.pulsecontrol", - "version": "0.4.0", + "version": "0.5.0", "release_date": "30-Sep-2011", "vendor": "WebOS Internals", "vendor_email": "support@webos-internals.org", diff --git a/enyo-app/index.html b/enyo-app/index.html index 0341afc..a4c9d34 100644 --- a/enyo-app/index.html +++ b/enyo-app/index.html @@ -17,7 +17,10 @@ if(params.dashboard == "none") { this.appUI.$.controlDashboard.setLayers([]); } else if(params.dashboard == "error") { - enyo.windows.addBannerMessage("PulseAudio server connection failed", "{}", "images/icon-dash.png"); + if(params.reason == "usb") + enyo.windows.addBannerMessage("No USB audio device was found", "{}", "images/icon-dash.png"); + else + enyo.windows.addBannerMessage("PulseAudio server connection failed", "{}", "images/icon-dash.png"); } else if(params.dashboard == "auto") { var hasNotification = false; diff --git a/enyo-app/source/Control.js b/enyo-app/source/Control.js index ddc5e9d..4685217 100644 --- a/enyo-app/source/Control.js +++ b/enyo-app/source/Control.js @@ -6,6 +6,7 @@ enyo.kind({ _ready: false, _prefs: { + _kind: "org.webosinternals.pulsecontrol:1", usbAudio: false, paServers: [], tcpServer: false, @@ -45,7 +46,7 @@ enyo.kind({ {content: $L("Loading PulseAudio Settings...")} ]}, {kind:"Control", name:"prefView", className:"box-center enyo-bg", components: [ - {layoutKind: "VFlexLayout", align: "center", style: "min-width: 100%;", components: [ + {layoutKind: "VFlexLayout", align: "left", style: "min-width: 100%;", components: [ {name: "usbSettings", layoutKind: "HFlexLayout", align: "center", style: "width: 500px;max-width: 100%;", components: [ {kind: "RowGroup", flex: 1, caption: "USB Audio Settings", components: [ {kind: "Item", layoutKind: "HFlexLayout", align: "center", flex: 1, tapHighlight: true, components: [ @@ -55,6 +56,8 @@ enyo.kind({ ]} ]}, + {name: "usbInformation", content: "Note: network audio is disabled while USB audio is enabled.", className: "enyo-item-secondary", style: "margin-left: 5px;margin-bottom: 2px;"}, + {layoutKind: "HFlexLayout", align: "center", style: "width: 500px;max-width: 100%;", components: [ {kind: "RowGroup", flex: 1, caption: "Network Client Settings", components: [ {name: "configuredServers", kind: "VirtualRepeater", onSetupRow: "getConfiguredServer", style: "margin: -10px;", components: [ @@ -83,13 +86,16 @@ enyo.kind({ ]}, ]}, ]}, - + + {style: "padding-top:0px;padding-bottom:6px;padding-left:3px;padding-right: 8px;max-width:100%;-webkit-box-sizing: border-box;", components: [ + {kind: "Button", className: "enyo-button-light", width: "488px", caption: "Show Audio Sources", onclick: "handleEditAdvanced"}, + ]}, + {style: "padding-top:6px;padding-bottom:6px;padding-left:3px;padding-right: 8px;max-width:100%;-webkit-box-sizing: border-box;", components: [ {name: "applySettingsButton", kind: "Button", className: "enyo-button-affirmative", width: "488px", caption: "Apply Configuration", onclick: "handleApplySettings"}, ]}, - {style: "padding-top:0px;padding-bottom:6px;padding-left:3px;padding-right: 8px;max-width:100%;-webkit-box-sizing: border-box;", components: [ - {kind: "Button", className: "enyo-button-light", width: "488px", caption: "Show Audio Sources", onclick: "handleEditAdvanced"}, - ]} + + {content: "You need to apply settings after changing the above settings.", className: "enyo-item-secondary", style: "margin-left: 5px;margin-bottom: 2px;"} ]}, ]}, @@ -223,10 +229,11 @@ enyo.kind({ create: function() { this.inherited(arguments); - this.$.usbSettings.hide(); - - if(enyo.fetchDeviceInfo().modelNameAscii != "TouchPad") { + if((enyo.fetchDeviceInfo().modelNameAscii != "TouchPad") && + (enyo.fetchDeviceInfo().modelNameAscii != "Emulator")) + { this.$.usbSettings.hide(); + this.$.usbInformation.hide(); for(var i = 0; i < this._sinks.length; i++) this.$[this._sinks[i]].items.splice(2, 2); @@ -287,7 +294,7 @@ enyo.kind({ }, handlePrefsSaved: function(inSender, inResponse) { - if (inResponse.results.length === 1) { + if(inResponse.results.length === 1) { this._prefs._id = inResponse.results[0].id; this._prefs._rev = inResponse.results[0].rev; diff --git a/node-service/assistants/control-assistant.js b/node-service/assistants/control-assistant.js index 870df12..f5739fe 100644 --- a/node-service/assistants/control-assistant.js +++ b/node-service/assistants/control-assistant.js @@ -105,7 +105,7 @@ ControlAssistant.prototype.init = function(future, config, args) { }; ControlAssistant.prototype.reset = function(future, config, args) { - var cmd = SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh reset"; + var cmd = "sh " + SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh reset"; exec(cmd, function(future, error, stdout, stderr) { if(error !== null) { @@ -127,58 +127,80 @@ ControlAssistant.prototype.reset = function(future, config, args) { // ControlAssistant.prototype.apply = function(future, config, args) { - var bin = SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; - - if(config.tcpServer) { - var method = "create"; - - var activity = { - "start" : true, - "replace": true, - "activity": { - "name": "firewall", - "description" : "Open PulseAudio Port", - "type": {"cancellable": true, "foreground": true, "persist": false}, - "trigger" : { - "method" : "palm://com.palm.firewall/control", - "params" : {'subscribe': true, "rules": [ - {"protocol": "TCP", "destinationPort": 4713}]} - }, - "callback" : { - "method" : "palm://org.webosinternals.pulsecontrol.srv/control", - "params" : {"action":"none"} - } - } - }; - - future.nest(this.execute(bin + " enable")); - } else { - var method = "cancel"; + var bin = "sh " + SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; - var activity = { activityName: "firewall" }; + if(config.usbAudio) { + var sinks = config.usbSinks.toString(); - future.nest(this.execute(bin + " disable")); + future.nest(this.execute(bin + " usbon " + sinks)); + } else { + future.nest(this.execute(bin + " usboff")); } future.then(this, function(future) { - future.nest(PalmCall.call("palm://com.palm.activitymanager", method, activity)); + var stdout = future.result.stdout; + + if((stdout) && (stdout.slice(0, 17) == "Module load error")) { + future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { + 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "error", "reason": "usb"}})); + } else { + future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { + 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "none"}})); + } - future.then(this, function(future) { - var exception = future.exception; + future.then(this, function(future) { + if((!config.usbAudio) && (config.tcpServer)) { + var method = "create"; + + var activity = { + "start" : true, + "replace": true, + "activity": { + "name": "firewall", + "description" : "Open PulseAudio Port", + "type": {"cancellable": true, "foreground": true, "persist": false}, + "trigger" : { + "method" : "palm://com.palm.firewall/control", + "params" : {'subscribe': true, "rules": [ + {"protocol": "TCP", "destinationPort": 4713}]} + }, + "callback" : { + "method" : "palm://org.webosinternals.pulsecontrol.srv/control", + "params" : {"action":"none"} + } + } + }; - future.nest(PalmCall.call("palm://com.palm.connectionmanager", "getstatus", {})); + future.nest(this.execute(bin + " enable")); + } else { + var method = "cancel"; + var activity = { activityName: "firewall" }; + + future.nest(this.execute(bin + " disable")); + } + future.then(this, function(future) { - if(future.result.wifi) { - args.wifi = future.result.wifi; - - this.check(future, config, args); - } else { - future.result = { returnValue: true }; - } - }); + future.nest(PalmCall.call("palm://com.palm.activitymanager", method, activity)); + + future.then(this, function(future) { + var exception = future.exception; + + future.nest(PalmCall.call("palm://com.palm.connectionmanager", "getstatus", {})); + + future.then(this, function(future) { + if(future.result.wifi) { + args.wifi = future.result.wifi; + + this.check(future, config, args); + } else { + future.result = { returnValue: true }; + } + }); + }); + }); }); - }); + }); }; ControlAssistant.prototype.check = function(future, config, args) { @@ -187,15 +209,17 @@ ControlAssistant.prototype.check = function(future, config, args) { if((args.wifi.state == "connected") && (args.wifi.ssid)) { var ssid = args.wifi.ssid.toLowerCase(); - for(var i = 0; i < config.paServers.length; i++) { - if(config.paServers[i].ssid.toLowerCase() == ssid) { - sinks = config.wifiSinks.toString(); + if(!config.usbAudio) { + for(var i = 0; i < config.paServers.length; i++) { + if(config.paServers[i].ssid.toLowerCase() == ssid) { + sinks = config.wifiSinks.toString(); - addr = config.paServers[i].address; + addr = config.paServers[i].address; - mode = config.paServers[i].mode; + mode = config.paServers[i].mode; - break; + break; + } } } } @@ -210,9 +234,9 @@ ControlAssistant.prototype.check = function(future, config, args) { future.result = { returnValue: true }; }); } else { - if((addr != null) && (sinks != null)) { - args = {address: addr, sinks: sinks}; + args = {address: addr, sinks: sinks}; + if((addr != null) && (sinks != null)) { this.connect(future, config, args); } else { this.disconnect(future, config, args); @@ -226,26 +250,24 @@ ControlAssistant.prototype.check = function(future, config, args) { // ControlAssistant.prototype.connect = function(future, config, args) { - if((args.address) && (args.sinks)) { - var addr = args.address, sinks = args.sinks; - - var bin = SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; + if((!config.usbAudio) && (args.address) && (args.sinks)) { + var bin = "sh " + SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; - future.nest(this.execute(bin + " connect " + addr + " " + sinks)); + future.nest(this.execute(bin + " connect " + args.address + " " + args.sinks)); future.then(this, function(future) { var stdout = future.result.stdout; if((stdout) && (stdout.slice(0, 16) == "Connection error")) { future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { - 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "error"}})); + 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "error", "reason": "net"}})); } else if((stdout) && (stdout.slice(0, 17) == "Module load error")) { future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { - 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "none"}})); + 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "error", "reason": "net"}})); } else { future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "auto", - 'address': addr, 'sinks': sinks}})); + 'address': args.address, 'sinks': args.sinks}})); } future.then(this, function(future) { @@ -258,19 +280,17 @@ ControlAssistant.prototype.connect = function(future, config, args) { }; ControlAssistant.prototype.disconnect = function(future, config, args) { - var addr = args.address, sinks = args.sinks; - - var bin = SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; + var bin = "sh " + SERVICES_DIR + "/" + SERVICE_ID + "/bin/papctl.sh"; future.nest(this.execute(bin + " disconnect")); future.then(this, function(future) { var stdout = future.result.stdout; - if((addr != undefined) && (sinks != undefined)) { + if((args.address) && (args.sinks)) { future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "manual", - 'address': addr, 'sinks': sinks}})); + 'address': args.address, 'sinks': args.sinks}})); } else { future.nest(PalmCall.call("palm://com.palm.applicationManager/", "launch", { 'id': "org.webosinternals.pulsecontrol", 'params': {'dashboard': "none"}})); diff --git a/package/packageinfo.json b/package/packageinfo.json index de14449..b7485c2 100644 --- a/package/packageinfo.json +++ b/package/packageinfo.json @@ -2,7 +2,7 @@ "id": "org.webosinternals.pulsecontrol", "package_format_version": 2, "loc_name": "PulseAudio Settings", - "version": "0.4.0", + "version": "0.5.0", "icon": "icon.png", "miniicon": "icon.png", "vendor": "WebOS Internals",