From 22cdcdb468d089a0c8b07e85fea34fca72d3cf18 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 May 2016 20:03:02 -0700 Subject: [PATCH 1/4] Add announcement feature If there's a message returned by the given remote URL, then it will show up for the user. Useful in situations where the auto-updater is not working, or if there's a security issue. --- config.js | 2 ++ main/announcement.js | 27 +++++++++++++++++++++++++++ main/index.js | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 main/announcement.js diff --git a/config.js b/config.js index db96cfab..95da64fc 100644 --- a/config.js +++ b/config.js @@ -9,6 +9,8 @@ var APP_VERSION = require('./package.json').version var PORTABLE_PATH = path.join(path.dirname(process.execPath), 'Portable Settings') module.exports = { + ANNOUNCEMENT_URL: 'https://webtorrent.io/desktop/announcement', + APP_COPYRIGHT: 'Copyright © 2014-2016 ' + APP_TEAM, APP_FILE_ICON: path.join(__dirname, 'static', 'WebTorrentFile'), APP_ICON: path.join(__dirname, 'static', 'WebTorrent'), diff --git a/main/announcement.js b/main/announcement.js new file mode 100644 index 00000000..a68f005f --- /dev/null +++ b/main/announcement.js @@ -0,0 +1,27 @@ +module.exports = { + init +} + +var electron = require('electron') +var get = require('simple-get') + +var config = require('../config') +var log = require('./log') + +var ANNOUNCEMENT_URL = config.ANNOUNCEMENT_URL + + '?version=' + config.APP_VERSION + + '&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') + + electron.dialog.showMessageBox({ + type: 'info', + buttons: ['OK'], + title: 'WebTorrent Desktop Announcement', + message: data.toString() + }) + }) +} diff --git a/main/index.js b/main/index.js index 6b6f63bf..83a3f5dc 100644 --- a/main/index.js +++ b/main/index.js @@ -5,6 +5,7 @@ var electron = require('electron') var app = electron.app var ipcMain = electron.ipcMain +var announcement = require('./announcement') var config = require('../config') var crashReporter = require('../crash-reporter') var handlers = require('./handlers') @@ -91,6 +92,7 @@ function init () { } function delayedInit () { + announcement.init() tray.init() handlers.install() updater.init() From 4e46b16c1352e455cbf98dfa7204f5fc4a1cb75f Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 May 2016 20:03:37 -0700 Subject: [PATCH 2/4] auto updater: code style --- config.js | 3 +-- main/updater.js | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index 95da64fc..ace04e58 100644 --- a/config.js +++ b/config.js @@ -19,8 +19,7 @@ module.exports = { APP_VERSION: APP_VERSION, APP_WINDOW_TITLE: APP_NAME + ' (BETA)', - AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update' + - '?version=' + APP_VERSION + '&platform=' + process.platform, + AUTO_UPDATE_URL: 'https://webtorrent.io/desktop/update', CRASH_REPORT_URL: 'https://webtorrent.io/desktop/crash-report', diff --git a/main/updater.js b/main/updater.js index 5cdc54f9..71f8922b 100644 --- a/main/updater.js +++ b/main/updater.js @@ -9,6 +9,10 @@ var config = require('../config') var log = require('./log') var windows = require('./windows') +var AUTO_UPDATE_URL = config.AUTO_UPDATE_URL + + '?version=' + config.APP_VERSION + + '&platform=' + process.platform + function init () { if (process.platform === 'linux') { initLinux() @@ -20,7 +24,7 @@ function init () { // The Electron auto-updater does not support Linux yet, so manually check for updates and // `show the user a modal notification. function initLinux () { - get.concat(config.AUTO_UPDATE_URL, onResponse) + get.concat(AUTO_UPDATE_URL, onResponse) function onResponse (err, res, data) { if (err) return log(`Update error: ${err.message}`) @@ -67,6 +71,6 @@ function initDarwinWin32 () { (e, notes, name, date, url) => log(`Update downloaded: ${name}: ${url}`) ) - electron.autoUpdater.setFeedURL(config.AUTO_UPDATE_URL) + electron.autoUpdater.setFeedURL(AUTO_UPDATE_URL) electron.autoUpdater.checkForUpdates() } From 47c554a5ffa52d7c2a24ab3143a977edc99e1c8e Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 May 2016 20:17:51 -0700 Subject: [PATCH 3/4] Announcement: Support custom window title, main message, details --- main/announcement.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main/announcement.js b/main/announcement.js index a68f005f..b653e3dc 100644 --- a/main/announcement.js +++ b/main/announcement.js @@ -17,11 +17,22 @@ function init () { 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: 'WebTorrent Desktop Announcement', - message: data.toString() + title: data.title, + message: data.message, + detail: data.detail }) }) } From 84c860cfcb75850db21da0d2f8c8bf82ba94e9c3 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 19 May 2016 20:24:25 -0700 Subject: [PATCH 4/4] Make dialog async --- main/announcement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/announcement.js b/main/announcement.js index b653e3dc..1e2801d5 100644 --- a/main/announcement.js +++ b/main/announcement.js @@ -33,6 +33,6 @@ function init () { title: data.title, message: data.message, detail: data.detail - }) + }, function () {}) }) }