Loëck Vézien
7 years ago
4 changed files with 57 additions and 70 deletions
@ -1,78 +1,25 @@ |
|||
// @flow
|
|||
|
|||
import React, { PureComponent } from 'react' |
|||
import React from 'react' |
|||
import { ThemeProvider } from 'styled-components' |
|||
import { ConnectedRouter } from 'react-router-redux' |
|||
import { Provider, connect } from 'react-redux' |
|||
import { Route } from 'react-router' |
|||
import { ipcRenderer } from 'electron' |
|||
import { Provider } from 'react-redux' |
|||
import { I18nextProvider } from 'react-i18next' |
|||
|
|||
import { devicesUpdate, deviceAdd, deviceRemove } from 'actions/devices' |
|||
|
|||
import theme from 'styles/theme' |
|||
|
|||
import Box from 'components/base/Box' |
|||
import SideBar from 'components/SideBar' |
|||
import TopBar from 'components/TopBar' |
|||
import Home from 'components/Home' |
|||
|
|||
import i18n from '../renderer/i18n' |
|||
|
|||
type Props = { |
|||
deviceAdd: (device: Object) => void, |
|||
deviceRemove: (device: Object) => void, |
|||
devicesUpdate: (devices: Object) => void, |
|||
history: Object, |
|||
store: Object, |
|||
} |
|||
|
|||
class App extends PureComponent<Props> { |
|||
componentWillMount() { |
|||
const { devicesUpdate, deviceAdd, deviceRemove } = this.props |
|||
|
|||
ipcRenderer.on('updateDevices', (e, devices) => devicesUpdate(devices)) |
|||
ipcRenderer.on('addDevice', (e, device) => deviceAdd(device)) |
|||
ipcRenderer.on('removeDevice', (e, device) => deviceRemove(device)) |
|||
|
|||
// First renderer, we get all devices
|
|||
ipcRenderer.send('getDevices') |
|||
|
|||
// Start detection when we plug/unplug devices
|
|||
ipcRenderer.send('listenDevices') |
|||
} |
|||
|
|||
componentWillUnmount() { |
|||
ipcRenderer.removeAllListeners('updateDevices') |
|||
ipcRenderer.removeAllListeners('addDevice') |
|||
ipcRenderer.removeAllListeners('removeDevice') |
|||
} |
|||
|
|||
render() { |
|||
const { history, store } = this.props |
|||
|
|||
return ( |
|||
<Provider store={store}> |
|||
<I18nextProvider i18n={i18n}> |
|||
<ThemeProvider theme={theme}> |
|||
<ConnectedRouter history={history}> |
|||
<Box grow horizontal> |
|||
<SideBar /> |
|||
<Box grow bg="cream"> |
|||
<TopBar /> |
|||
<Route path="/" component={Home} /> |
|||
</Box> |
|||
</Box> |
|||
</ConnectedRouter> |
|||
</ThemeProvider> |
|||
</I18nextProvider> |
|||
</Provider> |
|||
) |
|||
} |
|||
} |
|||
|
|||
export default connect(null, { |
|||
deviceAdd, |
|||
deviceRemove, |
|||
devicesUpdate, |
|||
})(App) |
|||
import i18n from 'renderer/i18n' |
|||
|
|||
import Wrapper from 'components/Wrapper' |
|||
|
|||
export default ({ store, history }: { store: Object, history: Object }) => ( |
|||
<Provider store={store}> |
|||
<I18nextProvider i18n={i18n}> |
|||
<ThemeProvider theme={theme}> |
|||
<ConnectedRouter history={history}> |
|||
<Wrapper /> |
|||
</ConnectedRouter> |
|||
</ThemeProvider> |
|||
</I18nextProvider> |
|||
</Provider> |
|||
) |
|||
|
@ -0,0 +1,19 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import { Route } from 'react-router' |
|||
|
|||
import Box from 'components/base/Box' |
|||
import SideBar from 'components/SideBar' |
|||
import TopBar from 'components/TopBar' |
|||
import Home from 'components/Home' |
|||
|
|||
export default () => ( |
|||
<Box grow horizontal> |
|||
<SideBar /> |
|||
<Box grow bg="cream"> |
|||
<TopBar /> |
|||
<Route path="/" component={Home} /> |
|||
</Box> |
|||
</Box> |
|||
) |
@ -0,0 +1,17 @@ |
|||
// @flow
|
|||
|
|||
import { ipcRenderer } from 'electron' |
|||
|
|||
import { devicesUpdate, deviceAdd, deviceRemove } from 'actions/devices' |
|||
|
|||
export default (store: Object) => { |
|||
ipcRenderer.on('updateDevices', (e, devices) => store.dispatch(devicesUpdate(devices))) |
|||
ipcRenderer.on('addDevice', (e, device) => store.dispatch(deviceAdd(device))) |
|||
ipcRenderer.on('removeDevice', (e, device) => store.dispatch(deviceRemove(device))) |
|||
|
|||
// First time, we get all devices
|
|||
ipcRenderer.send('getDevices') |
|||
|
|||
// Start detection when we plug/unplug devices
|
|||
ipcRenderer.send('listenDevices') |
|||
} |
Loading…
Reference in new issue