mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Make screenshots work again.
This commit is contained in:
parent
19f38456b8
commit
8da6297350
1 changed files with 54 additions and 1 deletions
|
@ -5,15 +5,21 @@ var http = require('http')
|
|||
var Promise = require('bluebird')
|
||||
var syrup = require('stf-syrup')
|
||||
var httpProxy = require('http-proxy')
|
||||
var adbkit = require('adbkit')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var lifecycle = require('../../../util/lifecycle')
|
||||
var streamutil = require('../../../util/streamutil')
|
||||
var wire = require('../../../wire')
|
||||
var wireutil = require('../../../wire/util')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
.dependency(require('../support/router'))
|
||||
.dependency(require('../support/push'))
|
||||
.dependency(require('../support/storage'))
|
||||
.dependency(require('../resources/minicap'))
|
||||
.define(function(options, adb, minicap) {
|
||||
.define(function(options, adb, router, push, storage, minicap) {
|
||||
var log = logger.createLogger('device:plugins:screen')
|
||||
var plugin = Object.create(null)
|
||||
|
||||
|
@ -110,6 +116,53 @@ module.exports = syrup.serial()
|
|||
})
|
||||
}
|
||||
|
||||
plugin.capture = function() {
|
||||
log.info('Capturing screenshot')
|
||||
|
||||
var file = util.format('/data/local/tmp/minicap_%d.jpg', Date.now())
|
||||
return run(util.format('-s >%s', file))
|
||||
.then(adbkit.util.readAll)
|
||||
.then(function() {
|
||||
return adb.stat(options.serial, file)
|
||||
})
|
||||
.then(function(stats) {
|
||||
if (stats.size === 0) {
|
||||
throw new Error('Empty screenshot; possibly secure screen?')
|
||||
}
|
||||
|
||||
return adb.pull(options.serial, file)
|
||||
.then(function(transfer) {
|
||||
return storage.store('image', transfer, {
|
||||
filename: util.format('%s.jpg', options.serial)
|
||||
, contentType: 'image/jpeg'
|
||||
, knownLength: stats.size
|
||||
})
|
||||
})
|
||||
})
|
||||
.finally(function() {
|
||||
return adb.shell(options.serial, ['rm', '-f', file])
|
||||
.then(adbkit.util.readAll)
|
||||
})
|
||||
}
|
||||
|
||||
router.on(wire.ScreenCaptureMessage, function(channel) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
plugin.capture()
|
||||
.then(function(file) {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay('success', file)
|
||||
])
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Screen capture failed', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail(err.message)
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
return startService()
|
||||
.then(forwardService)
|
||||
.then(startProxy)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue