mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
c63c6370b5
The goal is to make the command system more modular, so each command can be defined as a single object that includes a declaration (name, label, etc.) and a runtime (to execute the command, test if it should be enabled, etc.) Utility methods are provided to convert a command to a menu item or a toolbar button, thus reducing duplicated and boiler plate code across the codebase (often the menu item logic was duplicated in the toolbar button logic and vice versa). The goal is to make it easier to add new commands (and associated menu item and toolbar buttons) and to call them from anywhere. This is also useful for plugins, which can also easily define new commands. Could also allow creating a command palette.
121 lines
3.4 KiB
JavaScript
121 lines
3.4 KiB
JavaScript
const React = require('react');
|
|
const { render } = require('react-dom');
|
|
const { connect, Provider } = require('react-redux');
|
|
|
|
const { _ } = require('lib/locale.js');
|
|
const Setting = require('lib/models/Setting.js');
|
|
|
|
const { MainScreen } = require('.//MainScreen/MainScreen.min.js');
|
|
const ErrorBoundary = require('./ErrorBoundary').default;
|
|
const { OneDriveLoginScreen } = require('./OneDriveLoginScreen.min.js');
|
|
const { DropboxLoginScreen } = require('./DropboxLoginScreen.min.js');
|
|
const { StatusScreen } = require('./StatusScreen.min.js');
|
|
const { ImportScreen } = require('./ImportScreen.min.js');
|
|
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() {
|
|
this.wcsTimeoutId_ = null;
|
|
|
|
bridge().window().on('resize', function() {
|
|
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'),
|
|
});
|
|
|
|
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({
|
|
type: 'APP_STATE_SET',
|
|
state: 'initializing',
|
|
});
|
|
|
|
await initialize(this.props.dispatch);
|
|
|
|
this.props.dispatch({
|
|
type: 'APP_STATE_SET',
|
|
state: 'ready',
|
|
});
|
|
}
|
|
|
|
await WelcomeUtils.install(this.props.dispatch);
|
|
}
|
|
|
|
render() {
|
|
const navigatorStyle = {
|
|
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') },
|
|
DropboxLogin: { screen: DropboxLoginScreen, title: () => _('Dropbox Login') },
|
|
Import: { screen: ImportScreen, title: () => _('Import') },
|
|
Config: { screen: ConfigScreen, title: () => _('Options') },
|
|
Resources: { screen: ResourceScreen, title: () => _('Note attachments') },
|
|
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
|
|
};
|
|
|
|
return <Navigator style={navigatorStyle} screens={screens} />;
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = state => {
|
|
return {
|
|
size: state.windowContentSize,
|
|
zoomFactor: state.settings.windowContentZoomFactor / 100,
|
|
appState: state.appState,
|
|
};
|
|
};
|
|
|
|
const Root = connect(mapStateToProps)(RootComponent);
|
|
|
|
const store = app().store();
|
|
|
|
render(
|
|
<Provider store={store}>
|
|
<ErrorBoundary>
|
|
<Root />
|
|
</ErrorBoundary>
|
|
</Provider>,
|
|
document.getElementById('react-root')
|
|
);
|