2019-07-29 14:13:23 +02:00
|
|
|
const React = require('react');
|
|
|
|
const Component = React.Component;
|
2017-11-06 20:35:04 +02:00
|
|
|
const { connect } = require('react-redux');
|
2017-11-12 18:47:33 +02:00
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
2017-11-06 20:35:04 +02:00
|
|
|
|
|
|
|
class NavigatorComponent extends Component {
|
2019-12-13 03:16:34 +02:00
|
|
|
UNSAFE_componentWillReceiveProps(newProps) {
|
2017-11-12 18:47:33 +02:00
|
|
|
if (newProps.route) {
|
|
|
|
const screenInfo = this.props.screens[newProps.route.routeName];
|
2020-03-14 01:46:14 +02:00
|
|
|
const windowTitle = ['Joplin'];
|
2017-11-12 18:47:33 +02:00
|
|
|
if (screenInfo.title) {
|
|
|
|
windowTitle.push(screenInfo.title());
|
|
|
|
}
|
|
|
|
this.updateWindowTitle(windowTitle.join(' - '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateWindowTitle(title) {
|
2019-03-03 02:31:41 +02:00
|
|
|
try {
|
2019-09-11 01:53:01 +02:00
|
|
|
if (bridge().window()) bridge().window().setTitle(title);
|
2019-03-03 02:31:41 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.warn('updateWindowTitle', error);
|
|
|
|
}
|
2017-11-12 18:47:33 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
render() {
|
|
|
|
if (!this.props.route) throw new Error('Route must not be null');
|
|
|
|
|
|
|
|
const route = this.props.route;
|
2017-11-11 19:36:47 +02:00
|
|
|
const screenProps = route.props ? route.props : {};
|
2017-11-12 18:47:33 +02:00
|
|
|
const screenInfo = this.props.screens[route.routeName];
|
|
|
|
const Screen = screenInfo.screen;
|
2017-11-06 20:35:04 +02:00
|
|
|
|
|
|
|
const screenStyle = {
|
|
|
|
width: this.props.style.width,
|
|
|
|
height: this.props.style.height,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={this.props.style}>
|
2019-07-29 14:13:23 +02:00
|
|
|
<Screen style={screenStyle} {...screenProps} />
|
2017-11-06 20:35:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
const Navigator = connect(state => {
|
|
|
|
return {
|
|
|
|
route: state.route,
|
|
|
|
};
|
|
|
|
})(NavigatorComponent);
|
2017-11-06 20:35:04 +02:00
|
|
|
|
2019-07-29 14:13:23 +02:00
|
|
|
module.exports = { Navigator };
|