Mailspring/app/internal_packages/notifications/lib/items/update-notification.jsx

65 lines
1.7 KiB
React
Raw Normal View History

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';
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());
});
}
componentWillUnmount() {
this.disposable.dispose();
}
getStateFromStores() {
const updater = remote.getGlobal('application').autoUpdateManager;
const updateAvailable = updater.getState() === 'update-available';
const info = updateAvailable ? updater.getReleaseDetails() : {};
return {
updateAvailable,
updateIsManual: info.releaseNotes === 'manual-download',
version: info.releaseVersion,
2017-09-27 02:33:08 +08:00
};
}
_onUpdate = () => {
2017-09-27 02:33:08 +08:00
ipcRenderer.send('command', 'application:install-update');
};
_onViewChangelog = () => {
2017-09-27 02:33:08 +08:00
shell.openExternal('https://github.com/Foundry376/Mailspring/releases/latest');
};
render() {
2017-09-27 02:33:08 +08:00
const { updateAvailable, version, updateIsManual } = this.state;
if (!updateAvailable) {
2017-09-27 02:33:08 +08:00
return <span />;
}
return (
<Notification
priority="4"
title={`An update to Mailspring is available ${version ? `(${version})` : ''}`}
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,
},
]}
/>
2017-09-27 02:33:08 +08:00
);
}
}