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

65 lines
1.7 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import { React } from 'nylas-exports';
import { ipcRenderer, remote, shell } from 'electron';
import { Notification } from 'nylas-component-kit';
export default class UpdateNotification extends React.Component {
static displayName = 'UpdateNotification';
constructor() {
super();
this.state = this.getStateFromStores();
}
componentDidMount() {
this.disposable = NylasEnv.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
);
}
}