mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:23:28 +02:00
Add browser list to device identity.
This commit is contained in:
51
lib/roles/device/plugins/browsers.js
Normal file
51
lib/roles/device/plugins/browsers.js
Normal file
@@ -0,0 +1,51 @@
|
||||
var util = require('util')
|
||||
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup()
|
||||
.dependency(require('../support/http'))
|
||||
.dependency(require('./input'))
|
||||
.define(function(options, http, input) {
|
||||
var log = logger.createLogger('device:plugins:browsers')
|
||||
|
||||
log.info('Fetching browser list')
|
||||
return input.getBrowsers()
|
||||
.then(function(browsers) {
|
||||
var icons = Object.create(null)
|
||||
|
||||
browsers.apps.forEach(function(app) {
|
||||
icons[app.component] = app.icon.toBuffer()
|
||||
app.icon = util.format(
|
||||
'%s/api/v1/browsers/%s/icon'
|
||||
, http.get('public url')
|
||||
, app.component
|
||||
)
|
||||
})
|
||||
|
||||
http.get(
|
||||
'/api/v1/browsers/:package/:activity/icon'
|
||||
, function(req, res) {
|
||||
var component = util.format(
|
||||
'%s/%s'
|
||||
, req.params.package
|
||||
, req.params.activity
|
||||
)
|
||||
|
||||
var icon = icons[component]
|
||||
|
||||
if (icon) {
|
||||
res.set('Content-Type', 'image/png')
|
||||
res.set('Content-Length', icon.length)
|
||||
res.send(200, icon)
|
||||
}
|
||||
else {
|
||||
res.send(404)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return browsers
|
||||
})
|
||||
})
|
||||
@@ -6,13 +6,15 @@ var logger = require('../../../util/logger')
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/properties'))
|
||||
.dependency(require('./display'))
|
||||
.define(function(options, properties, display) {
|
||||
.dependency(require('./browsers'))
|
||||
.define(function(options, properties, display, browsers) {
|
||||
var log = logger.createLogger('device:plugins:identity')
|
||||
|
||||
function solve() {
|
||||
log.info('Solving identity')
|
||||
var identity = devutil.makeIdentity(options.serial, properties)
|
||||
identity.display = display
|
||||
identity.browsers = browsers
|
||||
return identity
|
||||
}
|
||||
|
||||
|
||||
@@ -293,6 +293,21 @@ module.exports = syrup.serial()
|
||||
})
|
||||
}
|
||||
|
||||
function getBrowsers() {
|
||||
return runServiceCommand(
|
||||
apk.serviceProto.RequestType.GET_BROWSERS
|
||||
, new apk.serviceProto.GetBrowsersRequest()
|
||||
)
|
||||
.then(function(data) {
|
||||
var response = apk.serviceProto.GetBrowsersResponse.decode(data)
|
||||
if (response.success) {
|
||||
delete response.success
|
||||
return response
|
||||
}
|
||||
throw new Error('Unable to get browser list')
|
||||
})
|
||||
}
|
||||
|
||||
function runServiceCommand(type, cmd) {
|
||||
var resolver = Promise.defer()
|
||||
service.writer.write(new apk.serviceProto.RequestEnvelope(
|
||||
@@ -361,6 +376,7 @@ module.exports = syrup.serial()
|
||||
})
|
||||
}
|
||||
, copy: getClipboard
|
||||
, getBrowsers: getBrowsers
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -42,6 +42,17 @@ module.exports = syrup.serial()
|
||||
, identity.display.secure
|
||||
, identity.display.url
|
||||
)
|
||||
, new wire.DeviceBrowsersMessage(
|
||||
identity.browsers.selected
|
||||
, identity.browsers.apps.map(function(app) {
|
||||
return new wire.DeviceBrowserAppMessage(
|
||||
app.name
|
||||
, app.component
|
||||
, app.selected
|
||||
, app.icon
|
||||
)
|
||||
})
|
||||
)
|
||||
))
|
||||
])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user