Implement clearBrowser().

This commit is contained in:
Simo Kinnunen
2014-04-22 13:52:13 +09:00
parent d037f45b29
commit 1f19fd58c1
4 changed files with 44 additions and 5 deletions

View File

@@ -12,14 +12,16 @@ module.exports = syrup.serial()
.define(function(options, router, push, adb, input) {
var log = logger.createLogger('device:plugins:browsers')
function pkg(component) {
return component.split('/', 1)[0]
}
log.info('Fetching browser list')
return input.getBrowsers()
.timeout(15000)
.then(function(browsers) {
browsers.apps.forEach(function(app) {
var pkg = app.component.split('/', 1)[0]
switch (pkg) {
switch (pkg(app.component)) {
case 'com.android.chrome':
app.type = 'chrome'
break
@@ -66,6 +68,24 @@ module.exports = syrup.serial()
})
})
router.on(wire.BrowserClearMessage, function(channel, message) {
var reply = wireutil.reply(options.serial)
adb.clear(options.serial, pkg(message.browser))
.then(function() {
push.send([
channel
, reply.okay()
])
})
.catch(function(err) {
log.error('Browser could not be cleared', err.stack)
push.send([
channel
, reply.fail()
])
})
})
return browsers
})
})