mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
remove old updater and add update dismissing
This commit is contained in:
parent
173d747f43
commit
08a106312d
2 changed files with 8 additions and 65 deletions
|
|
@ -5,7 +5,6 @@ import Mousetrap from 'mousetrap';
|
|||
import classes from 'classnames';
|
||||
import shallowCompare from 'react-addons-shallow-compare';
|
||||
import React, { Component } from 'react';
|
||||
import UpdateChecker from './update-checker';
|
||||
|
||||
export default class HyperTerm extends Component {
|
||||
constructor () {
|
||||
|
|
@ -23,8 +22,8 @@ export default class HyperTerm extends Component {
|
|||
mac: /Mac/.test(navigator.userAgent),
|
||||
resizeIndicatorShowing: false,
|
||||
fontSizeIndicatorShowing: false,
|
||||
dismissedUpdate: false,
|
||||
updateVersion: null,
|
||||
updateNote: null,
|
||||
fontSize: 12
|
||||
};
|
||||
|
||||
|
|
@ -52,6 +51,7 @@ export default class HyperTerm extends Component {
|
|||
this.resetFontSize = this.resetFontSize.bind(this);
|
||||
this.increaseFontSize = this.increaseFontSize.bind(this);
|
||||
this.decreaseFontSize = this.decreaseFontSize.bind(this);
|
||||
this.dismissUpdate = this.dismissUpdate.bind(this);
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
@ -98,15 +98,19 @@ export default class HyperTerm extends Component {
|
|||
{this.state.fontSizeIndicatorShowing && <div>{ this.state.fontSize }px</div>}
|
||||
<div>{ this.state.cols }x{ this.state.rows }</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.
|
||||
{this.state.updateNote ? ` ${this.state.updateNote}. ` : ' '}
|
||||
<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>;
|
||||
}
|
||||
|
||||
dismissUpdate () {
|
||||
this.setState({ dismissedUpdate: true });
|
||||
}
|
||||
|
||||
quitAndInstall (ev) {
|
||||
ev.preventDefault();
|
||||
this.rpc.emit('quit-and-install');
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue