Use wireutil.reply() where possible.

This commit is contained in:
Simo Kinnunen
2014-04-11 14:54:19 +09:00
parent 90b39306a8
commit 7f74ecd7af
8 changed files with 32 additions and 128 deletions

View File

@@ -13,57 +13,38 @@ module.exports = syrup.serial()
router.on(wire.PasteMessage, function(channel, message) {
log.info('Pasting "%s" to clipboard', message.text)
var seq = 0
var reply = wireutil.reply(options.serial)
input.paste(message.text)
.then(function() {
push.send([
channel
, wireutil.envelope(new wire.TransactionDoneMessage(
options.serial
, seq++
, true
))
, reply.okay()
])
})
.catch(function(err) {
log.error('Paste failed', err.stack)
push.send([
channel
, wireutil.envelope(new wire.TransactionDoneMessage(
options.serial
, seq++
, false
, err.message
))
, reply.fail(err.message)
])
})
})
router.on(wire.CopyMessage, function(channel) {
log.info('Copying clipboard contents')
var seq = 0
var reply = wireutil.reply(options.serial)
input.copy()
.then(function(content) {
push.send([
channel
, wireutil.envelope(new wire.TransactionDoneMessage(
options.serial
, seq++
, true
, content
))
, reply.okay(content)
])
})
.catch(function(err) {
log.error('Copy failed', err.stack)
push.send([
channel
, wireutil.envelope(new wire.TransactionDoneMessage(
options.serial
, seq++
, false
, err.message
))
, reply.fail(err.message)
])
})
})