mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
afbcfb6853
Switch from manually setting containerRequired to false on each individual notification to setting it on the InjectedComponentSet within the notifs-wrapper. This way, people adding new notifications don't need to remember to manually set it themselves.
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
import {React, DefaultClientHelper} from 'nylas-exports';
|
|
import {Notification} from 'nylas-component-kit';
|
|
|
|
const SETTINGS_KEY = 'nylas.mailto.prompted-about-default'
|
|
|
|
export default class DefaultClientNotification extends React.Component {
|
|
static displayName = 'DefaultClientNotification';
|
|
|
|
constructor() {
|
|
super();
|
|
this.helper = new DefaultClientHelper();
|
|
this.state = this.getStateFromStores();
|
|
this.state.initializing = true;
|
|
this.mounted = false;
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.mounted = true;
|
|
this.helper.isRegisteredForURLScheme('mailto', (registered) => {
|
|
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 = () => {
|
|
this.helper.registerForURLScheme('mailto', (err) => {
|
|
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
|
|
title="Would you like to make N1 your default mail client?"
|
|
priority="1"
|
|
icon="volstead-defaultclient.png"
|
|
actions={[{
|
|
label: "Yes",
|
|
fn: this._onAccept,
|
|
}, {
|
|
label: "No",
|
|
fn: this._onDecline,
|
|
}]}
|
|
/>
|
|
)
|
|
}
|
|
}
|