From 3feb833537609b851d3d60a00297cf81855b0d3a Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Thu, 28 Jul 2016 22:44:42 +0900 Subject: [PATCH] Refresh the inside of the current tab when reloading in the main window For #213 and #223 As the side effect, this doesn't reload the settings page. But it will not be problem in most cases. --- src/browser/index.jsx | 20 +++++++++++++++++++- src/main/menus/app.js | 19 ++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index a8690932..ffe0d441 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -63,6 +63,14 @@ var MainPage = React.createClass({ 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 webview = document.getElementById('mattermostView' + thisObj.state.key); webview.focus(); @@ -185,7 +193,7 @@ var MainPage = React.createClass({ } var id = 'mattermostView' + index; return () + onNotificationClick={ handleNotificationClick } ref={ id } />) }); var views_row = ( { views } @@ -408,6 +416,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() { const errorView = this.state.errorInfo ? () : null; // 'disablewebsecurity' is necessary to display external images. diff --git a/src/main/menus/app.js b/src/main/menus/app.js index 52ed7058..e5fd6432 100644 --- a/src/main/menus/app.js +++ b/src/main/menus/app.js @@ -99,18 +99,27 @@ var createTemplate = function(mainWindow, config) { accelerator: 'CmdOrCtrl+R', click: function(item, focusedWindow) { if (focusedWindow) { - focusedWindow.reload(); + if (focusedWindow === mainWindow) { + mainWindow.webContents.send('reload-tab'); + } + else { + focusedWindow.reload(); + } } } }, { label: 'Clear Cache and Reload', accelerator: 'Shift+CmdOrCtrl+R', click: function(item, focusedWindow) { - // TODO: should reload the selected tab only if (focusedWindow) { - focusedWindow.webContents.session.clearCache(function() { - focusedWindow.reload(); - }); + if (focusedWindow === mainWindow) { + mainWindow.webContents.send('clear-cache-and-reload-tab'); + } + else { + focusedWindow.webContents.session.clearCache(function() { + focusedWindow.reload(); + }); + } } } }, {