From aff402f6e01db1d0421078b8249ffbe2ef8714d2 Mon Sep 17 00:00:00 2001 From: Julen Garcia Leunda Date: Mon, 9 Sep 2019 22:24:49 +0200 Subject: [PATCH 1/3] Replace nobin-debian-installer --- bin/package.js | 53 ++++----- package-lock.json | 146 ++++++++++++++++++++++++ package.json | 2 +- src/main/handlers.js | 101 ---------------- static/linux/postinst | 4 - static/linux/prerm | 3 - static/linux/webtorrent-desktop.desktop | 29 ----- static/linux/webtorrent-desktop.ejs | 26 +++++ 8 files changed, 197 insertions(+), 167 deletions(-) delete mode 100644 static/linux/postinst delete mode 100644 static/linux/prerm delete mode 100644 static/linux/webtorrent-desktop.desktop create mode 100644 static/linux/webtorrent-desktop.ejs diff --git a/bin/package.js b/bin/package.js index d87dd616a1..a84da15edc 100755 --- a/bin/package.js +++ b/bin/package.js @@ -501,35 +501,30 @@ function buildLinux (cb) { // Create .deb file for Debian-based platforms console.log('Linux: Creating deb...') - const deb = require('nobin-debian-installer')() - const destPath = path.join('/opt', pkg.name) - - deb.pack({ - package: pkg, - info: { - arch: 'amd64', - targetDir: DIST_PATH, - depends: 'gconf2, libgtk2.0-0, libnss3, libxss1', - scripts: { - postinst: path.join(config.STATIC_PATH, 'linux', 'postinst'), - prerm: path.join(config.STATIC_PATH, 'linux', 'prerm') - } - } - }, [{ - src: ['./**'], - dest: destPath, - expand: true, - cwd: filesPath - }, { - src: ['./**'], - dest: path.join('/usr', 'share'), - expand: true, - cwd: path.join(config.STATIC_PATH, 'linux', 'share') - }], function (err) { - if (err) return cb(err) - console.log('Linux: Created deb.') - cb(null) - }) + const installer = require('electron-installer-debian') + + const options = { + src: filesPath + '/', + dest: DIST_PATH, + arch: 'amd64', + bin: 'WebTorrent', + icon: { + '48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'), + '256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png') + }, + categories: ['Network', 'FileTransfer', 'P2P'], + mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'], + desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs') + } + + installer(options) + .then(function () { + console.log('Linux: Created deb.') + cb(null) + }) + .catch(function (err) { + cb(err) + }) } function packageZip (filesPath, cb) { diff --git a/package-lock.json b/package-lock.json index e670fe4a2d..698246e26e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2081,6 +2081,15 @@ "which": "^1.2.9" } }, + "cross-spawn-promise": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/cross-spawn-promise/-/cross-spawn-promise-0.10.1.tgz", + "integrity": "sha1-25y0xQxgtyoVvgSbeBIs44LYexA=", + "dev": true, + "requires": { + "cross-spawn": "^5.1.0" + } + }, "cross-zip": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/cross-zip/-/cross-zip-2.1.6.tgz", @@ -2625,6 +2634,115 @@ } } }, + "electron-installer-common": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/electron-installer-common/-/electron-installer-common-0.7.3.tgz", + "integrity": "sha512-l4chYFTWr6uWODKYUXeC+Z4tqGa3b8e+Y2WUBf3F7Ruv6yYzZ+Ccic65oXreeotx09B7sUx1KTuwXRsRJHKlMw==", + "dev": true, + "requires": { + "asar": "^2.0.1", + "cross-spawn-promise": "^0.10.1", + "debug": "^4.1.1", + "fs-extra": "^8.0.1", + "glob": "^7.1.4", + "lodash": "^4.17.11", + "parse-author": "^2.0.0", + "semver": "^6.0.0", + "tmp-promise": "^2.0.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "tmp-promise": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-2.0.2.tgz", + "integrity": "sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q==", + "dev": true, + "requires": { + "tmp": "0.1.0" + } + } + } + }, + "electron-installer-debian": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/electron-installer-debian/-/electron-installer-debian-2.0.0.tgz", + "integrity": "sha512-FNdoIzCFhaHiOoLOacWvoUHV80AV/+iH6KNYNiYlB8LmqQKNTPKXNVfZHet/7yDZi2Md4DxRy4gsokEPvV8QSg==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "electron-installer-common": "^0.7.1", + "fs-extra": "^8.0.1", + "get-folder-size": "^2.0.1", + "lodash": "^4.17.4", + "word-wrap": "^1.2.3", + "yargs": "^13.2.2" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "electron-notarize": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-0.1.1.tgz", @@ -3916,6 +4034,12 @@ } } }, + "gar": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/gar/-/gar-1.0.4.tgz", + "integrity": "sha512-w4n9cPWyP7aHxKxYHFQMegj7WIAsL/YX/C4Bs5Rr8s1H9M1rNtRWRsw+ovYMkXDQ5S4ZbYHsHAPmevPjPgw44w==", + "dev": true + }, "gauge": { "version": "2.7.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", @@ -3970,6 +4094,16 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "get-folder-size": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/get-folder-size/-/get-folder-size-2.0.1.tgz", + "integrity": "sha512-+CEb+GDCM7tkOS2wdMKTn9vU7DgnKUTuDlehkNJKNSovdCOVxs14OfKCk4cvSaR3za4gj+OBdl9opPN9xrJ0zA==", + "dev": true, + "requires": { + "gar": "^1.0.4", + "tiny-each-async": "2.0.3" + } + }, "get-package-info": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/get-package-info/-/get-package-info-1.0.0.tgz", @@ -9246,6 +9380,12 @@ "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", "dev": true }, + "tiny-each-async": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/tiny-each-async/-/tiny-each-async-2.0.3.tgz", + "integrity": "sha1-jru/1tYpXxNwAD+7NxYq/loKUdE=", + "dev": true + }, "tmp": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", @@ -10285,6 +10425,12 @@ "resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.4.tgz", "integrity": "sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=" }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, "wordwrap": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", diff --git a/package.json b/package.json index 979e66d8df..4cb2547828 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "mkdirp": "^0.5.1", "music-metadata": "^4.5.0", "network-address": "^1.1.2", - "nobin-debian-installer": "github:webtorrent/nobin-debian-installer", "parse-torrent": "^7.0.1", "prettier-bytes": "^1.0.4", "prop-types": "^15.7.2", @@ -56,6 +55,7 @@ "cross-zip": "^2.1.6", "depcheck": "^0.8.3", "electron": "~6.0.7", + "electron-installer-debian": "^2.0.0", "electron-osx-sign": "^0.4.12", "electron-packager": "^14.0.5", "electron-winstaller": "^4.0.0", diff --git a/src/main/handlers.js b/src/main/handlers.js index 9e0ed897d9..dcc004d8ae 100644 --- a/src/main/handlers.js +++ b/src/main/handlers.js @@ -12,8 +12,6 @@ function install () { break case 'win32': installWin32() break - case 'linux': installLinux() - break } } @@ -23,8 +21,6 @@ function uninstall () { break case 'win32': uninstallWin32() break - case 'linux': uninstallLinux() - break } } @@ -269,100 +265,3 @@ function uninstallWin32 () { function commandToArgs (command) { return command.map((arg) => `"${arg}"`).join(' ') } - -function installLinux () { - const fs = require('fs') - const os = require('os') - const path = require('path') - - const config = require('../config') - const log = require('./log') - - // Do not install in user dir if running on system - if (/^\/opt/.test(process.execPath)) return - - installDesktopFile() - installIconFile() - - function installDesktopFile () { - const templatePath = path.join( - config.STATIC_PATH, 'linux', 'webtorrent-desktop.desktop' - ) - fs.readFile(templatePath, 'utf8', writeDesktopFile) - } - - function writeDesktopFile (err, desktopFile) { - if (err) return log.error(err.message) - - const appPath = config.IS_PRODUCTION - ? path.dirname(process.execPath) - : config.ROOT_PATH - - desktopFile = desktopFile - .replace(/\$APP_NAME/g, config.APP_NAME) - .replace(/\$APP_PATH/g, appPath) - .replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' ')) - .replace(/\$TRY_EXEC_PATH/g, process.execPath) - - const desktopFilePath = path.join( - os.homedir(), - '.local', - 'share', - 'applications', - 'webtorrent-desktop.desktop' - ) - fs.mkdirp(path.dirname(desktopFilePath)) - fs.writeFile(desktopFilePath, desktopFile, err => { - if (err) return log.error(err.message) - }) - } - - function installIconFile () { - const iconStaticPath = path.join(config.STATIC_PATH, 'WebTorrent.png') - fs.readFile(iconStaticPath, writeIconFile) - } - - function writeIconFile (err, iconFile) { - if (err) return log.error(err.message) - - const mkdirp = require('mkdirp') - - const iconFilePath = path.join( - os.homedir(), - '.local', - 'share', - 'icons', - 'webtorrent-desktop.png' - ) - mkdirp(path.dirname(iconFilePath), err => { - if (err) return log.error(err.message) - fs.writeFile(iconFilePath, iconFile, err => { - if (err) log.error(err.message) - }) - }) - } -} - -function uninstallLinux () { - const os = require('os') - const path = require('path') - const rimraf = require('rimraf') - - const desktopFilePath = path.join( - os.homedir(), - '.local', - 'share', - 'applications', - 'webtorrent-desktop.desktop' - ) - rimraf.sync(desktopFilePath) - - const iconFilePath = path.join( - os.homedir(), - '.local', - 'share', - 'icons', - 'webtorrent-desktop.png' - ) - rimraf.sync(iconFilePath) -} diff --git a/static/linux/postinst b/static/linux/postinst deleted file mode 100644 index 59f2fdf011..0000000000 --- a/static/linux/postinst +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -e -chmod +x /opt/webtorrent-desktop/WebTorrent -ln -s -f /opt/webtorrent-desktop/WebTorrent /usr/bin/webtorrent-desktop diff --git a/static/linux/prerm b/static/linux/prerm deleted file mode 100644 index dec86c69d4..0000000000 --- a/static/linux/prerm +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -set -e -rm /usr/bin/webtorrent-desktop diff --git a/static/linux/webtorrent-desktop.desktop b/static/linux/webtorrent-desktop.desktop deleted file mode 100644 index 57290768f2..0000000000 --- a/static/linux/webtorrent-desktop.desktop +++ /dev/null @@ -1,29 +0,0 @@ -[Desktop Entry] -Name=$APP_NAME -Version=1.0 -GenericName=BitTorrent Client -X-GNOME-FullName=$APP_NAME -Comment=Download and share files over BitTorrent -Type=Application -Icon=webtorrent-desktop -Terminal=false -Path=$APP_PATH -Exec=$EXEC_PATH %U -TryExec=$TRY_EXEC_PATH -StartupNotify=false -Categories=Network;FileTransfer;P2P; -MimeType=application/x-bittorrent;x-scheme-handler/magnet;x-scheme-handler/stream-magnet; - -Actions=CreateNewTorrent;OpenTorrentFile;OpenTorrentAddress; - -[Desktop Action CreateNewTorrent] -Name=Create New Torrent... -Exec=$EXEC_PATH -n - -[Desktop Action OpenTorrentFile] -Name=Open Torrent File... -Exec=$EXEC_PATH -o - -[Desktop Action OpenTorrentAddress] -Name=Open Torrent Address... -Exec=$EXEC_PATH -u diff --git a/static/linux/webtorrent-desktop.ejs b/static/linux/webtorrent-desktop.ejs new file mode 100644 index 0000000000..af143b6e6a --- /dev/null +++ b/static/linux/webtorrent-desktop.ejs @@ -0,0 +1,26 @@ +[Desktop Entry] +Type=Application +<% if (version) { %>Version=<%= version %><% } %> +Name=<%= productName %> +<% if (genericName) { %>GenericName=<%= genericName %><% } %> +<% if (description) { %>Comment=<%= description %><% } %> +Icon=<%= name %> +<% if (name) { %>Exec=<%= name %> %U<% } %> +Terminal=false +Actions=CreateNewTorrent;OpenTorrentFile;OpenTorrentAddress; +<% if (mimeType && mimeType.length) { %>MimeType=<%= mimeType.join(';') %>;<% } %> +<% if (categories && categories.length) { %>Categories=<%= categories.join(';') %>;<% } %> +StartupNotify=true +<% if (name) { %>StartupWMClass=<%= name %> <% } %> + +[Desktop Action CreateNewTorrent] +Name=Create New Torrent... +<% if (name) { %>Exec=<%= name %> -n <% } %> + +[Desktop Action OpenTorrentFile] +Name=Open Torrent File... +<% if (name) { %>Exec=<%= name %> -o <% } %> + +[Desktop Action OpenTorrentAddress] +Name=Open Torrent Address... +<% if (name) { %>Exec=<%= name %> -u <% } %> From 6255ccd25349617bbba643678d2f0987b25139a9 Mon Sep 17 00:00:00 2001 From: Julen Garcia Leunda Date: Tue, 10 Sep 2019 22:54:34 +0200 Subject: [PATCH 2/3] Resolve requested changes --- bin/package.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bin/package.js b/bin/package.js index a84da15edc..ecc545679d 100755 --- a/bin/package.js +++ b/bin/package.js @@ -517,14 +517,10 @@ function buildLinux (cb) { desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs') } - installer(options) - .then(function () { - console.log('Linux: Created deb.') - cb(null) - }) - .catch(function (err) { - cb(err) - }) + installer(options).then( + () => cb(null), + (err) => cb(err) + ) } function packageZip (filesPath, cb) { From b34417b1fc050b87c63547d11d63256699814fb1 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 10 Sep 2019 14:12:42 -0700 Subject: [PATCH 3/3] add back removed log statement --- bin/package.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/package.js b/bin/package.js index ecc545679d..3a8a50422a 100755 --- a/bin/package.js +++ b/bin/package.js @@ -518,7 +518,10 @@ function buildLinux (cb) { } installer(options).then( - () => cb(null), + () => { + console.log('Linux: Created deb.') + cb(null) + }, (err) => cb(err) ) }