From a62a6094e4ccba1c6266f01ff0ffc35ac9408b1f Mon Sep 17 00:00:00 2001 From: Vishal Banthia Date: Wed, 23 Nov 2016 06:45:36 +0530 Subject: [PATCH] Use automation state for devices used by api --- lib/db/api.js | 15 +++++++++++++++ lib/units/api/controllers/user.js | 2 ++ lib/units/device/plugins/group.js | 7 ++++--- lib/units/processor/index.js | 4 ++++ lib/units/websocket/index.js | 1 + lib/wire/wire.proto | 2 ++ .../stf/device/device-info-filter/index.js | 6 ++++-- .../enhance-device/enhance-device-service.js | 7 ++++++- .../stf/device/state-classes-service.js | 7 ++++--- .../device-list/column/device-column-service.js | 1 + .../icons/device-list-icons-directive.js | 3 ++- 11 files changed, 45 insertions(+), 10 deletions(-) diff --git a/lib/db/api.js b/lib/db/api.js index c5d7adfc..860ecbd4 100644 --- a/lib/db/api.js +++ b/lib/db/api.js @@ -153,6 +153,7 @@ dbapi.saveDeviceInitialState = function(serial, device) { , reverseForwards: [] , remoteConnect: false , remoteConnectUrl: null + , usage: null } return db.run(r.table('devices').get(serial).update(data)) .then(function(stats) { @@ -212,6 +213,20 @@ dbapi.setDeviceAbsent = function(serial) { })) } +dbapi.setDeviceUsage = function(serial, usage) { + return db.run(r.table('devices').get(serial).update({ + usage: usage + , usageChangedAt: r.now() + })) +} + +dbapi.unsetDeviceUsage = function(serial) { + return db.run(r.table('devices').get(serial).update({ + usage: null + , usageChangedAt: r.now() + })) +} + dbapi.setDeviceAirplaneMode = function(serial, enabled) { return db.run(r.table('devices').get(serial).update({ airplaneMode: enabled diff --git a/lib/units/api/controllers/user.js b/lib/units/api/controllers/user.js index 6cfb5fa2..caac4e6c 100644 --- a/lib/units/api/controllers/user.js +++ b/lib/units/api/controllers/user.js @@ -148,6 +148,7 @@ function addUserDevice(req, res) { .handler() req.options.channelRouter.on(wireutil.global, messageListener) + var usage = 'automation' req.options.push.send([ device.channel @@ -165,6 +166,7 @@ function addUserDevice(req, res) { , match: 'exact' } }) + , usage ) ) ]) diff --git a/lib/units/device/plugins/group.js b/lib/units/device/plugins/group.js index 50e62b31..2ebe030a 100644 --- a/lib/units/device/plugins/group.js +++ b/lib/units/device/plugins/group.js @@ -30,7 +30,7 @@ module.exports = syrup.serial() return currentGroup }) - plugin.join = function(newGroup, timeout, identifier) { + plugin.join = function(newGroup, timeout, usage) { return plugin.get() .then(function() { if (currentGroup.group !== newGroup.group) { @@ -57,10 +57,11 @@ module.exports = syrup.serial() , wireutil.envelope(new wire.JoinGroupMessage( options.serial , currentGroup + , usage )) ]) - plugin.emit('join', currentGroup, identifier) + plugin.emit('join', currentGroup) return currentGroup }) @@ -113,7 +114,7 @@ module.exports = syrup.serial() var reply = wireutil.reply(options.serial) grouputil.match(ident, message.requirements) .then(function() { - return plugin.join(message.owner, message.timeout) + return plugin.join(message.owner, message.timeout, message.usage) }) .then(function() { push.send([ diff --git a/lib/units/processor/index.js b/lib/units/processor/index.js index 886fcdbb..dfe464c1 100644 --- a/lib/units/processor/index.js +++ b/lib/units/processor/index.js @@ -175,10 +175,14 @@ module.exports = function(options) { }) .on(wire.JoinGroupMessage, function(channel, message, data) { dbapi.setDeviceOwner(message.serial, message.owner) + if (message.usage) { + dbapi.setDeviceUsage(message.serial, message.usage) + } appDealer.send([channel, data]) }) .on(wire.LeaveGroupMessage, function(channel, message, data) { dbapi.unsetDeviceOwner(message.serial, message.owner) + dbapi.unsetDeviceUsage(message.serial) appDealer.send([channel, data]) }) .on(wire.DeviceLogMessage, function(channel, message, data) { diff --git a/lib/units/websocket/index.js b/lib/units/websocket/index.js index f2a93255..6eeb6088 100644 --- a/lib/units/websocket/index.js +++ b/lib/units/websocket/index.js @@ -174,6 +174,7 @@ module.exports = function(options) { serial: message.serial , owner: message.owner , likelyLeaveReason: 'owner_change' + , usage: message.usage } , user ) diff --git a/lib/wire/wire.proto b/lib/wire/wire.proto index 52215f09..5de995cd 100644 --- a/lib/wire/wire.proto +++ b/lib/wire/wire.proto @@ -261,6 +261,7 @@ message GroupMessage { required OwnerMessage owner = 1; optional uint32 timeout = 2; repeated DeviceRequirement requirements = 3; + optional string usage = 4; } message AutoGroupMessage { @@ -275,6 +276,7 @@ message UngroupMessage { message JoinGroupMessage { required string serial = 1; required OwnerMessage owner = 2; + optional string usage = 3; } message JoinGroupByAdbFingerprintMessage { diff --git a/res/app/components/stf/device/device-info-filter/index.js b/res/app/components/stf/device/device-info-filter/index.js index 198ee0cf..3d85abc4 100644 --- a/res/app/components/stf/device/device-info-filter/index.js +++ b/res/app/components/stf/device/device-info-filter/index.js @@ -10,7 +10,8 @@ module.exports = angular.module('stf.device-status', []) ready: gettext('Ready'), using: gettext('Stop Using'), busy: gettext('Busy'), - available: gettext('Use') + available: gettext('Use'), + automation: gettext('Stop Automation') }[text] || gettext('Unknown') } }) @@ -25,7 +26,8 @@ module.exports = angular.module('stf.device-status', []) ready: gettext('Ready'), using: gettext('Using'), busy: gettext('Busy'), - available: gettext('Available') + available: gettext('Available'), + automation: gettext('Automating'), }[text] || gettext('Unknown') } }) diff --git a/res/app/components/stf/device/enhance-device/enhance-device-service.js b/res/app/components/stf/device/enhance-device/enhance-device-service.js index 39afae92..b55701a1 100644 --- a/res/app/components/stf/device/enhance-device/enhance-device-service.js +++ b/res/app/components/stf/device/enhance-device/enhance-device-service.js @@ -19,7 +19,12 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) { if (data.ready) { data.state = 'ready' if (data.using) { - data.state = 'using' + if (data.usage === 'automation') { + data.state = 'automation' + } + else { + data.state = 'using' + } } else { if (data.owner) { diff --git a/res/app/components/stf/device/state-classes-service.js b/res/app/components/stf/device/state-classes-service.js index dadf0725..42f33b3e 100644 --- a/res/app/components/stf/device/state-classes-service.js +++ b/res/app/components/stf/device/state-classes-service.js @@ -10,7 +10,8 @@ module.exports = function StateClassesService() { present: 'state-present btn-primary-outline', preparing: 'state-preparing btn-primary-outline btn-success-outline', unauthorized: 'state-unauthorized btn-danger-outline', - offline: 'state-offline btn-warning-outline' + offline: 'state-offline btn-warning-outline', + automation: 'state-automation btn-info' }[state] if (typeof stateClasses === 'undefined') { stateClasses = 'btn-default-outline' @@ -27,7 +28,8 @@ module.exports = function StateClassesService() { present: 'state-present', preparing: 'state-preparing', unauthorized: 'state-unauthorized', - offline: 'state-offline' + offline: 'state-offline', + automation: 'state-automation' }[state] if (typeof stateClasses === 'undefined') { stateClasses = '' @@ -37,4 +39,3 @@ module.exports = function StateClassesService() { return service } - diff --git a/res/app/device-list/column/device-column-service.js b/res/app/device-list/column/device-column-service.js index 750fb42b..3a6d3430 100644 --- a/res/app/device-list/column/device-column-service.js +++ b/res/app/device-list/column/device-column-service.js @@ -571,6 +571,7 @@ function DeviceStatusCell(options) { , preparing: 'state-preparing btn-primary-outline btn-success-outline' , unauthorized: 'state-unauthorized btn-danger-outline' , offline: 'state-offline btn-warning-outline' + , automation: 'state-automation btn-info' } return _.defaults(options, { diff --git a/res/app/device-list/icons/device-list-icons-directive.js b/res/app/device-list/icons/device-list-icons-directive.js index f77bc16c..084ff454 100644 --- a/res/app/device-list/icons/device-list-icons-directive.js +++ b/res/app/device-list/icons/device-list-icons-directive.js @@ -66,7 +66,8 @@ module.exports = function DeviceListIconsDirective( present: 'state-present btn-primary-outline', preparing: 'state-preparing btn-primary-outline btn-success-outline', unauthorized: 'state-unauthorized btn-danger-outline', - offline: 'state-offline btn-warning-outline' + offline: 'state-offline btn-warning-outline', + automation: 'state-automation btn-info' }[state] if (typeof stateClasses === 'undefined') { stateClasses = 'btn-default-outline'