[MM-40025] Stop app from redirecting to tabs when not logged in (#1870)

This commit is contained in:
Devin Binnie 2021-11-22 09:49:53 -05:00 committed by GitHub
parent 4fa89a5fce
commit 3b4437e480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View file

@ -98,6 +98,7 @@ export const SEND_DROPDOWN_MENU_SIZE = 'send-dropdown-menu-size';
export const BROWSER_HISTORY_PUSH = 'browser-history-push';
export const APP_LOGGED_IN = 'app-logged-in';
export const APP_LOGGED_OUT = 'app-logged-out';
export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';

View file

@ -23,6 +23,7 @@ import {
CLOSE_TEAMS_DROPDOWN,
BROWSER_HISTORY_PUSH,
APP_LOGGED_IN,
APP_LOGGED_OUT,
GET_VIEW_NAME,
GET_VIEW_WEBCONTENTS_ID,
} from 'common/communication';
@ -256,6 +257,9 @@ window.addEventListener('storage', (e) => {
if (e.key === '__login__' && e.storageArea === localStorage && e.newValue) {
ipcRenderer.send(APP_LOGGED_IN, viewName);
}
if (e.key === '__logout__' && e.storageArea === localStorage && e.newValue) {
ipcRenderer.send(APP_LOGGED_OUT, viewName);
}
});
/* eslint-enable no-magic-numbers */

View file

@ -47,6 +47,7 @@ export class MattermostView extends EventEmitter {
window: BrowserWindow;
view: BrowserView;
isVisible: boolean;
isLoggedIn: boolean;
options: BrowserViewConstructorOptions;
serverInfo: ServerInfo;
@ -85,6 +86,7 @@ export class MattermostView extends EventEmitter {
...options.webPreferences,
};
this.isVisible = false;
this.isLoggedIn = false;
this.view = new BrowserView(this.options);
this.resetLoadingStatus();

View file

@ -20,6 +20,7 @@ import {
APP_LOGGED_IN,
GET_VIEW_NAME,
GET_VIEW_WEBCONTENTS_ID,
APP_LOGGED_OUT,
} from 'common/communication';
import urlUtils from 'common/utils/url';
@ -56,6 +57,7 @@ ipcMain.on(REACT_APP_INITIALIZED, handleReactAppInitialized);
ipcMain.on(LOADING_SCREEN_ANIMATION_FINISHED, handleLoadingScreenAnimationFinished);
ipcMain.on(BROWSER_HISTORY_PUSH, handleBrowserHistoryPush);
ipcMain.on(APP_LOGGED_IN, handleAppLoggedIn);
ipcMain.on(APP_LOGGED_OUT, handleAppLoggedOut);
ipcMain.handle(GET_VIEW_NAME, handleGetViewName);
ipcMain.handle(GET_VIEW_WEBCONTENTS_ID, handleGetWebContentsId);
@ -570,10 +572,12 @@ function handleBrowserHistoryPush(e: IpcMainEvent, viewName: string, pathName: s
if (status.viewManager?.closedViews.has(redirectedViewName)) {
status.viewManager.openClosedTab(redirectedViewName, `${currentView?.tab.server.url}${pathName}`);
}
const redirectedView = status.viewManager?.views.get(redirectedViewName) || currentView;
if (redirectedView !== currentView && redirectedView?.tab.server.name === status.currentServerName) {
let redirectedView = status.viewManager?.views.get(redirectedViewName) || currentView;
if (redirectedView !== currentView && redirectedView?.tab.server.name === status.currentServerName && redirectedView?.isLoggedIn) {
log.info('redirecting to a new view', redirectedView?.name || viewName);
status.viewManager?.showByName(redirectedView?.name || viewName);
} else {
redirectedView = currentView;
}
// Special case check for Channels to not force a redirect to "/", causing a refresh
@ -587,7 +591,18 @@ export function getCurrentTeamName() {
}
function handleAppLoggedIn(event: IpcMainEvent, viewName: string) {
status.viewManager?.reloadViewIfNeeded(viewName);
const view = status.viewManager?.views.get(viewName);
if (view) {
view.isLoggedIn = true;
status.viewManager?.reloadViewIfNeeded(viewName);
}
}
function handleAppLoggedOut(event: IpcMainEvent, viewName: string) {
const view = status.viewManager?.views.get(viewName);
if (view) {
view.isLoggedIn = false;
}
}
function handleGetViewName(event: IpcMainInvokeEvent) {