From 3757507b180197a6614fc6e8da09ee7edebd8823 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 26 May 2016 18:41:48 -0700 Subject: [PATCH] cleanup announcement --- main/announcement.js | 48 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/main/announcement.js b/main/announcement.js index 1e2801d5..1959b886 100644 --- a/main/announcement.js +++ b/main/announcement.js @@ -13,26 +13,30 @@ var ANNOUNCEMENT_URL = config.ANNOUNCEMENT_URL + '&platform=' + process.platform function init () { - get.concat(ANNOUNCEMENT_URL, function (err, res, data) { - if (err) return log('failed to retrieve remote message') - if (res.statusCode !== 200) return log('no remote message') - - try { - data = JSON.parse(data.toString()) - } catch (err) { - data = { - title: 'WebTorrent Desktop Announcement', - message: 'WebTorrent Desktop Announcement', - detail: data.toString() - } - } - - electron.dialog.showMessageBox({ - type: 'info', - buttons: ['OK'], - title: data.title, - message: data.message, - detail: data.detail - }, function () {}) - }) + get.concat(ANNOUNCEMENT_URL, onResponse) } + +function onResponse (err, res, data) { + if (err) return log('failed to retrieve remote message') + if (res.statusCode !== 200) return log('no remote message') + + try { + data = JSON.parse(data.toString()) + } catch (err) { + data = { + title: 'WebTorrent Desktop Announcement', + message: 'Announcement', + detail: data.toString() + } + } + + electron.dialog.showMessageBox({ + type: 'info', + buttons: ['OK'], + title: data.title, + message: data.message, + detail: data.detail + }, noop) +} + +function noop () {}