2016-10-04 23:02:11 +08:00
|
|
|
import {React} from 'nylas-exports';
|
|
|
|
import {ipcRenderer, remote, shell} from 'electron';
|
2016-10-07 01:53:22 +08:00
|
|
|
import {Notification} from 'nylas-component-kit';
|
2016-10-04 23:02:11 +08:00
|
|
|
|
|
|
|
export default class UpdateNotification extends React.Component {
|
|
|
|
static displayName = 'UpdateNotification';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.disposable = NylasEnv.onUpdateAvailable(() => {
|
|
|
|
this.setState(this.getStateFromStores())
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.disposable.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
getStateFromStores() {
|
2016-10-13 07:05:28 +08:00
|
|
|
const updater = remote.getGlobal('application').autoUpdateManager;
|
2017-09-07 02:30:59 +08:00
|
|
|
const updateAvailable = updater.getState() === 'update-available';
|
|
|
|
const info = updateAvailable ? updater.getReleaseDetails() : {};
|
2016-10-04 23:02:11 +08:00
|
|
|
return {
|
2017-09-07 02:30:59 +08:00
|
|
|
updateAvailable,
|
|
|
|
updateIsManual: info.releaseNotes === 'manual-download',
|
|
|
|
version: info.releaseVersion,
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onUpdate = () => {
|
|
|
|
ipcRenderer.send('command', 'application:install-update')
|
|
|
|
}
|
|
|
|
|
|
|
|
_onViewChangelog = () => {
|
2017-09-06 04:37:40 +08:00
|
|
|
shell.openExternal('https://github.com/Foundry376/Mailspring/releases/latest')
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-07 02:30:59 +08:00
|
|
|
const {updateAvailable, version, updateIsManual} = this.state;
|
|
|
|
|
|
|
|
if (!updateAvailable) {
|
2016-10-04 23:02:11 +08:00
|
|
|
return <span />
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Notification
|
|
|
|
priority="4"
|
2017-09-07 02:30:59 +08:00
|
|
|
title={`An update to Mailspring is available ${version ? `(${version})` : ''}`}
|
2016-10-04 23:02:11 +08:00
|
|
|
subtitle="View changelog"
|
|
|
|
subtitleAction={this._onViewChangelog}
|
|
|
|
icon="volstead-upgrade.png"
|
|
|
|
actions={[{
|
2017-09-07 02:30:59 +08:00
|
|
|
label: updateIsManual ? 'Download Now' : 'Install Update',
|
2016-10-04 23:02:11 +08:00
|
|
|
fn: this._onUpdate,
|
|
|
|
}]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|