Merge branch 'improve-reloading'

Close #213 and #223
This commit is contained in:
Yuya Ochiai 2016-08-03 23:27:37 +09:00
commit dcbf18e863
2 changed files with 33 additions and 6 deletions

View file

@ -63,6 +63,14 @@ var MainPage = React.createClass({
this.handleSelect(this.state.key - 1); this.handleSelect(this.state.key - 1);
}); });
// reload the activated tab
ipcRenderer.on('reload-tab', (event) => {
this.refs[`mattermostView${this.state.key}`].reload();
});
ipcRenderer.on('clear-cache-and-reload-tab', (event) => {
this.refs[`mattermostView${this.state.key}`].clearCacheAndReload();
});
var focusListener = function() { var focusListener = function() {
var webview = document.getElementById('mattermostView' + thisObj.state.key); var webview = document.getElementById('mattermostView' + thisObj.state.key);
webview.focus(); webview.focus();
@ -185,7 +193,7 @@ var MainPage = React.createClass({
} }
var id = 'mattermostView' + index; var id = 'mattermostView' + index;
return (<MattermostView key={ id } id={ id } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } name={ team.name } onUnreadCountChange={ handleUnreadCountChange } return (<MattermostView key={ id } id={ id } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } name={ team.name } onUnreadCountChange={ handleUnreadCountChange }
onNotificationClick={ handleNotificationClick } />) onNotificationClick={ handleNotificationClick } ref={ id } />)
}); });
var views_row = (<Row> var views_row = (<Row>
{ views } { views }
@ -401,6 +409,16 @@ var MattermostView = React.createClass({
} }
}); });
}, },
reload: function() {
var webview = ReactDOM.findDOMNode(this.refs.webview);
webview.reload();
},
clearCacheAndReload() {
var webContents = ReactDOM.findDOMNode(this.refs.webview).getWebContents();
webContents.session.clearCache(() => {
webContents.reload();
});
},
render: function() { 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; 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. // 'disablewebsecurity' is necessary to display external images.

View file

@ -99,20 +99,29 @@ var createTemplate = function(mainWindow, config) {
accelerator: 'CmdOrCtrl+R', accelerator: 'CmdOrCtrl+R',
click: function(item, focusedWindow) { click: function(item, focusedWindow) {
if (focusedWindow) { if (focusedWindow) {
if (focusedWindow === mainWindow) {
mainWindow.webContents.send('reload-tab');
}
else {
focusedWindow.reload(); focusedWindow.reload();
} }
} }
}
}, { }, {
label: 'Clear Cache and Reload', label: 'Clear Cache and Reload',
accelerator: 'Shift+CmdOrCtrl+R', accelerator: 'Shift+CmdOrCtrl+R',
click: function(item, focusedWindow) { click: function(item, focusedWindow) {
// TODO: should reload the selected tab only
if (focusedWindow) { if (focusedWindow) {
if (focusedWindow === mainWindow) {
mainWindow.webContents.send('clear-cache-and-reload-tab');
}
else {
focusedWindow.webContents.session.clearCache(function() { focusedWindow.webContents.session.clearCache(function() {
focusedWindow.reload(); focusedWindow.reload();
}); });
} }
} }
}
}, { }, {
label: 'Toggle Full Screen', label: 'Toggle Full Screen',
accelerator: (function() { accelerator: (function() {