[MM-40025] Stop app from redirecting to tabs when not logged in (#1870)
This commit is contained in:
@@ -98,6 +98,7 @@ export const SEND_DROPDOWN_MENU_SIZE = 'send-dropdown-menu-size';
|
|||||||
|
|
||||||
export const BROWSER_HISTORY_PUSH = 'browser-history-push';
|
export const BROWSER_HISTORY_PUSH = 'browser-history-push';
|
||||||
export const APP_LOGGED_IN = 'app-logged-in';
|
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';
|
export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ import {
|
|||||||
CLOSE_TEAMS_DROPDOWN,
|
CLOSE_TEAMS_DROPDOWN,
|
||||||
BROWSER_HISTORY_PUSH,
|
BROWSER_HISTORY_PUSH,
|
||||||
APP_LOGGED_IN,
|
APP_LOGGED_IN,
|
||||||
|
APP_LOGGED_OUT,
|
||||||
GET_VIEW_NAME,
|
GET_VIEW_NAME,
|
||||||
GET_VIEW_WEBCONTENTS_ID,
|
GET_VIEW_WEBCONTENTS_ID,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
@@ -256,6 +257,9 @@ window.addEventListener('storage', (e) => {
|
|||||||
if (e.key === '__login__' && e.storageArea === localStorage && e.newValue) {
|
if (e.key === '__login__' && e.storageArea === localStorage && e.newValue) {
|
||||||
ipcRenderer.send(APP_LOGGED_IN, viewName);
|
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 */
|
/* eslint-enable no-magic-numbers */
|
||||||
|
@@ -47,6 +47,7 @@ export class MattermostView extends EventEmitter {
|
|||||||
window: BrowserWindow;
|
window: BrowserWindow;
|
||||||
view: BrowserView;
|
view: BrowserView;
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
|
isLoggedIn: boolean;
|
||||||
options: BrowserViewConstructorOptions;
|
options: BrowserViewConstructorOptions;
|
||||||
serverInfo: ServerInfo;
|
serverInfo: ServerInfo;
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ export class MattermostView extends EventEmitter {
|
|||||||
...options.webPreferences,
|
...options.webPreferences,
|
||||||
};
|
};
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
|
this.isLoggedIn = false;
|
||||||
this.view = new BrowserView(this.options);
|
this.view = new BrowserView(this.options);
|
||||||
this.resetLoadingStatus();
|
this.resetLoadingStatus();
|
||||||
|
|
||||||
|
@@ -20,6 +20,7 @@ import {
|
|||||||
APP_LOGGED_IN,
|
APP_LOGGED_IN,
|
||||||
GET_VIEW_NAME,
|
GET_VIEW_NAME,
|
||||||
GET_VIEW_WEBCONTENTS_ID,
|
GET_VIEW_WEBCONTENTS_ID,
|
||||||
|
APP_LOGGED_OUT,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
import urlUtils from 'common/utils/url';
|
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(LOADING_SCREEN_ANIMATION_FINISHED, handleLoadingScreenAnimationFinished);
|
||||||
ipcMain.on(BROWSER_HISTORY_PUSH, handleBrowserHistoryPush);
|
ipcMain.on(BROWSER_HISTORY_PUSH, handleBrowserHistoryPush);
|
||||||
ipcMain.on(APP_LOGGED_IN, handleAppLoggedIn);
|
ipcMain.on(APP_LOGGED_IN, handleAppLoggedIn);
|
||||||
|
ipcMain.on(APP_LOGGED_OUT, handleAppLoggedOut);
|
||||||
ipcMain.handle(GET_VIEW_NAME, handleGetViewName);
|
ipcMain.handle(GET_VIEW_NAME, handleGetViewName);
|
||||||
ipcMain.handle(GET_VIEW_WEBCONTENTS_ID, handleGetWebContentsId);
|
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)) {
|
if (status.viewManager?.closedViews.has(redirectedViewName)) {
|
||||||
status.viewManager.openClosedTab(redirectedViewName, `${currentView?.tab.server.url}${pathName}`);
|
status.viewManager.openClosedTab(redirectedViewName, `${currentView?.tab.server.url}${pathName}`);
|
||||||
}
|
}
|
||||||
const redirectedView = status.viewManager?.views.get(redirectedViewName) || currentView;
|
let redirectedView = status.viewManager?.views.get(redirectedViewName) || currentView;
|
||||||
if (redirectedView !== currentView && redirectedView?.tab.server.name === status.currentServerName) {
|
if (redirectedView !== currentView && redirectedView?.tab.server.name === status.currentServerName && redirectedView?.isLoggedIn) {
|
||||||
log.info('redirecting to a new view', redirectedView?.name || viewName);
|
log.info('redirecting to a new view', redirectedView?.name || viewName);
|
||||||
status.viewManager?.showByName(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
|
// Special case check for Channels to not force a redirect to "/", causing a refresh
|
||||||
@@ -587,8 +591,19 @@ export function getCurrentTeamName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleAppLoggedIn(event: IpcMainEvent, viewName: string) {
|
function handleAppLoggedIn(event: IpcMainEvent, viewName: string) {
|
||||||
|
const view = status.viewManager?.views.get(viewName);
|
||||||
|
if (view) {
|
||||||
|
view.isLoggedIn = true;
|
||||||
status.viewManager?.reloadViewIfNeeded(viewName);
|
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) {
|
function handleGetViewName(event: IpcMainInvokeEvent) {
|
||||||
return getViewNameByWebContentsId(event.sender.id);
|
return getViewNameByWebContentsId(event.sender.id);
|
||||||
|
Reference in New Issue
Block a user