mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 05:41:05 +08:00
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
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(() => {
|
|
this.setState(this.getStateFromStores())
|
|
});
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.disposable.dispose();
|
|
}
|
|
|
|
getStateFromStores() {
|
|
const updater = remote.getGlobal('application').autoUpdateManager;
|
|
|
|
return {
|
|
updateAvailable: updater.getState() === 'update-available',
|
|
version: updater.releaseVersion,
|
|
}
|
|
}
|
|
|
|
_onUpdate = () => {
|
|
ipcRenderer.send('command', 'application:install-update')
|
|
}
|
|
|
|
_onViewChangelog = () => {
|
|
shell.openExternal('https://github.com/nylas/nylas-mail/blob/master/CHANGELOG.md')
|
|
}
|
|
|
|
render() {
|
|
if (!this.state.updateAvailable) {
|
|
return <span />
|
|
}
|
|
const version = this.state.version ? `(${this.state.version})` : '';
|
|
return (
|
|
<Notification
|
|
priority="4"
|
|
title={`An update to Nylas Mail is available ${version}`}
|
|
subtitle="View changelog"
|
|
subtitleAction={this._onViewChangelog}
|
|
icon="volstead-upgrade.png"
|
|
actions={[{
|
|
label: "Update",
|
|
fn: this._onUpdate,
|
|
}]}
|
|
/>
|
|
)
|
|
}
|
|
}
|