-
Notifications
You must be signed in to change notification settings - Fork 903
refactor: remove deprecated "ipfs on PATH" feature #1948
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4cb2c4
refactor: remove ipfs on path
hacdias f7b3b28
refactor: remove ipfs on path
hacdias 94e0799
remove IPFS_EXEC file
hacdias 5d7b486
feat: add open cli doc opt
hacdias cc01a6c
remove backup file, keep symlink
hacdias b4a5af2
cleanup uninstall.js file
hacdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')) | ||
| } 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 | ||
| }) | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.