2016-10-13 07:05:28 +08:00
|
|
|
import {React, DefaultClientHelper} from 'nylas-exports';
|
2016-10-07 01:53:22 +08:00
|
|
|
import {Notification} from 'nylas-component-kit';
|
2016-10-04 23:02:11 +08:00
|
|
|
|
|
|
|
const SETTINGS_KEY = 'nylas.mailto.prompted-about-default'
|
|
|
|
|
|
|
|
export default class DefaultClientNotification extends React.Component {
|
|
|
|
static displayName = 'DefaultClientNotification';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2016-10-13 07:05:28 +08:00
|
|
|
this.helper = new DefaultClientHelper();
|
2016-10-04 23:02:11 +08:00
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
this.state.initializing = true;
|
|
|
|
this.mounted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.mounted = true;
|
2016-10-13 07:05:28 +08:00
|
|
|
this.helper.isRegisteredForURLScheme('mailto', (registered) => {
|
2016-10-04 23:02:11 +08:00
|
|
|
if (this.mounted) {
|
|
|
|
this.setState({
|
|
|
|
initializing: false,
|
|
|
|
registered: registered,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.disposable = NylasEnv.config.onDidChange(SETTINGS_KEY,
|
|
|
|
() => this.setState(this.getStateFromStores()));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.mounted = false;
|
|
|
|
this.disposable.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
getStateFromStores() {
|
|
|
|
return {
|
|
|
|
alreadyPrompted: NylasEnv.config.get(SETTINGS_KEY),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onAccept = () => {
|
2016-10-13 07:05:28 +08:00
|
|
|
this.helper.registerForURLScheme('mailto', (err) => {
|
2016-10-04 23:02:11 +08:00
|
|
|
if (err) {
|
|
|
|
NylasEnv.reportError(err)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
NylasEnv.config.set(SETTINGS_KEY, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDecline = () => {
|
|
|
|
NylasEnv.config.set(SETTINGS_KEY, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.initializing || this.state.alreadyPrompted || this.state.registered) {
|
|
|
|
return <span />
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Notification
|
2017-01-12 09:41:07 +08:00
|
|
|
title="Would you like to make Nylas Mail your default mail client?"
|
2016-10-04 23:02:11 +08:00
|
|
|
priority="1"
|
|
|
|
icon="volstead-defaultclient.png"
|
|
|
|
actions={[{
|
|
|
|
label: "Yes",
|
|
|
|
fn: this._onAccept,
|
|
|
|
}, {
|
|
|
|
label: "No",
|
|
|
|
fn: this._onDecline,
|
|
|
|
}]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|