2020-10-09 19:35:46 +02:00
|
|
|
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';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { themeStyle } from '@joplin/lib/theme';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { Size } from './ResizableLayout/ResizableLayout';
|
|
|
|
import MenuBar from './MenuBar';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-10-20 00:24:40 +02:00
|
|
|
const React = require('react');
|
2020-10-09 19:35:46 +02:00
|
|
|
|
2017-11-04 17:42:20 +02:00
|
|
|
const { render } = require('react-dom');
|
2017-11-04 18:40:34 +02:00
|
|
|
const { connect, Provider } = require('react-redux');
|
2020-11-07 17:59:37 +02:00
|
|
|
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');
|
2020-02-19 12:13:33 +02:00
|
|
|
const { ResourceScreen } = require('./ResourceScreen.js');
|
2017-11-06 20:35:04 +02:00
|
|
|
const { Navigator } = require('./Navigator.min.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const WelcomeUtils = require('@joplin/lib/WelcomeUtils');
|
2020-09-15 15:01:07 +02:00
|
|
|
const { ThemeProvider, StyleSheetManager, createGlobalStyle } = require('styled-components');
|
2020-10-09 19:35:46 +02:00
|
|
|
const bridge = require('electron').remote.require('./bridge').default;
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
themeId: number,
|
|
|
|
appState: string,
|
|
|
|
dispatch: Function,
|
|
|
|
size: Size,
|
|
|
|
zoomFactor: number,
|
|
|
|
}
|
2017-11-05 02:17:48 +02:00
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const GlobalStyle = createGlobalStyle`
|
|
|
|
div, span, a {
|
2020-10-09 19:35:46 +02:00
|
|
|
/*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
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
let wcsTimeoutId_:any = null;
|
2017-11-12 01:13:14 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
async function initialize() {
|
2020-04-09 19:57:20 +02:00
|
|
|
bridge().window().on('resize', function() {
|
2020-10-09 19:35:46 +02:00
|
|
|
if (wcsTimeoutId_) shim.clearTimeout(wcsTimeoutId_);
|
2020-04-09 19:57:20 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
wcsTimeoutId_ = shim.setTimeout(() => {
|
2020-04-09 19:57:20 +02:00
|
|
|
store.dispatch({
|
|
|
|
type: 'WINDOW_CONTENT_SIZE_SET',
|
|
|
|
size: bridge().windowContentSize(),
|
|
|
|
});
|
2020-10-09 19:35:46 +02:00
|
|
|
wcsTimeoutId_ = null;
|
2020-04-09 19:57:20 +02:00
|
|
|
}, 10);
|
|
|
|
});
|
2017-11-05 02:17:48 +02:00
|
|
|
|
2017-11-17 20:02:01 +02:00
|
|
|
// 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(),
|
|
|
|
});
|
|
|
|
|
2017-11-12 19:02:20 +02:00
|
|
|
store.dispatch({
|
|
|
|
type: 'NOTE_VISIBLE_PANES_SET',
|
|
|
|
panes: Setting.value('noteVisiblePanes'),
|
|
|
|
});
|
2018-04-15 17:50:39 +02:00
|
|
|
|
|
|
|
store.dispatch({
|
|
|
|
type: 'SIDEBAR_VISIBILITY_SET',
|
2019-07-29 14:13:23 +02:00
|
|
|
visibility: Setting.value('sidebarVisibility'),
|
2018-04-15 17:50:39 +02:00
|
|
|
});
|
2019-10-30 11:40:34 +02:00
|
|
|
|
|
|
|
store.dispatch({
|
|
|
|
type: 'NOTELIST_VISIBILITY_SET',
|
|
|
|
visibility: Setting.value('noteListVisibility'),
|
|
|
|
});
|
2017-11-05 02:17:48 +02:00
|
|
|
}
|
2017-11-04 17:42:20 +02:00
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
class RootComponent extends React.Component<Props, any> {
|
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',
|
|
|
|
});
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
await initialize();
|
2017-11-05 02:17:48 +02:00
|
|
|
|
|
|
|
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',
|
|
|
|
});
|
|
|
|
}
|
2019-02-09 01:38:29 +02:00
|
|
|
|
2019-02-09 21:04:34 +02:00
|
|
|
await WelcomeUtils.install(this.props.dispatch);
|
2017-11-05 02:17:48 +02:00
|
|
|
}
|
|
|
|
|
2017-11-04 17:42:20 +02:00
|
|
|
render() {
|
2017-11-06 20:35:04 +02:00
|
|
|
const navigatorStyle = {
|
2020-02-12 14:41:32 +02:00
|
|
|
width: this.props.size.width / this.props.zoomFactor,
|
|
|
|
height: this.props.size.height / this.props.zoomFactor,
|
2017-11-04 21:46:37 +02:00
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
const theme = themeStyle(this.props.themeId);
|
|
|
|
|
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') },
|
2018-03-26 19:33:55 +02:00
|
|
|
DropboxLogin: { screen: DropboxLoginScreen, title: () => _('Dropbox Login') },
|
2017-11-12 18:47:33 +02:00
|
|
|
Import: { screen: ImportScreen, title: () => _('Import') },
|
2017-11-30 20:36:26 +02:00
|
|
|
Config: { screen: ConfigScreen, title: () => _('Options') },
|
2020-04-08 12:12:25 +02:00
|
|
|
Resources: { screen: ResourceScreen, title: () => _('Note attachments') },
|
2017-12-05 20:56:39 +02:00
|
|
|
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
|
2017-11-04 21:46:37 +02:00
|
|
|
};
|
|
|
|
|
2020-09-15 15:01:07 +02:00
|
|
|
return (
|
|
|
|
<StyleSheetManager disableVendorPrefixes>
|
|
|
|
<ThemeProvider theme={theme}>
|
2020-10-09 19:35:46 +02:00
|
|
|
<MenuBar/>
|
2020-09-15 15:01:07 +02:00
|
|
|
<GlobalStyle/>
|
|
|
|
<Navigator style={navigatorStyle} screens={screens} />
|
|
|
|
</ThemeProvider>
|
|
|
|
</StyleSheetManager>
|
|
|
|
);
|
2017-11-04 17:42:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:35:46 +02:00
|
|
|
const mapStateToProps = (state:any) => {
|
2017-11-04 21:46:37 +02:00
|
|
|
return {
|
|
|
|
size: state.windowContentSize,
|
2020-02-12 14:41:32 +02:00
|
|
|
zoomFactor: state.settings.windowContentZoomFactor / 100,
|
2017-11-05 02:17:48 +02:00
|
|
|
appState: state.appState,
|
2020-09-15 15:01:07 +02:00
|
|
|
themeId: state.settings.theme,
|
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}>
|
2020-07-03 23:32:39 +02:00
|
|
|
<ErrorBoundary>
|
|
|
|
<Root />
|
|
|
|
</ErrorBoundary>
|
2017-11-04 17:42:20 +02:00
|
|
|
</Provider>,
|
|
|
|
document.getElementById('react-root')
|
2019-07-29 14:13:23 +02:00
|
|
|
);
|