2016-07-07 19:10:43 -08:00
|
|
|
/* global Notification */
|
|
|
|
|
/* eslint no-new:0 */
|
2016-07-07 07:15:03 -08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { ipcRenderer, remote } from 'electron';
|
|
|
|
|
|
|
|
|
|
const config = remote.require('./config');
|
|
|
|
|
|
|
|
|
|
export default class Config extends React.Component {
|
|
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
|
super();
|
|
|
|
|
this.state = {
|
2016-07-07 12:48:55 -08:00
|
|
|
config: config.getConfig()
|
2016-07-07 07:15:03 -08:00
|
|
|
};
|
|
|
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChange () {
|
2016-07-07 12:48:55 -08:00
|
|
|
this.setState({ config: config.getConfig() });
|
2016-07-07 07:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
|
ipcRenderer.on('config change', this.onChange);
|
2016-07-07 16:15:42 -08:00
|
|
|
ipcRenderer.on('plugins change', this.onChange);
|
2016-07-07 07:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// passes `config` as props to the decorated component
|
|
|
|
|
render () {
|
|
|
|
|
const child = React.Children.only(this.props.children);
|
|
|
|
|
const { config } = this.state;
|
2016-07-07 16:15:42 -08:00
|
|
|
const decorate = remote.require('./plugins').decorateConfig;
|
|
|
|
|
return React.cloneElement(child, { config: decorate(config) });
|
2016-07-07 07:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
|
ipcRenderer.removeListener('config change', this.onChange);
|
2016-07-07 16:15:42 -08:00
|
|
|
ipcRenderer.removeListener('plugins change', this.onChange);
|
2016-07-07 07:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|