2017-11-04 17:42:20 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { render } = require('react-dom');
|
|
|
|
const { createStore } = require('redux');
|
2017-11-04 18:40:34 +02:00
|
|
|
const { connect, Provider } = require('react-redux');
|
|
|
|
|
2017-11-12 18:47:33 +02:00
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
const { MainScreen } = require('./MainScreen.min.js');
|
2017-11-06 23:11:15 +02:00
|
|
|
const { OneDriveLoginScreen } = require('./OneDriveLoginScreen.min.js');
|
2017-11-11 19:36:47 +02:00
|
|
|
const { ImportScreen } = require('./ImportScreen.min.js');
|
2017-11-12 02:44:26 +02:00
|
|
|
const { ConfigScreen } = require('./ConfigScreen.min.js');
|
2017-11-06 20:35:04 +02:00
|
|
|
const { Navigator } = require('./Navigator.min.js');
|
2017-11-04 17:42:20 +02:00
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
const { app } = require('../app');
|
|
|
|
|
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
|
|
|
|
|
|
|
async function initialize(dispatch) {
|
2017-11-12 01:13:14 +02:00
|
|
|
this.wcsTimeoutId_ = null;
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
bridge().window().on('resize', function() {
|
2017-11-12 01:13:14 +02:00
|
|
|
if (this.wcsTimeoutId_) clearTimeout(this.wcsTimeoutId_);
|
|
|
|
|
|
|
|
this.wcsTimeoutId_ = setTimeout(() => {
|
|
|
|
store.dispatch({
|
|
|
|
type: 'WINDOW_CONTENT_SIZE_SET',
|
|
|
|
size: bridge().windowContentSize(),
|
|
|
|
});
|
|
|
|
this.wcsTimeoutId_ = null;
|
|
|
|
}, 10);
|
2017-11-05 02:17:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
store.dispatch({
|
|
|
|
type: 'WINDOW_CONTENT_SIZE_SET',
|
|
|
|
size: bridge().windowContentSize(),
|
|
|
|
});
|
|
|
|
}
|
2017-11-04 17:42:20 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
class RootComponent extends React.Component {
|
2017-11-04 17:42:20 +02:00
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
async componentDidMount() {
|
|
|
|
if (this.props.appState == 'starting') {
|
|
|
|
this.props.dispatch({
|
2017-11-08 23:22:24 +02:00
|
|
|
type: 'APP_STATE_SET',
|
2017-11-05 02:17:48 +02:00
|
|
|
state: 'initializing',
|
|
|
|
});
|
|
|
|
|
|
|
|
await initialize(this.props.dispatch);
|
|
|
|
|
|
|
|
this.props.dispatch({
|
2017-11-08 23:22:24 +02:00
|
|
|
type: 'APP_STATE_SET',
|
2017-11-05 02:17:48 +02:00
|
|
|
state: 'ready',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 17:42:20 +02:00
|
|
|
render() {
|
2017-11-06 20:35:04 +02:00
|
|
|
const navigatorStyle = {
|
2017-11-04 21:46:37 +02:00
|
|
|
width: this.props.size.width,
|
|
|
|
height: this.props.size.height,
|
|
|
|
};
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
const screens = {
|
|
|
|
Main: { screen: MainScreen },
|
2017-11-12 18:47:33 +02:00
|
|
|
OneDriveLogin: { screen: OneDriveLoginScreen, title: () => _('OneDrive Login') },
|
|
|
|
Import: { screen: ImportScreen, title: () => _('Import') },
|
|
|
|
Config: { screen: ConfigScreen, title: () => _('Configuration') },
|
2017-11-04 21:46:37 +02:00
|
|
|
};
|
|
|
|
|
2017-11-04 17:42:20 +02:00
|
|
|
return (
|
2017-11-06 20:35:04 +02:00
|
|
|
<Navigator style={navigatorStyle} screens={screens} />
|
2017-11-04 21:46:37 +02:00
|
|
|
);
|
2017-11-04 17:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-04 18:40:34 +02:00
|
|
|
const mapStateToProps = (state) => {
|
2017-11-04 21:46:37 +02:00
|
|
|
return {
|
|
|
|
size: state.windowContentSize,
|
2017-11-05 02:17:48 +02:00
|
|
|
appState: state.appState,
|
2017-11-04 21:46:37 +02:00
|
|
|
};
|
2017-11-04 18:40:34 +02:00
|
|
|
};
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
const Root = connect(mapStateToProps)(RootComponent);
|
2017-11-04 18:40:34 +02:00
|
|
|
|
2017-11-04 17:42:20 +02:00
|
|
|
const store = app().store();
|
|
|
|
|
|
|
|
render(
|
|
|
|
<Provider store={store}>
|
2017-11-06 20:35:04 +02:00
|
|
|
<Root />
|
2017-11-04 17:42:20 +02:00
|
|
|
</Provider>,
|
|
|
|
document.getElementById('react-root')
|
|
|
|
)
|