Merge pull request #175 from kitematic/setup-cancel

Adding setup retry when user cancels virtualbox install
This commit is contained in:
Jeffrey Morgan 2015-02-12 09:35:16 -08:00
commit f80cda4e0d
2 changed files with 42 additions and 7 deletions

View File

@ -4,6 +4,7 @@ var Radial = require('./Radial.react.js');
var SetupStore = require('./SetupStore');
var RetinaImage = require('react-retina-image');
var Header = require('./Header.react');
var Util = require('./Util');
var Setup = React.createClass({
mixins: [ Router.Navigation ],
@ -26,11 +27,18 @@ var Setup = React.createClass({
SetupStore.removeListener(SetupStore.STEP_EVENT, this.update);
SetupStore.removeListener(SetupStore.ERROR_EVENT, this.update);
},
handleRetry: function () {
SetupStore.run().catch(() => {});
},
handleOpenWebsite: function () {
Util.exec(['open', 'https://www.virtualbox.org/wiki/Downloads']);
},
update: function () {
this.setState({
progress: SetupStore.percent(),
step: SetupStore.step(),
error: SetupStore.error()
error: SetupStore.error(),
cancelled: SetupStore.cancelled()
});
},
renderContents: function () {
@ -64,6 +72,25 @@ var Setup = React.createClass({
</div>
);
},
renderCancelled: function () {
return (
<div className="setup">
<Header />
<div className="image">
{this.renderContents()}
</div>
<div className="desc">
<div className="content">
<h4>Installation Cancelled</h4>
<h1>Couldn&#39;t Install VirtualBox</h1>
<p>Kitematic did not receive the administrative privileges required to install VirtualBox.</p>
<p>Please retry or download &amp; install VirutalBox manually from the <a onClick={this.handleOpenWebsite}>official Oracle website</a>.</p>
<button className="btn btn-action" onClick={this.handleRetry}>Retry</button>
</div>
</div>
</div>
);
},
renderError: function () {
return (
<div className="setup">
@ -90,7 +117,9 @@ var Setup = React.createClass({
if (!SetupStore.step()) {
return false;
}
if (this.state.error) {
if (this.state.cancelled) {
return this.renderCancelled();
} else if (this.state.error) {
return this.renderError();
} else {
return this.renderStep();

View File

@ -11,6 +11,7 @@ var util = require('./Util');
var SUDO_PROMPT = 'Kitematic requires administrative privileges to install VirtualBox.';
var _currentStep = null;
var _error = null;
var _cancelled = false;
var _steps = [{
name: 'downloadVirtualBox',
@ -54,7 +55,8 @@ var _steps = [{
try {
yield util.exec(sudoCmd);
} catch (err) {
console.log('Could not install virtualbox...');
_cancelled = true;
throw err;
}
})
}, {
@ -127,9 +129,14 @@ var SetupStore = assign(EventEmitter.prototype, {
error: function () {
return _error;
},
run: Promise.coroutine(function* (startAt) {
startAt = startAt || 0;
for (let step of _steps.slice(startAt)) {
cancelled: function () {
return _cancelled;
},
run: Promise.coroutine(function* () {
_error = null;
_cancelled = false;
var steps = _currentStep ? _steps.slice(_steps.indexOf(_currentStep)) : _steps;
for (let step of steps) {
_currentStep = step;
step.percent = 0;
try {
@ -149,7 +156,6 @@ var SetupStore = assign(EventEmitter.prototype, {
throw err;
}
}
_currentStep = null;
})
});