Document and cleanup announcement/dialog/handlers.js

This commit is contained in:
Feross Aboukhadijeh
2016-05-28 18:25:25 -07:00
parent 5767d5b95d
commit 8b773c5f59
3 changed files with 64 additions and 26 deletions

View File

@@ -11,21 +11,36 @@ var ANNOUNCEMENT_URL = config.ANNOUNCEMENT_URL +
'?version=' + config.APP_VERSION +
'&platform=' + process.platform
/**
* In certain situations, the WebTorrent team may need to show an announcement to
* all WebTorrent Desktop users. For example: a security notice, or an update
* notification (if the auto-updater stops working).
*
* When there is an announcement, the `ANNOUNCEMENT_URL` endpoint should return an
* HTTP 200 status code with a JSON object like this:
*
* {
* "title": "WebTorrent Desktop Announcement",
* "message": "Security Issue in v0.xx",
* "detail": "Please update to v0.xx as soon as possible..."
* }
*/
function init () {
var get = require('simple-get')
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')
if (err) return log(`Failed to retrieve announcement: ${err.message}`)
if (res.statusCode !== 200) return log('No announcement exists')
try {
data = JSON.parse(data.toString())
} catch (err) {
// Support plaintext announcement messages, using a default title.
data = {
title: 'WebTorrent Desktop Announcement',
message: 'Announcement',
message: data.toString(),
detail: data.toString()
}
}

View File

@@ -8,38 +8,46 @@ module.exports = {
var electron = require('electron')
var windows = require('./windows')
// Prompts the user for a file, then creates a torrent. Only allows a single file
// selection.
/**
* Show open dialog to create a single-file torrent.
*/
function openSeedFile () {
electron.dialog.showOpenDialog({
var opts = {
title: 'Select a file for the torrent file.',
properties: [ 'openFile' ]
}, function (selectedPaths) {
}
electron.dialog.showOpenDialog(opts, function (selectedPaths) {
if (!Array.isArray(selectedPaths)) return
windows.main.send('dispatch', 'showCreateTorrent', selectedPaths)
})
}
// Prompts the user for a file or directory, then creates a torrent. Only allows a
// single selection. To create a multi-file torrent, the user must select a
// directory.
/*
* Show open dialog to create a single-file or single-directory torrent. On
* Windows and Linux, open dialogs are for files *or* directories only, not both.
* This function shows a directory dialog.
*/
function openSeedDirectory () {
electron.dialog.showOpenDialog({
var opts = {
title: 'Select a file or folder for the torrent file.',
properties: [ 'openFile', 'openDirectory' ]
}, function (selectedPaths) {
}
electron.dialog.showOpenDialog(opts, function (selectedPaths) {
if (!Array.isArray(selectedPaths)) return
windows.main.send('dispatch', 'showCreateTorrent', selectedPaths)
})
}
// Prompts the user to choose a torrent file, then adds it.
/*
* Show open dialog to open a .torrent file.
*/
function openTorrentFile () {
electron.dialog.showOpenDialog(windows.main.win, {
var opts = {
title: 'Select a .torrent file to open.',
filters: [{ name: 'Torrent Files', extensions: ['torrent'] }],
properties: [ 'openFile', 'multiSelections' ]
}, function (selectedPaths) {
}
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
if (!Array.isArray(selectedPaths)) return
selectedPaths.forEach(function (selectedPath) {
windows.main.send('dispatch', 'addTorrent', selectedPath)
@@ -47,7 +55,9 @@ function openTorrentFile () {
})
}
// Prompts the user for the URL of a torrent file, then downloads and adds it
/*
* Show modal dialog to open a torrent URL (magnet uri, http torrent link, etc.)
*/
function openTorrentAddress () {
windows.main.send('showOpenTorrentAddress')
}

View File

@@ -3,9 +3,8 @@ module.exports = {
uninstall
}
var path = require('path')
var config = require('../config')
var path = require('path')
function install () {
if (process.platform === 'darwin') {
@@ -35,11 +34,11 @@ function installDarwin () {
var electron = require('electron')
var app = electron.app
// On OS X, only protocols that are listed in Info.plist can be set as the default
// handler at runtime.
// On OS X, only protocols that are listed in `Info.plist` can be set as the
// default handler at runtime.
app.setAsDefaultProtocolClient('magnet')
// File handlers are registered in the Info.plist.
// File handlers are defined in `Info.plist`.
}
function uninstallDarwin () {}
@@ -55,10 +54,22 @@ function installWin32 () {
var log = require('./log')
var iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
registerProtocolHandlerWin32('magnet', 'URL:BitTorrent Magnet URL', iconPath, EXEC_COMMAND)
registerFileHandlerWin32('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', iconPath, EXEC_COMMAND)
var iconPath = path.join(
process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico'
)
registerProtocolHandlerWin32(
'magnet',
'URL:BitTorrent Magnet URL',
iconPath,
EXEC_COMMAND
)
registerFileHandlerWin32(
'.torrent',
'io.webtorrent.torrent',
'BitTorrent Document',
iconPath,
EXEC_COMMAND
)
/**
* To add a protocol handler, the following keys must be added to the Windows registry:
@@ -265,7 +276,9 @@ function installLinux () {
installIconFile()
function installDesktopFile () {
var templatePath = path.join(config.STATIC_PATH, 'linux', 'webtorrent-desktop.desktop')
var templatePath = path.join(
config.STATIC_PATH, 'linux', 'webtorrent-desktop.desktop'
)
fs.readFile(templatePath, 'utf8', writeDesktopFile)
}