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

152 lines
4.2 KiB
TypeScript
Raw Normal View History

import app from '../app';
import MainScreen from './MainScreen/MainScreen';
import ConfigScreen from './ConfigScreen/ConfigScreen';
import StatusScreen from './StatusScreen/StatusScreen';
import OneDriveLoginScreen from './OneDriveLoginScreen';
import DropboxLoginScreen from './DropboxLoginScreen';
import ErrorBoundary from './ErrorBoundary';
import { themeStyle } from '@joplin/lib/theme';
import { Size } from './ResizableLayout/ResizableLayout';
import MenuBar from './MenuBar';
import { _ } from '@joplin/lib/locale';
const React = require('react');
const { render } = require('react-dom');
2017-11-04 18:40:34 +02:00
const { connect, Provider } = require('react-redux');
const Setting = require('@joplin/lib/models/Setting').default;
const shim = require('@joplin/lib/shim').default;
2020-11-05 18:58:23 +02:00
shim.setReact(React);
2017-11-11 19:36:47 +02:00
const { ImportScreen } = require('./ImportScreen.min.js');
const { ResourceScreen } = require('./ResourceScreen.js');
const { Navigator } = require('./Navigator.min.js');
const WelcomeUtils = require('@joplin/lib/WelcomeUtils');
2020-09-15 15:01:07 +02:00
const { ThemeProvider, StyleSheetManager, createGlobalStyle } = require('styled-components');
const bridge = require('electron').remote.require('./bridge').default;
interface Props {
themeId: number,
appState: string,
dispatch: Function,
size: Size,
zoomFactor: number,
}
2020-09-15 15:01:07 +02:00
const GlobalStyle = createGlobalStyle`
div, span, a {
/*color: ${(props:any) => props.theme.color};*/
/*font-size: ${(props:any) => props.theme.fontSize}px;*/
font-family: ${(props:any) => props.theme.fontFamily};
2020-09-15 15:01:07 +02:00
}
`;
let wcsTimeoutId_:any = null;
2017-11-12 01:13:14 +02:00
async function initialize() {
bridge().window().on('resize', function() {
if (wcsTimeoutId_) shim.clearTimeout(wcsTimeoutId_);
wcsTimeoutId_ = shim.setTimeout(() => {
store.dispatch({
type: 'WINDOW_CONTENT_SIZE_SET',
size: bridge().windowContentSize(),
});
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<Props, any> {
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({
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,
};
2020-09-15 15:01:07 +02:00
const theme = themeStyle(this.props.themeId);
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: () => _('Note attachments') },
2017-12-05 20:56:39 +02:00
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
};
2020-09-15 15:01:07 +02:00
return (
<StyleSheetManager disableVendorPrefixes>
<ThemeProvider theme={theme}>
<MenuBar/>
2020-09-15 15:01:07 +02:00
<GlobalStyle/>
<Navigator style={navigatorStyle} screens={screens} />
</ThemeProvider>
</StyleSheetManager>
);
}
}
const mapStateToProps = (state:any) => {
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,
2020-09-15 15:01:07 +02:00
themeId: state.settings.theme,
};
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}>
<ErrorBoundary>
<Root />
</ErrorBoundary>
</Provider>,
document.getElementById('react-root')
);