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;
|
|
|
|
|
2016-10-04 23:02:11 +08:00
|
|
|
return {
|
2016-10-13 07:05:28 +08:00
|
|
|
updateAvailable: updater.getState() === 'update-available',
|
|
|
|
version: updater.releaseVersion,
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onUpdate = () => {
|
|
|
|
ipcRenderer.send('command', 'application:install-update')
|
|
|
|
}
|
|
|
|
|
|
|
|
_onViewChangelog = () => {
|
2017-01-20 03:28:30 +08:00
|
|
|
shell.openExternal('https://github.com/nylas/N1/blob/n1-next/CHANGELOG.md')
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (!this.state.updateAvailable) {
|
|
|
|
return <span />
|
|
|
|
}
|
|
|
|
const version = this.state.version ? `(${this.state.version})` : '';
|
|
|
|
return (
|
|
|
|
<Notification
|
|
|
|
priority="4"
|
2017-01-12 09:41:07 +08:00
|
|
|
title={`An update to Nylas Mail is available ${version}`}
|
2016-10-04 23:02:11 +08:00
|
|
|
subtitle="View changelog"
|
|
|
|
subtitleAction={this._onViewChangelog}
|
|
|
|
icon="volstead-upgrade.png"
|
|
|
|
actions={[{
|
|
|
|
label: "Update",
|
|
|
|
fn: this._onUpdate,
|
|
|
|
}]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|