From 2351025f6f067867fd9c451977e59d025f994319 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Fri, 22 Sep 2017 17:07:45 +0900 Subject: [PATCH] Allow master volume to be always muted. --- CHANGELOG.md | 1 + lib/cli/device/index.js | 16 ++++++++++++++-- lib/cli/local/index.js | 18 +++++++++++++++--- lib/cli/provider/index.js | 18 +++++++++++++++--- lib/units/device/plugins/mute.js | 27 +++++++++++++++++++++------ 5 files changed, 66 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec636846..1a381255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Enhancements - The network column in the device list is now based on a value that gets updated in real time. The format of the column has changed slightly due to this change. +- The `--mute-master` option now accepts the values `never` (default), `inuse` (only when a device is being used), and `always` (mute pre-emptively during setup phase). For backwards compatibility, `--mute-master` with no value maps to `inuse`, and `--no-mute-master` to `never`. ### Fixes diff --git a/lib/cli/device/index.js b/lib/cli/device/index.js index 124fb1fb..d94bee53 100644 --- a/lib/cli/device/index.js +++ b/lib/cli/device/index.js @@ -66,8 +66,20 @@ module.exports.builder = function(yargs) { , type: 'boolean' }) .option('mute-master', { - describe: 'Whether to mute master volume when devices are being used.' - , type: 'boolean' + describe: 'Whether to mute master volume.' + , choices: ['always', 'inuse', 'never'] + , default: 'never' + , coerce: val => { + if (val === true) { + return 'inuse' // For backwards compatibility. + } + + if (val === false) { + return 'never' // For backwards compatibility. + } + + return val + } }) .option('provider', { alias: 'n' diff --git a/lib/cli/local/index.js b/lib/cli/local/index.js index ae58baa1..6470dd94 100644 --- a/lib/cli/local/index.js +++ b/lib/cli/local/index.js @@ -115,8 +115,20 @@ module.exports.builder = function(yargs) { , type: 'boolean' }) .option('mute-master', { - describe: 'Whether to mute master volume when devices are being used.' - , type: 'boolean' + describe: 'Whether to mute master volume.' + , choices: ['always', 'inuse', 'never'] + , default: 'never' + , coerce: val => { + if (val === true) { + return 'inuse' // For backwards compatibility. + } + + if (val === false) { + return 'never' // For backwards compatibility. + } + + return val + } }) .option('port', { alias: ['p', 'poorxy-port'] @@ -265,9 +277,9 @@ module.exports.handler = function(argv) { , '--adb-host', argv.adbHost , '--adb-port', argv.adbPort , '--vnc-initial-size', argv.vncInitialSize.join('x') + , '--mute-master', argv.muteMaster ] .concat(argv.allowRemote ? ['--allow-remote'] : []) - .concat(argv.muteMaster ? ['--mute-master'] : []) .concat(argv.lockRotation ? ['--lock-rotation'] : []) .concat(!argv.cleanup ? ['--no-cleanup'] : []) .concat(argv.serial)) diff --git a/lib/cli/provider/index.js b/lib/cli/provider/index.js index 1d68eba6..108b2347 100644 --- a/lib/cli/provider/index.js +++ b/lib/cli/provider/index.js @@ -85,8 +85,20 @@ module.exports.builder = function(yargs) { , default: 7400 }) .option('mute-master', { - describe: 'Whether to mute master volume when devices are being used.' - , type: 'boolean' + describe: 'Whether to mute master volume.' + , choices: ['always', 'inuse', 'never'] + , default: 'never' + , coerce: val => { + if (val === true) { + return 'inuse' // For backwards compatibility. + } + + if (val === false) { + return 'never' // For backwards compatibility. + } + + return val + } }) .option('name', { alias: 'n' @@ -177,6 +189,7 @@ module.exports.handler = function(argv) { , '--heartbeat-interval', argv.heartbeatInterval , '--boot-complete-timeout', argv.bootCompleteTimeout , '--vnc-initial-size', argv.vncInitialSize.join('x') + , '--mute-master', argv.muteMaster ] .concat(argv.connectSub.reduce(function(all, val) { return all.concat(['--connect-sub', val]) @@ -184,7 +197,6 @@ module.exports.handler = function(argv) { .concat(argv.connectPush.reduce(function(all, val) { return all.concat(['--connect-push', val]) }, [])) - .concat(argv.muteMaster ? ['--mute-master'] : []) .concat(argv.lockRotation ? ['--lock-rotation'] : []) .concat(!argv.cleanup ? ['--no-cleanup'] : []) diff --git a/lib/units/device/plugins/mute.js b/lib/units/device/plugins/mute.js index 6ff54675..7afef3f3 100644 --- a/lib/units/device/plugins/mute.js +++ b/lib/units/device/plugins/mute.js @@ -9,11 +9,23 @@ module.exports = syrup.serial() .define(function(options, group, service) { var log = logger.createLogger('device:plugins:mute') - if (options.muteMaster) { - log.info('Will mute master volume during use') + switch (options.muteMaster) { + case 'always': + log.info('Pre-emptively muting master volume') + + service.setMasterMute(true) + + group.on('leave', function() { + log.info('Muting master volume again just in case it was re-enabled') + service.setMasterMute(true) + }) + + break + case 'inuse': + log.info('Will mute master volume during use only') group.on('join', function() { - log.info('Muting master volume') + log.info('Muting master volume during use') service.setMasterMute(true) }) @@ -21,9 +33,12 @@ module.exports = syrup.serial() log.info('Unmuting master volume') service.setMasterMute(false) }) - } - else { - log.info('Will not mute master volume during use') + + break + case 'never': + default: + log.info('Will not mute master volume') + break } return Promise.resolve()