Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove deprecated "ipfs on PATH" feature #1948

Merged
merged 6 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"customIpfsBinary": "Custom IPFS Binary",
"setCustomIpfsBinary": "Set Custom IPFS Binary",
"clearCustomIpfsBinary": "Clear Custom IPFS Binary",
"openCliDocumentation": "Open CLI Documentation",
"polkitDialog": {
"title": "Polkit not found",
"message": "IPFS can't be added to /usr/local/bin/ without polkit agent."
Expand Down Expand Up @@ -149,10 +150,6 @@
"title": "Move repository",
"message": "Could not move the repository from \"{ currDir }\" to \"{ newDir }\"."
},
"cantAddIpfsToPath": {
"title": "IPFS on PATH",
"message": "Could not add IPFS to the PATH."
},
"runGarbageCollectorErrored": {
"title": "Garbage collector",
"message": "The garbage collector run could not be completed successfully."
Expand Down Expand Up @@ -187,16 +184,6 @@
"title": "Error",
"message": "Launch at login could not be enabled on your machine."
},
"enableIpfsOnPath": {
"title": "Enable IPFS on PATH",
"message": "By enabling this option, IPFS will be available on your command line as \"ipfs\". This action is reversible.",
"action": "Enable"
},
"disableIpfsOnPath": {
"title": "Disable IPFS on PATH",
"message": "By disabling this option, IPFS will no longer be available on your command line as \"ipfs\".",
"action": "Disable"
},
"enableGlobalTakeScreenshotShortcut": {
"title": "Enable screenshot shortcut",
"message": "By enabling this, the shortcut \"{ accelerator }\" will be available to take screenshots as long as IPFS Desktop is running."
Expand All @@ -215,7 +202,6 @@
"pubsub": "Enable PubSub",
"namesysPubsub": "Enable IPNS over PubSub",
"automaticGC": "Automatic Garbage Collection",
"ipfsCommandLineTools": "Command Line Tools",
"takeScreenshotShortcut": "Global Screenshot Shortcut",
"downloadHashShortcut": "Global Download Shortcut",
"experiments": "Experiments",
Expand Down
12 changes: 0 additions & 12 deletions src/daemon/daemon.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const Ctl = require('ipfsd-ctl')
const i18n = require('i18next')
const fs = require('fs-extra')
const { join } = require('path')
const { app } = require('electron')
const { showDialog } = require('../dialogs')
const logger = require('../common/logger')
const { applyDefaults, migrateConfig, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
Expand All @@ -27,17 +24,8 @@ function getIpfsBinPath () {
.replace('app.asar', 'app.asar.unpacked')
}

function writeIpfsBinaryPath (path) {
fs.outputFileSync(
join(app.getPath('home'), './.ipfs-desktop/IPFS_EXEC')
.replace('app.asar', 'app.asar.unpacked'),
path
)
}

async function spawn ({ flags, path }) {
const ipfsBin = getIpfsBinPath()
writeIpfsBinaryPath(ipfsBin)

const ipfsd = await Ctl.createController({
ipfsHttpModule: require('ipfs-http-client'),
Expand Down
16 changes: 0 additions & 16 deletions src/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ module.exports = async function (ctx) {
const config = store.get('ipfsConfig')
updateStatus(STATUS.STARTING_STARTED)

if (config.path) {
// Updates the IPFS_PATH file. We do this every time we start up
// to make sure we always have that file present, even though
// there are installations and updates that might remove the file.
writeIpfsPath(config.path)
}

try {
ipfsd = await createDaemon(config)

Expand All @@ -59,7 +52,6 @@ module.exports = async function (ctx) {
if (!config.path || typeof config.path !== 'string') {
config.path = ipfsd.path
store.set('ipfsConfig', config)
writeIpfsPath(config.path)
}

log.end()
Expand Down Expand Up @@ -125,11 +117,3 @@ module.exports = async function (ctx) {
}

module.exports.STATUS = STATUS

function writeIpfsPath (path) {
fs.outputFileSync(
join(app.getPath('home'), './.ipfs-desktop/IPFS_PATH')
.replace('app.asar', 'app.asar.unpacked'),
path
)
}
122 changes: 39 additions & 83 deletions src/ipfs-on-path/index.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,79 @@
const { join } = require('path')
const i18n = require('i18next')
const which = require('which')
const { app, shell } = require('electron')
const { execFile } = require('child_process')
const createToggler = require('../utils/create-toggler')
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, recoverableErrorDialog } = require('../dialogs')
const { showDialog } = require('../dialogs')
const { unlinkSync } = require('fs')

const CONFIG_KEY = 'ipfsOnPath'

const errorMessage = {
title: i18n.t('cantAddIpfsToPath.title'),
message: i18n.t('cantAddIpfsToPath.message')
}

// 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 () {
createToggler(CONFIG_KEY, async ({ newValue, oldValue }) => {
if (newValue === oldValue || (oldValue === null && !newValue)) {
return
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()}`)
}

if (newValue === true) {
if (showDialog({
title: i18n.t('enableIpfsOnPath.title'),
message: i18n.t('enableIpfsOnPath.message'),
buttons: [
i18n.t('enableIpfsOnPath.action'),
i18n.t('cancel')
]
}) !== 0) {
// User canceled
return
}

return run('install')
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'))
lidel marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
// Weird, but not worth bothering.
logger.error(`[ipfs on path] ${err.toString()}`)
}

if (showDialog({
title: i18n.t('disableIpfsOnPath.title'),
message: i18n.t('disableIpfsOnPath.message'),
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('disableIpfsOnPath.action'),
i18n.t('cancel')
i18n.t('openCliDocumentation'),
i18n.t('close')
]
}) !== 0) {
// User canceled
return
}

return run('uninstall')
})

firstTime()
}

module.exports.CONFIG_KEY = CONFIG_KEY

async function firstTime () {
// Check if we've done this before.
if (store.get(CONFIG_KEY, null) !== null) {
logger.info('[ipfs on path] no action taken')
return
}
})

if (which.sync('ipfs', { nothrow: true }) !== null) {
// ipfs already exists on user's system so we won't take any action
// by default. Doesn't try again next time.
store.set(CONFIG_KEY, false)
return
if (opt === 0) {
shell.openExternal('https://docs.ipfs.io/install/command-line/')
}
}

// Tries to install ipfs-on-path on the system. It doesn't try to elevate
// to sudo so the user doesn't get annoying prompts when running IPFS Desktop
// for the first time. Sets the option according to the success or failure of the
// procedure.
try {
const res = await run('install', { trySudo: false, failSilently: true })
store.set(CONFIG_KEY, res)
} catch (err) {
logger.error(`[ipfs on path] unexpected error while no-sudo install: ${err.toString()}`)
store.set(CONFIG_KEY, false)
}
store.delete(CONFIG_KEY)
}

async function runWindows (script, { failSilently }) {
return new Promise(resolve => {
async function uninstallWindows () {
return new Promise((resolve, reject) => {
execFile('powershell.exe', [
'-nop', '-exec', 'bypass',
'-win', 'hidden', '-File',
join(__dirname, `scripts/${script}.ps1`).replace('app.asar', 'app.asar.unpacked')
join(__dirname, 'scripts/uninstall.ps1').replace('app.asar', 'app.asar.unpacked')
lidel marked this conversation as resolved.
Show resolved Hide resolved
], {}, err => {
if (err) {
logger.error(`[ipfs on path] ${err.toString()}`)

if (!failSilently) {
recoverableErrorDialog(err, errorMessage)
}

return resolve(false)
return reject(err)
}

logger.info(`[ipfs on path] ${script}ed`)
resolve(true)
resolve()
})
})
}

async function run (script, { trySudo = true, failSilently = false } = {}) {
async function uninstall () {
if (IS_WIN) {
return runWindows(script, { failSilently })
return uninstallWindows()
}

return execOrSudo({
script: join(__dirname, `./scripts/${script}.js`),
script: join(__dirname, './scripts/uninstall.js'),
scope: 'ipfs on path',
trySudo,
failSilently,
errorOptions: errorMessage
trySudo: true,
failSilently: true
})
}
59 changes: 0 additions & 59 deletions src/ipfs-on-path/scripts/backup.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/ipfs-on-path/scripts/bin-win/ipfs.cmd

This file was deleted.

6 changes: 0 additions & 6 deletions src/ipfs-on-path/scripts/consts.js

This file was deleted.

52 changes: 0 additions & 52 deletions src/ipfs-on-path/scripts/install.js

This file was deleted.

Loading