diff --git a/package-lock.json b/package-lock.json index 207c5ed2a..3a6641817 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,10 +27,8 @@ "multiaddr": "10.0.1", "multiaddr-to-uri": "8.0.0", "portfinder": "^1.0.28", - "sudo-prompt": "^9.2.1", "untildify": "^4.0.0", "v8-compile-cache": "^2.3.0", - "which": "^2.0.2", "winston": "^3.7.2", "yargs": "^17.4.0" }, @@ -11722,11 +11720,6 @@ "node": ">=0.10.0" } }, - "node_modules/sudo-prompt": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/sudo-prompt/-/sudo-prompt-9.2.1.tgz", - "integrity": "sha512-Mu7R0g4ig9TUuGSxJavny5Rv0egCEtpZRNMrZaYS1vxkiIxGiGUwoezU3LazIQ+KE04hTrTfNPgxU5gzi7F5Pw==" - }, "node_modules/sumchecker": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", @@ -22020,11 +22013,6 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, - "sudo-prompt": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/sudo-prompt/-/sudo-prompt-9.2.1.tgz", - "integrity": "sha512-Mu7R0g4ig9TUuGSxJavny5Rv0egCEtpZRNMrZaYS1vxkiIxGiGUwoezU3LazIQ+KE04hTrTfNPgxU5gzi7F5Pw==" - }, "sumchecker": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", diff --git a/package.json b/package.json index 0c02e79a2..dcd855d21 100644 --- a/package.json +++ b/package.json @@ -88,10 +88,8 @@ "multiaddr": "10.0.1", "multiaddr-to-uri": "8.0.0", "portfinder": "^1.0.28", - "sudo-prompt": "^9.2.1", "untildify": "^4.0.0", "v8-compile-cache": "^2.3.0", - "which": "^2.0.2", "winston": "^3.7.2", "yargs": "^17.4.0" }, diff --git a/src/index.js b/src/index.js index e60fa1c1a..6bf778818 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,6 @@ const { criticalErrorDialog } = require('./dialogs') const logger = require('./common/logger') const setupProtocolHandlers = require('./protocol-handlers') const setupI18n = require('./i18n') -const setupNpmOnIpfs = require('./npm-on-ipfs') const setupDaemon = require('./daemon') const setupWebUI = require('./webui') const setupAutoLaunch = require('./auto-launch') @@ -29,7 +28,6 @@ const setupAppMenu = require('./app-menu') const setupArgvFilesHandler = require('./argv-files-handler') const setupAutoUpdater = require('./auto-updater') const setupTray = require('./tray') -const setupIpfsOnPath = require('./ipfs-on-path') const setupAnalytics = require('./analytics') const setupSecondInstance = require('./second-instance') @@ -93,10 +91,7 @@ async function run () { setupNamesysPubsub(ctx), setupSecondInstance(ctx), // Setup global shortcuts - setupTakeScreenshot(ctx), - // Setup PATH-related features - setupNpmOnIpfs(ctx), - setupIpfsOnPath(ctx) + setupTakeScreenshot(ctx) ]) const submitAppReady = () => { logger.addAnalyticsEvent({ withAnalytics: 'APP_READY', dur: getSecondsSinceAppStart() }) diff --git a/src/ipfs-on-path/index.js b/src/ipfs-on-path/index.js deleted file mode 100644 index 401cfe1fa..000000000 --- a/src/ipfs-on-path/index.js +++ /dev/null @@ -1,79 +0,0 @@ -const { join } = require('path') -const i18n = require('i18next') -const { app, shell } = require('electron') -const { execFile } = require('child_process') -const execOrSudo = require('../utils/exec-or-sudo') -const logger = require('../common/logger') -const store = require('../common/store') -const { IS_WIN } = require('../common/consts') -const { showDialog } = require('../dialogs') -const { unlinkSync } = require('fs') - -const CONFIG_KEY = 'ipfsOnPath' - -// Deprecated in February 2021 https://github.com/ipfs/ipfs-desktop/pull/1768 -// Once this bit of code is removed, also remove ../utils/exec-or-sudo. -module.exports = async function () { - if (store.get(CONFIG_KEY, null) === true) { - try { - await uninstall('uninstall') - } catch (err) { - // Weird, but not worth bothering. - logger.error(`[ipfs on path] ${err.toString()}`) - } - - try { - unlinkSync(join(app.getPath('home'), './.ipfs-desktop/IPFS_PATH').replace('app.asar', 'app.asar.unpacked')) - unlinkSync(join(app.getPath('home'), './.ipfs-desktop/IPFS_EXEC').replace('app.asar', 'app.asar.unpacked')) - } catch (err) { - // Weird, but not worth bothering. - logger.error(`[ipfs on path] ${err.toString()}`) - } - - logger.info('[ipfs on path] uninstalled') - - const opt = showDialog({ - title: 'Command Line Tools Uninstalled', - message: 'Command Line Tools via IPFS Desktop have been deprecated in February 2021. They have now been uninstalled. Please refer to https://docs.ipfs.io/install/command-line/ if you need to use ipfs from the command line.', - buttons: [ - i18n.t('openCliDocumentation'), - i18n.t('close') - ] - }) - - if (opt === 0) { - shell.openExternal('https://docs.ipfs.io/install/command-line/') - } - } - - store.delete(CONFIG_KEY) -} - -async function uninstallWindows () { - return new Promise((resolve, reject) => { - execFile('powershell.exe', [ - '-nop', '-exec', 'bypass', - '-win', 'hidden', '-File', - join(__dirname, 'scripts/uninstall.ps1').replace('app.asar', 'app.asar.unpacked') - ], {}, err => { - if (err) { - return reject(err) - } - - resolve() - }) - }) -} - -async function uninstall () { - if (IS_WIN) { - return uninstallWindows() - } - - return execOrSudo({ - script: join(__dirname, './scripts/uninstall.js'), - scope: 'ipfs on path', - trySudo: true, - failSilently: true - }) -} diff --git a/src/ipfs-on-path/scripts/uninstall.js b/src/ipfs-on-path/scripts/uninstall.js deleted file mode 100644 index ff15773f6..000000000 --- a/src/ipfs-on-path/scripts/uninstall.js +++ /dev/null @@ -1,15 +0,0 @@ -const { argv } = require('yargs') -const fs = require('fs-extra') -const { join } = require('path') - -function revert (userData, bin, dst) { - const backup = join(userData, bin + '.bak') - - try { - fs.unlinkSync(backup) - } catch (_) { - // Failed to remove the backup. Suprising, but not worth bothering the user about. - } -} - -revert(argv.data, 'ipfs', '/usr/local/bin/ipfs') diff --git a/src/ipfs-on-path/scripts/uninstall.ps1 b/src/ipfs-on-path/scripts/uninstall.ps1 deleted file mode 100644 index 5904cd497..000000000 --- a/src/ipfs-on-path/scripts/uninstall.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -$path = [System.Environment]::GetEnvironmentVariable('PATH', 'User') -$path = ($path.Split(';') | Where-Object { $_ -ne "$PSScriptRoot\bin-win" }) -join ';' -[Environment]::SetEnvironmentVariable('PATH', $path, 'User') diff --git a/src/npm-on-ipfs/index.js b/src/npm-on-ipfs/index.js deleted file mode 100644 index b154e2a07..000000000 --- a/src/npm-on-ipfs/index.js +++ /dev/null @@ -1,48 +0,0 @@ -const which = require('which') -const util = require('util') -const i18n = require('i18next') -const logger = require('../common/logger') -const store = require('../common/store') -const { showDialog } = require('../dialogs') -const { IS_WIN } = require('../common/consts') -const childProcess = require('child_process') - -const execFile = util.promisify(childProcess.execFile) -const npmBin = IS_WIN ? 'npm.cmd' : 'npm' - -const CONFIG_KEY = 'experiments.npmOnIpfs' - -// Deprecated in February 2021. Remove soon. -module.exports = function (ctx) { - if (store.get(CONFIG_KEY, null) === true) { - logger.info('[npm on ipfs] deprecated, removing') - store.delete(CONFIG_KEY) - uninstall() - - showDialog({ - title: 'NPM on IPFS Uninstalled', - message: 'NPM on IPFS via IPFS Desktop has been deprecated since February 2021. It was now fully removed. As an alternative, you can use https://github.com/foragepm/forage.', - buttons: [i18n.t('close')] - }) - } -} - -module.exports.CONFIG_KEY = CONFIG_KEY - -function isPkgInstalled () { - return !!which.sync('ipfs-npm', { nothrow: true }) -} - -async function uninstall () { - if (isPkgInstalled() === false) { - return - } - - try { - await execFile(npmBin, ['uninstall', '-g', 'ipfs-npm']) - logger.info('[npm on ipfs] ipfs-npm: uninstalled globally') - return true - } catch (err) { - logger.error(`[npm on ipfs] ipfs-npm failed to uninstall: ${err.toString()}`, err) - } -} diff --git a/src/utils/exec-or-sudo.js b/src/utils/exec-or-sudo.js deleted file mode 100644 index 415c02f4f..000000000 --- a/src/utils/exec-or-sudo.js +++ /dev/null @@ -1,77 +0,0 @@ -const i18n = require('i18next') -const util = require('util') -const sudo = require('sudo-prompt') -const { dialog, app } = require('electron') -const childProcess = require('child_process') -const { recoverableErrorDialog } = require('../dialogs') -const logger = require('../common/logger') - -const execFile = util.promisify(childProcess.execFile) - -const env = { - noSudo: { - ELECTRON_RUN_AS_NODE: 1 - }, - sudo: 'env ELECTRON_RUN_AS_NODE=1' -} - -const getResult = (err, stdout, stderr, scope, failSilently, errorOptions) => { - if (stdout) { - logger.info(`[${scope}] sudo: stdout: ${stdout.toString().trim()}`) - } - - if (stderr) { - logger.info(`[${scope}] sudo: stderr: ${stderr.toString().trim()}`) - } - - if (!err) { - return true - } - - const str = err.toString() - logger.error(`[${scope}] error: ${str}`) - - if (process.env.NODE_ENV !== 'test' && !failSilently) { - if (str.includes('No polkit authentication agent found')) { - dialog.showErrorBox(i18n.t('polkitDialog.title'), i18n.t('polkitDialog.message')) - } else if (str.includes('User did not grant permission')) { - dialog.showErrorBox(i18n.t('noPermissionDialog.title'), i18n.t('noPermissionDialog.message')) - } else { - recoverableErrorDialog(err, errorOptions) - } - } - - return false -} - -module.exports = async function ({ script, scope, failSilently, trySudo = true, errorOptions }) { - const dataArg = `--data="${app.getPath('userData')}"` - let err = null - - // First try executing with regular permissions. - try { - const { stdout } = await execFile(process.execPath, [script, dataArg], { env: env.noSudo }) - logger.info(`[${scope}] stdout: ${stdout.toString().trim()}`) - return true - } catch ({ stderr }) { - const msg = stderr.toString().trim() - err = new Error(msg) - logger.info(`[${scope}] no-sudo: stderr: ${msg}`) - } - - if (!trySudo) { - if (!failSilently) { - recoverableErrorDialog(err, errorOptions) - } - - return false - } - - // Otherwise, try to elevate the user. - const command = `${env.sudo} "${process.execPath}" "${script}" ${dataArg}` - return new Promise(resolve => { - sudo.exec(command, { name: 'IPFS Desktop' }, (err, stdout, stderr) => { - resolve(getResult(err, stdout, stderr, scope, failSilently, errorOptions)) - }) - }) -}