Skip to content

Commit

Permalink
Catch errors directly when copying to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Mar 8, 2017
1 parent 343daa3 commit f0fd992
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/listening.js
Expand Up @@ -8,15 +8,6 @@ const {coroutine, promisify} = require('bluebird')

const copyAsync = promisify(copy)

const copyToClipboard = coroutine(function * (text) {
try {
yield copyAsync(text)
return true
} catch (err) {
return false
}
})

module.exports = coroutine(function * (server, current, inUse) {
const details = server.address()
const isTTY = process.stdout.isTTY
Expand Down Expand Up @@ -44,22 +35,20 @@ module.exports = coroutine(function * (server, current, inUse) {
message += '\n\n'

const localURL = `http://localhost:${details.port}`

message += `- ${chalk.bold('Local: ')} ${localURL}`

try {
const ipAddress = ip.address()
const url = `http://${ipAddress}:${details.port}`

message += `\n\n- ${chalk.bold('On Your Network: ')} ${url}`
message += `\n- ${chalk.bold('On Your Network: ')} ${url}`
} catch (err) {}

if (isTTY && process.platform === 'darwin') {
const copied = yield copyToClipboard(localURL)

if (copied) {
if (isTTY) {
try {
yield copyAsync(localURL)
message += `\n\n${chalk.grey('Copied local address to clipboard!')}`
}
} catch (err) {}
}

console.log(boxen(message, {
Expand Down

0 comments on commit f0fd992

Please sign in to comment.