[MM-32371] Communicate history information to webapp for disable/enabling Back/Forward buttons (#1941)

* [MM-32371] Communicate history information to webapp for disable/enabling Back/Forward buttons

* Merge'd
This commit is contained in:
Devin Binnie
2022-01-10 17:38:23 -05:00
committed by GitHub
parent 8ad949eedb
commit 8f96fe42c7
6 changed files with 112 additions and 8 deletions

View File

@@ -21,6 +21,7 @@ import {
GET_VIEW_WEBCONTENTS_ID,
RESIZE_MODAL,
APP_LOGGED_OUT,
BROWSER_HISTORY_BUTTON,
} from 'common/communication';
import urlUtils from 'common/utils/url';
import Config from 'common/config';
@@ -56,6 +57,7 @@ export class WindowManager {
ipcMain.on(REACT_APP_INITIALIZED, this.handleReactAppInitialized);
ipcMain.on(LOADING_SCREEN_ANIMATION_FINISHED, this.handleLoadingScreenAnimationFinished);
ipcMain.on(BROWSER_HISTORY_PUSH, this.handleBrowserHistoryPush);
ipcMain.on(BROWSER_HISTORY_BUTTON, this.handleBrowserHistoryButton);
ipcMain.on(APP_LOGGED_IN, this.handleAppLoggedIn);
ipcMain.on(APP_LOGGED_OUT, this.handleAppLoggedOut);
ipcMain.handle(GET_VIEW_NAME, this.handleGetViewName);
@@ -558,6 +560,22 @@ export class WindowManager {
// Special case check for Channels to not force a redirect to "/", causing a refresh
if (!(redirectedView !== currentView && redirectedView?.tab.type === TAB_MESSAGING && pathName === '/')) {
redirectedView?.view.webContents.send(BROWSER_HISTORY_PUSH, pathName);
if (redirectedView) {
this.handleBrowserHistoryButton(e, redirectedView.name);
}
}
}
handleBrowserHistoryButton = (e: IpcMainEvent, viewName: string) => {
const currentView = this.viewManager?.views.get(viewName);
if (currentView) {
if (currentView.view.webContents.getURL() === currentView.tab.url.toString()) {
currentView.view.webContents.clearHistory();
currentView.isAtRoot = true;
} else {
currentView.isAtRoot = false;
}
currentView?.view.webContents.send(BROWSER_HISTORY_BUTTON, currentView.view.webContents.canGoBack(), currentView.view.webContents.canGoForward());
}
}