2017-09-27 02:42:18 +08:00
|
|
|
import { React } from 'mailspring-exports';
|
2017-09-27 02:33:08 +08:00
|
|
|
import { ipcRenderer, remote, shell } from 'electron';
|
2017-09-27 02:46:00 +08:00
|
|
|
import { Notification } from 'mailspring-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() {
|
2017-09-27 02:36:58 +08:00
|
|
|
this.disposable = AppEnv.onUpdateAvailable(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
this.setState(this.getStateFromStores());
|
2016-10-04 23:02:11 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2017-09-27 02:33:08 +08:00
|
|
|
};
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_onUpdate = () => {
|
2017-09-27 02:33:08 +08:00
|
|
|
ipcRenderer.send('command', 'application:install-update');
|
|
|
|
};
|
2016-10-04 23:02:11 +08:00
|
|
|
|
|
|
|
_onViewChangelog = () => {
|
2017-09-27 02:33:08 +08:00
|
|
|
shell.openExternal('https://github.com/Foundry376/Mailspring/releases/latest');
|
|
|
|
};
|
2016-10-04 23:02:11 +08:00
|
|
|
|
|
|
|
render() {
|
2017-09-27 02:33:08 +08:00
|
|
|
const { updateAvailable, version, updateIsManual } = this.state;
|
2017-09-07 02:30:59 +08:00
|
|
|
|
|
|
|
if (!updateAvailable) {
|
2017-09-27 02:33:08 +08:00
|
|
|
return <span />;
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
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"
|
2017-09-27 02:33:08 +08:00
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
label: updateIsManual ? 'Download Now' : 'Install Update',
|
|
|
|
fn: this._onUpdate,
|
|
|
|
},
|
|
|
|
]}
|
2016-10-04 23:02:11 +08:00
|
|
|
/>
|
2017-09-27 02:33:08 +08:00
|
|
|
);
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
}
|