Merge pull request #172 from feross/windows-torrent-handler

Set Windows protocol/file handler icons; unpack icon for browserWindow.icon
This commit is contained in:
Feross Aboukhadijeh
2016-03-20 01:14:04 -07:00
4 changed files with 43 additions and 21 deletions

View File

@@ -41,6 +41,10 @@ var all = {
// require().
asar: true,
// A glob expression, that unpacks the files with matching names to the
// "app.asar.unpacked" directory.
'asar-unpack': 'WebTorrent*',
// The build version of the application. Maps to the FileVersion metadata property on
// Windows, and CFBundleVersion on OS X. We're using the short git hash (e.g. 'e7d837e')
// Windows requires the build version to start with a number :/ so we stick on a prefix
@@ -81,7 +85,7 @@ var darwin = {
'helper-bundle-id': 'io.webtorrent.app.helper',
// Application icon.
icon: path.join(__dirname, '..', 'static', 'WebTorrent.icns')
icon: config.APP_ICON + '.icns'
}
var win32 = {
@@ -93,9 +97,8 @@ var win32 = {
// Company that produced the file.
CompanyName: config.APP_NAME,
// Copyright notices that apply to the file. This should include the full text of all
// notices, legal symbols, copyright dates, and so on.
LegalCopyright: fs.readFileSync(path.join(__dirname, '..', 'LICENSE'), 'utf8'),
// Copyright notices that apply to the file.
LegalCopyright: config.APP_COPYRIGHT,
// Name of the program, displayed to users
FileDescription: config.APP_NAME,
@@ -115,7 +118,7 @@ var win32 = {
},
// Application icon.
icon: path.join(__dirname, '..', 'static', 'WebTorrent.ico')
icon: config.APP_ICON + '.ico'
}
var linux = {
@@ -141,18 +144,12 @@ function buildDarwin (cb) {
)
var resourcesPath = path.join(contentsPath, 'Resources')
var infoPlistPath = path.join(contentsPath, 'Info.plist')
var webTorrentFileIconPath = path.join(
__dirname,
'..',
'static',
'WebTorrentFile.icns'
)
var infoPlist = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'))
infoPlist.CFBundleDocumentTypes = [
{
CFBundleTypeExtensions: [ 'torrent' ],
CFBundleTypeIconFile: 'WebTorrentFile.icns',
CFBundleTypeIconFile: path.basename(config.APP_FILE_ICON) + '.icns',
CFBundleTypeName: 'BitTorrent Document',
CFBundleTypeRole: 'Editor',
LSHandlerRank: 'Owner',
@@ -170,16 +167,16 @@ function buildDarwin (cb) {
infoPlist.CFBundleURLTypes = [
{
CFBundleTypeRole: 'Editor',
CFBundleURLIconFile: 'WebTorrentFile.icns',
CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns',
CFBundleURLName: 'BitTorrent Magnet URL',
CFBundleURLSchemes: [ 'magnet' ]
}
]
infoPlist.NSHumanReadableCopyright = 'Copyright © 2014-2016 The WebTorrent Project'
infoPlist.NSHumanReadableCopyright = config.APP_COPYRIGHT
fs.writeFileSync(infoPlistPath, plist.build(infoPlist))
cp.execSync(`cp ${webTorrentFileIconPath} ${resourcesPath}`)
cp.execSync(`cp ${config.APP_FILE_ICON + '.icns'} ${resourcesPath}`)
if (cb) cb(null)
})

View File

@@ -2,7 +2,9 @@ var applicationConfigPath = require('application-config-path')
var path = require('path')
module.exports = {
APP_ICON: path.join(__dirname, 'static', 'WebTorrent.png'),
APP_COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project',
APP_FILE_ICON: path.join(pathToStatic(), 'WebTorrentFile'),
APP_ICON: path.join(pathToStatic(), 'WebTorrent'),
APP_NAME: 'WebTorrent',
CONFIG_PATH: applicationConfigPath('WebTorrent'),
@@ -24,6 +26,9 @@ module.exports = {
}
function isProduction () {
if (!process.versions.electron) {
return false
}
if (process.platform === 'darwin') {
return !/\/Electron\.app\/Contents\/MacOS\/Electron$/.test(process.execPath)
}
@@ -34,3 +39,9 @@ function isProduction () {
// TODO
}
}
function pathToStatic () {
return isProduction()
? path.join(process.resourcesPath, 'app.asar.unpacked', 'static')
: path.join(__dirname, 'static')
}

View File

@@ -1,7 +1,9 @@
var config = require('../config')
module.exports = function () {
if (process.platform === 'win32') {
registerProtocolHandler('magnet', 'BitTorrent Magnet URL', process.execPath)
registerFileHandler('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', process.execPath)
registerProtocolHandler('magnet', 'BitTorrent Magnet URL', config.APP_FILE_ICON + '.ico', process.execPath)
registerFileHandler('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', config.APP_FILE_ICON + '.ico', process.execPath)
}
}
@@ -25,7 +27,7 @@ module.exports = function () {
* "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
*/
function registerProtocolHandler (protocol, name, command) {
function registerProtocolHandler (protocol, name, icon, command) {
var Registry = require('winreg')
var protocolKey = new Registry({
@@ -35,6 +37,12 @@ function registerProtocolHandler (protocol, name, command) {
protocolKey.set('', Registry.REG_SZ, 'URL:' + name, callback)
protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback)
var iconKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + protocol + '\\DefaultIcon'
})
iconKey.set('', Registry.REG_SZ, icon, callback)
var commandKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + protocol + '\\shell\\open\\command'
@@ -46,7 +54,7 @@ function registerProtocolHandler (protocol, name, command) {
}
}
function registerFileHandler (ext, id, name, command) {
function registerFileHandler (ext, id, name, icon, command) {
var Registry = require('winreg')
var extKey = new Registry({
@@ -61,6 +69,12 @@ function registerFileHandler (ext, id, name, command) {
})
idKey.set('', Registry.REG_SZ, name, callback)
var iconKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + id + '\\DefaultIcon'
})
iconKey.set('', Registry.REG_SZ, icon, callback)
var commandKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + id + '\\shell\\open\\command'

View File

@@ -16,7 +16,7 @@ function createMainWindow () {
autoHideMenuBar: true, // Hide top menu bar unless Alt key is pressed (Windows, Linux)
backgroundColor: '#282828',
darkTheme: true, // Forces dark theme (GTK+3)
icon: config.APP_ICON,
icon: config.APP_ICON + '.png',
minWidth: 375,
minHeight: 38 + (120 * 2), // header height + 2 torrents
show: false, // Hide window until DOM finishes loading