remove old updater and add update dismissing

This commit is contained in:
Guillermo Rauch 2016-07-07 00:13:53 -07:00
parent 173d747f43
commit 08a106312d
2 changed files with 8 additions and 65 deletions

View file

@ -5,7 +5,6 @@ import Mousetrap from 'mousetrap';
import classes from 'classnames'; import classes from 'classnames';
import shallowCompare from 'react-addons-shallow-compare'; import shallowCompare from 'react-addons-shallow-compare';
import React, { Component } from 'react'; import React, { Component } from 'react';
import UpdateChecker from './update-checker';
export default class HyperTerm extends Component { export default class HyperTerm extends Component {
constructor () { constructor () {
@ -23,8 +22,8 @@ export default class HyperTerm extends Component {
mac: /Mac/.test(navigator.userAgent), mac: /Mac/.test(navigator.userAgent),
resizeIndicatorShowing: false, resizeIndicatorShowing: false,
fontSizeIndicatorShowing: false, fontSizeIndicatorShowing: false,
dismissedUpdate: false,
updateVersion: null, updateVersion: null,
updateNote: null,
fontSize: 12 fontSize: 12
}; };
@ -52,6 +51,7 @@ export default class HyperTerm extends Component {
this.resetFontSize = this.resetFontSize.bind(this); this.resetFontSize = this.resetFontSize.bind(this);
this.increaseFontSize = this.increaseFontSize.bind(this); this.increaseFontSize = this.increaseFontSize.bind(this);
this.decreaseFontSize = this.decreaseFontSize.bind(this); this.decreaseFontSize = this.decreaseFontSize.bind(this);
this.dismissUpdate = this.dismissUpdate.bind(this);
} }
render () { render () {
@ -98,15 +98,19 @@ export default class HyperTerm extends Component {
{this.state.fontSizeIndicatorShowing && <div>{ this.state.fontSize }px</div>} {this.state.fontSizeIndicatorShowing && <div>{ this.state.fontSize }px</div>}
<div>{ this.state.cols }x{ this.state.rows }</div> <div>{ this.state.cols }x{ this.state.rows }</div>
</div> </div>
<div className={classes('update-indicator', { showing: null !== this.state.updateVersion })}> <div className={classes('update-indicator', { showing: null !== this.state.updateVersion && !this.state.dismissedUpdate })}>
Version <b>{ this.state.updateVersion }</b> ready. Version <b>{ this.state.updateVersion }</b> ready.
{this.state.updateNote ? ` ${this.state.updateNote}. ` : ' '} {this.state.updateNote ? ` ${this.state.updateNote}. ` : ' '}
<a href='' onClick={this.quitAndInstall}>Restart</a> <a href='' onClick={this.quitAndInstall}>Restart</a>
to apply <span className='close' onClick={this.quitAndInstall}>[x]</span> to apply <span className='close' onClick={this.dismissUpdate}>[x]</span>
</div> </div>
</div>; </div>;
} }
dismissUpdate () {
this.setState({ dismissedUpdate: true });
}
quitAndInstall (ev) { quitAndInstall (ev) {
ev.preventDefault(); ev.preventDefault();
this.rpc.emit('quit-and-install'); this.rpc.emit('quit-and-install');

View file

@ -1,61 +0,0 @@
/*global fetch:false*/
import { version as currentVersion } from '../package';
import compare from 'semver-compare';
import ms from 'ms';
const DEFAULT_INTERVAL = ms('5m');
export default class UpdateChecker {
constructor (fn, { interval = DEFAULT_INTERVAL } = {}) {
this.callback = fn;
this.interval = interval;
this.check();
this.lastKnown = null;
}
check () {
const done = () => {
this.checkTimer = setTimeout(() => {
this.check();
}, this.interval);
};
console.log('checking for update');
fetch('https://hyperterm.now.sh/updates.json')
.then((res) => {
if (200 !== res.status) {
console.error('Update check error. Status (%d)', res.status);
return done();
}
res.json()
.then(({ version, note }) => {
if (this.lastKnown !== version) {
this.lastKnown = version;
if (1 === compare(version, currentVersion)) {
console.log('update found');
this.callback(version, note);
} else {
console.log('no update. latest:', version);
}
}
done();
})
.catch((err) => {
console.error('Update JSON parse error', err.stack);
done();
});
}).catch((err) => {
console.error('Update check error', err.stack);
done();
});
}
destroy () {
this.aborted = true;
clearTimeout(this.checkTimer);
}
}