Fix webview doesn't get focus correctly
For #231 webview.focus() was used to focus on the webview, but it's DOM element function. So only the tag was focused in the host window, and its webContents was not focused. As the result, the shortcuts of Mattermost server didn't work in some cases. Electron is upgraded to 1.2.8 because of webContents.isFocused().
This commit is contained in:
@@ -82,10 +82,8 @@ var MainPage = React.createClass({
|
||||
});
|
||||
|
||||
var focusListener = function() {
|
||||
var webview = document.getElementById('mattermostView' + thisObj.state.key);
|
||||
webview.focus();
|
||||
|
||||
thisObj.handleOnTeamFocused(thisObj.state.key);
|
||||
thisObj.refs[`mattermostView${thisObj.state.key}`].focusOnWebView();
|
||||
};
|
||||
|
||||
var currentWindow = remote.getCurrentWindow();
|
||||
@@ -94,14 +92,17 @@ var MainPage = React.createClass({
|
||||
currentWindow.removeListener('focus', focusListener);
|
||||
});
|
||||
},
|
||||
componentDidUpdate: function() {
|
||||
this.refs[`mattermostView${this.state.key}`].focusOnWebView();
|
||||
},
|
||||
handleSelect: function(key) {
|
||||
const newKey = (this.props.teams.length + key) % this.props.teams.length;
|
||||
this.setState({
|
||||
key: newKey
|
||||
});
|
||||
this.handleOnTeamFocused(key);
|
||||
this.handleOnTeamFocused(newKey);
|
||||
|
||||
var webview = document.getElementById('mattermostView' + key);
|
||||
var webview = document.getElementById('mattermostView' + newKey);
|
||||
ipcRenderer.send('update-title', {
|
||||
title: webview.getTitle()
|
||||
});
|
||||
@@ -451,6 +452,13 @@ var MattermostView = React.createClass({
|
||||
webContents.reload();
|
||||
});
|
||||
},
|
||||
focusOnWebView: function() {
|
||||
const webview = ReactDOM.findDOMNode(this.refs.webview);
|
||||
if (!webview.getWebContents().isFocused()) {
|
||||
webview.focus();
|
||||
webview.getWebContents().focus();
|
||||
}
|
||||
},
|
||||
render: function() {
|
||||
const errorView = this.state.errorInfo ? (<ErrorView id={ this.props.id + '-fail' } style={ this.props.style } className="errorView" errorInfo={ this.state.errorInfo }></ErrorView>) : null;
|
||||
// 'disablewebsecurity' is necessary to display external images.
|
||||
|
Reference in New Issue
Block a user