1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Move utility plugins into their own folder. They don't go into the support folder because they're not standalone units and require interaction with the main units. Further refactoring pending.

This commit is contained in:
Simo Kinnunen 2015-07-28 15:59:02 +09:00
parent 252f778598
commit 361bf9caea
13 changed files with 20 additions and 22 deletions

View file

@ -0,0 +1,71 @@
var util = require('util')
var syrup = require('stf-syrup')
var EventEmitter = require('eventemitter3').EventEmitter
var logger = require('../../../../util/logger')
var streamutil = require('../../../../util/streamutil')
module.exports = syrup.serial()
.dependency(require('../../support/adb'))
.dependency(require('../../resources/minicap'))
.dependency(require('../service'))
.dependency(require('../screen/options'))
.define(function(options, adb, minicap, service, screenOptions) {
var log = logger.createLogger('device:plugins:display')
function Display(id, properties) {
this.id = id
this.properties = properties
}
util.inherits(Display, EventEmitter)
Display.prototype.updateRotation = function(newRotation) {
log.info('Rotation changed to %d', newRotation)
this.properties.rotation = newRotation
this.emit('rotationChange', newRotation)
}
function infoFromMinicap(id) {
return minicap.run(util.format('-d %d -i', id))
.then(streamutil.readAll)
.then(function(out) {
var match
if ((match = /^ERROR: (.*)$/.exec(out))) {
throw new Error(match[1])
}
try {
return JSON.parse(out)
}
catch (e) {
throw new Error(out.toString())
}
})
}
function infoFromService(id) {
return service.getDisplay(id)
}
function readInfo(id) {
log.info('Reading display info')
return infoFromService(id)
.catch(function() {
return infoFromMinicap(id)
})
.then(function(properties) {
properties.url = screenOptions.publicUrl
return new Display(id, properties)
})
}
return readInfo(0).then(function(display) {
service.on('rotationChange', function(data) {
display.updateRotation(data.rotation)
})
return display
})
})