mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
URLs can now be opened.
This commit is contained in:
@@ -1,51 +1,63 @@
|
||||
var util = require('util')
|
||||
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var wire = require('../../../wire')
|
||||
var wireutil = require('../../../wire/util')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/http'))
|
||||
.dependency(require('../support/router'))
|
||||
.dependency(require('../support/push'))
|
||||
.dependency(require('../support/adb'))
|
||||
.dependency(require('./input'))
|
||||
.define(function(options, http, input) {
|
||||
.define(function(options, router, push, adb, input) {
|
||||
var log = logger.createLogger('device:plugins:browsers')
|
||||
|
||||
log.info('Fetching browser list')
|
||||
return input.getBrowsers()
|
||||
.timeout(15000)
|
||||
.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
|
||||
)
|
||||
var pkg = app.component.split('/', 1)[0]
|
||||
|
||||
switch (pkg) {
|
||||
case 'com.android.chrome':
|
||||
app.type = 'chrome'
|
||||
break
|
||||
case 'com.sec.android.app.sbrowser':
|
||||
app.type = 'samsung-chrome'
|
||||
break
|
||||
case 'com.android.browser':
|
||||
app.type = 'default'
|
||||
break
|
||||
}
|
||||
|
||||
app.id = app.component
|
||||
|
||||
delete app.icon
|
||||
delete 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)
|
||||
}
|
||||
}
|
||||
)
|
||||
router.on(wire.BrowserOpenMessage, function(channel, message) {
|
||||
var reply = wireutil.reply(options.serial)
|
||||
adb.startActivity(options.serial, {
|
||||
action: 'android.intent.action.VIEW'
|
||||
, component: message.browser
|
||||
, data: message.url
|
||||
})
|
||||
.then(function() {
|
||||
push.send([
|
||||
channel
|
||||
, reply.okay()
|
||||
])
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Browser could not be opened', err.stack)
|
||||
push.send([
|
||||
channel
|
||||
, reply.fail()
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
return browsers
|
||||
})
|
||||
|
||||
@@ -46,10 +46,10 @@ module.exports = syrup.serial()
|
||||
identity.browsers.selected
|
||||
, identity.browsers.apps.map(function(app) {
|
||||
return new wire.DeviceBrowserAppMessage(
|
||||
app.name
|
||||
, app.component
|
||||
app.id
|
||||
, app.type
|
||||
, app.name
|
||||
, app.selected
|
||||
, app.icon
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user