From f1c27f2a693a3faa44236d0216d84413d7e38651 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 20 Mar 2016 00:11:44 -0700 Subject: [PATCH 1/4] config.COPYRIGHT --- bin/package.js | 7 +++---- config.js | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/package.js b/bin/package.js index 72b2df38..3983aace 100755 --- a/bin/package.js +++ b/bin/package.js @@ -93,9 +93,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.COPYRIGHT, // Name of the program, displayed to users FileDescription: config.APP_NAME, @@ -176,7 +175,7 @@ function buildDarwin (cb) { } ] - infoPlist.NSHumanReadableCopyright = 'Copyright © 2014-2016 The WebTorrent Project' + infoPlist.NSHumanReadableCopyright = config.COPYRIGHT fs.writeFileSync(infoPlistPath, plist.build(infoPlist)) cp.execSync(`cp ${webTorrentFileIconPath} ${resourcesPath}`) diff --git a/config.js b/config.js index f8c65135..cf1031d8 100644 --- a/config.js +++ b/config.js @@ -9,6 +9,8 @@ module.exports = { CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'Posters'), CONFIG_TORRENT_PATH: path.join(applicationConfigPath('WebTorrent'), 'Torrents'), + COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project', + INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'), IS_PRODUCTION: isProduction(), From 1022d616d24975bc0b1d2f981d2f2c80db55e12e Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 20 Mar 2016 00:52:02 -0700 Subject: [PATCH 2/4] Unpack icon files so setting browserWindow.icon works --- bin/package.js | 14 +++++++++----- config.js | 12 +++++++++++- main/windows.js | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bin/package.js b/bin/package.js index 3983aace..3b275f62 100755 --- a/bin/package.js +++ b/bin/package.js @@ -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 = { @@ -114,7 +118,7 @@ var win32 = { }, // Application icon. - icon: path.join(__dirname, '..', 'static', 'WebTorrent.ico') + icon: config.APP_ICON + '.ico' } var linux = { @@ -151,7 +155,7 @@ function buildDarwin (cb) { infoPlist.CFBundleDocumentTypes = [ { CFBundleTypeExtensions: [ 'torrent' ], - CFBundleTypeIconFile: 'WebTorrentFile.icns', + CFBundleTypeIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleTypeName: 'BitTorrent Document', CFBundleTypeRole: 'Editor', LSHandlerRank: 'Owner', @@ -169,7 +173,7 @@ function buildDarwin (cb) { infoPlist.CFBundleURLTypes = [ { CFBundleTypeRole: 'Editor', - CFBundleURLIconFile: 'WebTorrentFile.icns', + CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleURLName: 'BitTorrent Magnet URL', CFBundleURLSchemes: [ 'magnet' ] } @@ -178,7 +182,7 @@ function buildDarwin (cb) { infoPlist.NSHumanReadableCopyright = config.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) }) diff --git a/config.js b/config.js index cf1031d8..e9200bbd 100644 --- a/config.js +++ b/config.js @@ -2,7 +2,8 @@ var applicationConfigPath = require('application-config-path') var path = require('path') module.exports = { - APP_ICON: path.join(__dirname, 'static', 'WebTorrent.png'), + APP_FILE_ICON: path.join(pathToStatic(), 'WebTorrentFile'), + APP_ICON: path.join(pathToStatic(), 'WebTorrent'), APP_NAME: 'WebTorrent', CONFIG_PATH: applicationConfigPath('WebTorrent'), @@ -26,6 +27,9 @@ module.exports = { } function isProduction () { + if (!process.versions.electron) { + return false + } if (process.platform === 'darwin') { return !/\/Electron\.app\/Contents\/MacOS\/Electron$/.test(process.execPath) } @@ -36,3 +40,9 @@ function isProduction () { // TODO } } + +function pathToStatic () { + return isProduction() + ? path.join(process.resourcesPath, 'app.asar.unpacked', 'static') + : path.join(__dirname, 'static') +} diff --git a/main/windows.js b/main/windows.js index 17988afd..f56df2b8 100644 --- a/main/windows.js +++ b/main/windows.js @@ -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 From 45b36fb7a1c40602181d47c45ba9a78560c88ffe Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 20 Mar 2016 00:52:24 -0700 Subject: [PATCH 3/4] config.COPYRIGHT -> APP_COPYRIGHT --- bin/package.js | 10 ++-------- config.js | 3 +-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/bin/package.js b/bin/package.js index 3b275f62..c72f8475 100755 --- a/bin/package.js +++ b/bin/package.js @@ -98,7 +98,7 @@ var win32 = { CompanyName: config.APP_NAME, // Copyright notices that apply to the file. - LegalCopyright: config.COPYRIGHT, + LegalCopyright: config.APP_COPYRIGHT, // Name of the program, displayed to users FileDescription: config.APP_NAME, @@ -144,12 +144,6 @@ 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 = [ @@ -179,7 +173,7 @@ function buildDarwin (cb) { } ] - infoPlist.NSHumanReadableCopyright = config.COPYRIGHT + infoPlist.NSHumanReadableCopyright = config.APP_COPYRIGHT fs.writeFileSync(infoPlistPath, plist.build(infoPlist)) cp.execSync(`cp ${config.APP_FILE_ICON + '.icns'} ${resourcesPath}`) diff --git a/config.js b/config.js index e9200bbd..7ded0738 100644 --- a/config.js +++ b/config.js @@ -2,6 +2,7 @@ var applicationConfigPath = require('application-config-path') var path = require('path') module.exports = { + APP_COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project', APP_FILE_ICON: path.join(pathToStatic(), 'WebTorrentFile'), APP_ICON: path.join(pathToStatic(), 'WebTorrent'), APP_NAME: 'WebTorrent', @@ -10,8 +11,6 @@ module.exports = { CONFIG_POSTER_PATH: path.join(applicationConfigPath('WebTorrent'), 'Posters'), CONFIG_TORRENT_PATH: path.join(applicationConfigPath('WebTorrent'), 'Torrents'), - COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project', - INDEX: 'file://' + path.join(__dirname, 'renderer', 'index.html'), IS_PRODUCTION: isProduction(), From fb37b87297aa8a200e87b688bb1ec955051f2eba Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 20 Mar 2016 00:52:54 -0700 Subject: [PATCH 4/4] set windows protocol/file icons --- main/register-protocol-handler.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main/register-protocol-handler.js b/main/register-protocol-handler.js index e84587c7..9b46f6b1 100644 --- a/main/register-protocol-handler.js +++ b/main/register-protocol-handler.js @@ -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'