diff --git a/lib/installer/manager.js b/lib/installer/manager.js index f44462c..fa9d603 100644 --- a/lib/installer/manager.js +++ b/lib/installer/manager.js @@ -8,6 +8,8 @@ * the root directory of this source tree. */ +import * as utils from '../utils'; + import { CompositeDisposable, Emitter } from 'atom'; import AtomDependenciesStage from './stages/atom-dependencies'; @@ -16,6 +18,7 @@ import ConfigurationStage from './stages/configuration'; import InstallerProgressModal from './progress-modal'; import PlatformIOCoreStage from './stages/platformio-core'; import ProjectExamplesStage from './stages/project-examples'; +import semver from 'semver'; export default class InstallationManager { @@ -29,7 +32,11 @@ export default class InstallationManager { new CodeCompletionEngineStage(this.eventbus), new AtomDependenciesStage(this.eventbus), new ProjectExamplesStage(this.eventbus), - new PlatformIOCoreStage(this.eventbus) + new PlatformIOCoreStage(this.eventbus, { + useBuiltinPIOCore: atom.config.get('platformio-ide.useBuiltinPIOCore'), + setUseBuiltinPIOCore: (value) => atom.config.set('platformio-ide.useBuiltinPIOCore', value), + useDevelopmentPIOCore: atom.config.get('platformio-ide.advanced.useDevelopmentPIOCore') || semver.prerelease(utils.getIDEVersion()) + }) ]; this.progress = new InstallerProgressModal({ diff --git a/lib/installer/stages/base.js b/lib/installer/stages/base.js index fbfd480..eb02ba9 100644 --- a/lib/installer/stages/base.js +++ b/lib/installer/stages/base.js @@ -17,8 +17,9 @@ export default class BaseStage { static STORAGE_STATE_KEY = 'platformio-ide:installer-state'; - constructor(eventbus) { + constructor(eventbus, params = {}) { this.eventbus = eventbus; + this.params = params; this._status = BaseStage.STATUS_CHECKING; } diff --git a/lib/installer/stages/platformio-core.js b/lib/installer/stages/platformio-core.js index 420c0f6..dffa89b 100644 --- a/lib/installer/stages/platformio-core.js +++ b/lib/installer/stages/platformio-core.js @@ -234,7 +234,7 @@ export default class PlatformIOCoreStage extends BaseStage { async installPIOCore() { let cmd = 'pip'; const args = ['install', '--no-cache-dir', '-U']; - if (atom.config.get('platformio-ide.advanced.useDevelopmentPIOCore') || semver.prerelease(utils.getIDEVersion())) { + if (this.params.useDevelopmentPIOCore) { cmd = path.join(config.ENV_BIN_DIR, 'pip'); args.push('https://github.com/platformio/platformio/archive/develop.zip'); } else { @@ -324,7 +324,7 @@ export default class PlatformIOCoreStage extends BaseStage { } async check() { - if (atom.config.get('platformio-ide.useBuiltinPIOCore')) { + if (this.params.useBuiltinPIOCore) { if (!fs.isDirectorySync(config.ENV_BIN_DIR)) { throw new Error('Virtual environment is not created'); } @@ -335,8 +335,8 @@ export default class PlatformIOCoreStage extends BaseStage { const coreVersion = await utils.getCoreVersion(); if (semver.lt(PEPverToSemver(coreVersion), config.PIO_CORE_MIN_VERSION)) { - atom.config.set('platformio-ide.useBuiltinPIOCore', true); - throw new Error('Incompatible PIO Core', coreVersion); + this.params.setUseBuiltinPIOCore(true); + throw new Error(`Incompatible PIO Core ${coreVersion}`); } this.status = BaseStage.STATUS_SUCCESSED; @@ -348,7 +348,7 @@ export default class PlatformIOCoreStage extends BaseStage { if (this.status === BaseStage.STATUS_SUCCESSED) { return true; } - if (!atom.config.get('platformio-ide.useBuiltinPIOCore')) { + if (!this.params.useBuiltinPIOCore) { this.status = BaseStage.STATUS_SUCCESSED; return true; }