Mailspring/app/internal_packages/preferences/lib/tabs/workspace-section.jsx

160 lines
4.2 KiB
React
Raw Normal View History

import React from 'react';
2017-09-27 02:33:08 +08:00
import PropTypes from 'prop-types';
import { DefaultClientHelper, SystemStartService } from 'mailspring-exports';
import ConfigSchemaItem from './config-schema-item';
class DefaultMailClientItem extends React.Component {
constructor() {
super();
2017-09-27 02:33:08 +08:00
this.state = { defaultClient: false };
this._helper = new DefaultClientHelper();
if (this._helper.available()) {
2017-09-27 02:33:08 +08:00
this._helper.isRegisteredForURLScheme('mailto', registered => {
if (this._mounted) this.setState({ defaultClient: registered });
});
}
}
componentDidMount() {
this._mounted = true;
}
componentWillUnmount() {
this._mounted = false;
}
2017-09-27 02:33:08 +08:00
toggleDefaultMailClient = event => {
if (this.state.defaultClient) {
2017-09-27 02:33:08 +08:00
this.setState({ defaultClient: false });
this._helper.resetURLScheme('mailto');
} else {
2017-09-27 02:33:08 +08:00
this.setState({ defaultClient: true });
this._helper.registerForURLScheme('mailto');
}
event.target.blur();
2017-09-27 02:33:08 +08:00
};
render() {
return (
<div className="item">
2016-05-07 07:06:16 +08:00
<input
type="checkbox"
id="default-client"
checked={this.state.defaultClient}
onChange={this.toggleDefaultMailClient}
/>
<label htmlFor="default-client">Use Mailspring as default mail client</label>
</div>
);
}
}
class LaunchSystemStartItem extends React.Component {
constructor() {
super();
this.state = {
available: false,
launchOnStart: false,
};
this._service = new SystemStartService();
}
componentDidMount() {
this._mounted = true;
2017-09-27 02:33:08 +08:00
this._service.checkAvailability().then(available => {
if (this._mounted) {
2017-09-27 02:33:08 +08:00
this.setState({ available });
}
if (!available || !this._mounted) return;
2017-09-27 02:33:08 +08:00
this._service.doesLaunchOnSystemStart().then(launchOnStart => {
if (this._mounted) {
2017-09-27 02:33:08 +08:00
this.setState({ launchOnStart });
}
});
});
}
componentWillUnmount() {
this._mounted = false;
}
2017-09-27 02:33:08 +08:00
_toggleLaunchOnStart = event => {
if (this.state.launchOnStart) {
2017-09-27 02:33:08 +08:00
this.setState({ launchOnStart: false });
this._service.dontLaunchOnSystemStart();
} else {
2017-09-27 02:33:08 +08:00
this.setState({ launchOnStart: true });
this._service.configureToLaunchOnSystemStart();
}
event.target.blur();
2017-09-27 02:33:08 +08:00
};
render() {
if (!this.state.available) return false;
return (
<div className="item">
2016-05-07 07:06:16 +08:00
<input
type="checkbox"
id="launch-on-start"
checked={this.state.launchOnStart}
onChange={this._toggleLaunchOnStart}
/>
<label htmlFor="launch-on-start">Launch on system start</label>
</div>
);
}
}
2017-09-27 02:33:08 +08:00
const WorkspaceSection = props => {
2016-05-07 07:23:48 +08:00
return (
<section>
<DefaultMailClientItem />
<LaunchSystemStartItem />
<ConfigSchemaItem
configSchema={props.configSchema.properties.workspace.properties.systemTray}
keyPath="core.workspace.systemTray"
config={props.config}
/>
<ConfigSchemaItem
configSchema={props.configSchema.properties.workspace.properties.showImportant}
keyPath="core.workspace.showImportant"
config={props.config}
/>
<ConfigSchemaItem
configSchema={props.configSchema.properties.workspace.properties.showUnreadForAllCategories}
keyPath="core.workspace.showUnreadForAllCategories"
config={props.config}
/>
2016-04-10 12:39:38 +08:00
<ConfigSchemaItem
configSchema={props.configSchema.properties.workspace.properties.use24HourClock}
2016-04-10 12:39:38 +08:00
keyPath="core.workspace.use24HourClock"
config={props.config}
2016-04-10 12:39:38 +08:00
/>
2016-05-07 07:23:48 +08:00
<ConfigSchemaItem
configSchema={props.configSchema.properties.workspace.properties.interfaceZoom}
keyPath="core.workspace.interfaceZoom"
config={props.config}
/>
<div className="platform-note platform-linux-only">
2017-09-27 02:33:08 +08:00
&quot;Launch on system start&quot; only works in XDG-compliant desktop environments. To
enable the N1 icon in the system tray, you may need to install libappindicator1. (i.e.,
&lt;code&gt;sudo apt-get install libappindicator1&lt;/code&gt;)
2016-05-07 07:23:48 +08:00
</div>
</section>
);
2017-09-27 02:33:08 +08:00
};
2016-05-07 07:23:48 +08:00
WorkspaceSection.propTypes = {
2017-09-27 02:33:08 +08:00
config: PropTypes.object,
configSchema: PropTypes.object,
};
export default WorkspaceSection;