1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00
joplin/ElectronClient/gui/Root.jsx

121 lines
3.3 KiB
React
Raw Normal View History

const React = require('react');
const { render } = require('react-dom');
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 { ResourceScreen } = require('./ResourceScreen.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() {
2017-11-12 01:13:14 +02:00
this.wcsTimeoutId_ = null;
bridge()
.window()
.on('resize', function() {
if (this.wcsTimeoutId_) clearTimeout(this.wcsTimeoutId_);
2017-11-12 01:13:14 +02:00
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'),
});
store.dispatch({
type: 'NOTELIST_VISIBILITY_SET',
visibility: Setting.value('noteListVisibility'),
});
}
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 = {
Desktop: Resolves #2162: Added zoom controls to the application menu commit 2285000a6ac09eed12d4215d71b4f88f1660411a Author: Laurent Cozic <laurent@cozic.net> Date: Tue Feb 11 22:25:12 2020 +0000 Deprecate style.zoom commit 3a6da4ffee280dd93eee1f4ae8891a72ecaea8e3 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Feb 11 22:13:01 2020 +0000 Fix zoom branch commit c46c080a069d213e4f75c261a12cbed47ed8de8f Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:37:10 2019 -0500 Using componentDidUpdate rather than deprecated componentWillRecieveProps https://github.com/laurent22/joplin/pull/2165#discussion_r357441917 commit 069444fd02e18f6542e6483d9fffae8a941ab59c Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:33:23 2019 -0500 Zoom factor is saved to private setting https://github.com/laurent22/joplin/pull/2165#issuecomment-565258704 commit 34a1b2dc3e65f6a5b72a59608f4dddd9bad4bd08 Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:30:29 2019 -0500 Basing new zoom value off redux state https://github.com/laurent22/joplin/pull/2165#discussion_r357441406 https://github.com/laurent22/joplin/pull/2165#discussion_r357441512 commit 7ec15ff4c4b334fd96003aaf04c119e013bb748c Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Fri Dec 13 12:50:11 2019 -0500 Reducer shouldn't have any side effects https://github.com/laurent22/joplin/pull/2165#discussion_r357440767 commit 9e676ece1369e60496ba72cd953ba141b93afd6a Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 8 11:11:28 2019 -0500 Added zoom options to the view menu
2020-02-12 14:41:32 +02:00
width: this.props.size.width / this.props.zoomFactor,
height: this.props.size.height / this.props.zoomFactor,
};
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') },
Resources: { screen: ResourceScreen, title: () => _('Resources') },
2017-12-05 20:56:39 +02:00
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
};
return <Navigator style={navigatorStyle} screens={screens} />;
}
}
const mapStateToProps = state => {
return {
size: state.windowContentSize,
Desktop: Resolves #2162: Added zoom controls to the application menu commit 2285000a6ac09eed12d4215d71b4f88f1660411a Author: Laurent Cozic <laurent@cozic.net> Date: Tue Feb 11 22:25:12 2020 +0000 Deprecate style.zoom commit 3a6da4ffee280dd93eee1f4ae8891a72ecaea8e3 Author: Laurent Cozic <laurent@cozic.net> Date: Tue Feb 11 22:13:01 2020 +0000 Fix zoom branch commit c46c080a069d213e4f75c261a12cbed47ed8de8f Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:37:10 2019 -0500 Using componentDidUpdate rather than deprecated componentWillRecieveProps https://github.com/laurent22/joplin/pull/2165#discussion_r357441917 commit 069444fd02e18f6542e6483d9fffae8a941ab59c Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:33:23 2019 -0500 Zoom factor is saved to private setting https://github.com/laurent22/joplin/pull/2165#issuecomment-565258704 commit 34a1b2dc3e65f6a5b72a59608f4dddd9bad4bd08 Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 15 10:30:29 2019 -0500 Basing new zoom value off redux state https://github.com/laurent22/joplin/pull/2165#discussion_r357441406 https://github.com/laurent22/joplin/pull/2165#discussion_r357441512 commit 7ec15ff4c4b334fd96003aaf04c119e013bb748c Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Fri Dec 13 12:50:11 2019 -0500 Reducer shouldn't have any side effects https://github.com/laurent22/joplin/pull/2165#discussion_r357440767 commit 9e676ece1369e60496ba72cd953ba141b93afd6a Author: Elizabeth Schafer <elizabeth.schafer.wenk@gmail.com> Date: Sun Dec 8 11:11:28 2019 -0500 Added zoom options to the view menu
2020-02-12 14:41:32 +02:00
zoomFactor: state.settings.windowContentZoomFactor / 100,
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')
);