1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ElectronClient/app/gui/Root.jsx

119 lines
3.3 KiB
React
Raw Normal View History

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');
const { _ } = require('lib/locale.js');
2017-12-14 20:12:14 +02:00
const Setting = require('lib/models/Setting.js');
const { MainScreen } = require('./MainScreen.min.js');
2017-11-06 23:11:15 +02:00
const { OneDriveLoginScreen } = require('./OneDriveLoginScreen.min.js');
2018-03-26 19:33:55 +02:00
const { DropboxLoginScreen } = require('./DropboxLoginScreen.min.js');
2017-12-05 20:56:39 +02:00
const { StatusScreen } = require('./StatusScreen.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');
const { EncryptionConfigScreen } = require('./EncryptionConfigScreen.min.js');
const { ClipperConfigScreen } = require('./ClipperConfigScreen.min.js');
const { Navigator } = require('./Navigator.min.js');
const WelcomeUtils = require('lib/WelcomeUtils');
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;
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);
});
// Need to dispatch this to make sure the components are
// displayed at the right size. The windowContentSize is
// also set in the store default state, but at that point
// the window might not be at its final size.
store.dispatch({
type: 'WINDOW_CONTENT_SIZE_SET',
size: bridge().windowContentSize(),
});
store.dispatch({
type: 'NOTE_VISIBLE_PANES_SET',
panes: Setting.value('noteVisiblePanes'),
});
store.dispatch({
type: 'SIDEBAR_VISIBILITY_SET',
visibility: Setting.value('sidebarVisibility')
});
}
class RootComponent extends React.Component {
async componentDidMount() {
if (this.props.appState == 'starting') {
this.props.dispatch({
2017-11-08 23:22:24 +02:00
type: 'APP_STATE_SET',
state: 'initializing',
});
await initialize(this.props.dispatch);
this.props.dispatch({
2017-11-08 23:22:24 +02:00
type: 'APP_STATE_SET',
state: 'ready',
});
}
await WelcomeUtils.install(this.props.dispatch);
}
render() {
const navigatorStyle = {
width: this.props.size.width,
height: this.props.size.height,
};
const screens = {
Main: { screen: MainScreen },
OneDriveLogin: { screen: OneDriveLoginScreen, title: () => _('OneDrive Login') },
2018-03-26 19:33:55 +02:00
DropboxLogin: { screen: DropboxLoginScreen, title: () => _('Dropbox Login') },
Import: { screen: ImportScreen, title: () => _('Import') },
2017-11-30 20:36:26 +02:00
Config: { screen: ConfigScreen, title: () => _('Options') },
2017-12-05 20:56:39 +02:00
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
EncryptionConfig: { screen: EncryptionConfigScreen, title: () => _('Encryption Options') },
ClipperConfig: { screen: ClipperConfigScreen, title: () => _('Clipper Options') },
};
return (
<Navigator style={navigatorStyle} screens={screens} />
);
}
}
2017-11-04 18:40:34 +02:00
const mapStateToProps = (state) => {
return {
size: state.windowContentSize,
appState: state.appState,
};
2017-11-04 18:40:34 +02:00
};
const Root = connect(mapStateToProps)(RootComponent);
2017-11-04 18:40:34 +02:00
const store = app().store();
render(
<Provider store={store}>
<Root />
</Provider>,
document.getElementById('react-root')
)