[MM-59489] Change logged in tracking code for new API, check for /
when navigating tabs (#3105)
* [MM-59489] Change logged in tracking code for new API, check for `/` when navigating tabs * Better naming
This commit is contained in:
parent
7af6601e23
commit
a00cb4c814
|
@ -98,6 +98,7 @@ export const NO_UPDATE_AVAILABLE = 'no-update-available';
|
|||
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 TAB_LOGIN_CHANGED = 'tab-login-changed';
|
||||
|
||||
export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import {
|
|||
GET_DESKTOP_SOURCES,
|
||||
UNREADS_AND_MENTIONS,
|
||||
LEGACY_OFF,
|
||||
TAB_LOGIN_CHANGED,
|
||||
} from 'common/communication';
|
||||
|
||||
import type {ExternalAPI} from 'types/externalAPI';
|
||||
|
@ -73,8 +74,8 @@ const desktopAPI: DesktopAPI = {
|
|||
setSessionExpired: (isExpired) => ipcRenderer.send(SESSION_EXPIRED, isExpired),
|
||||
onUserActivityUpdate: (listener) => createListener(USER_ACTIVITY_UPDATE, listener),
|
||||
|
||||
onLogin: () => ipcRenderer.send(APP_LOGGED_IN),
|
||||
onLogout: () => ipcRenderer.send(APP_LOGGED_OUT),
|
||||
onLogin: () => ipcRenderer.send(TAB_LOGIN_CHANGED, true),
|
||||
onLogout: () => ipcRenderer.send(TAB_LOGIN_CHANGED, false),
|
||||
|
||||
// Unreads/mentions/notifications
|
||||
sendNotification: (title, body, channelId, teamId, url, silent, soundName) =>
|
||||
|
|
|
@ -33,6 +33,7 @@ import {
|
|||
REQUEST_BROWSER_HISTORY_STATUS,
|
||||
LEGACY_OFF,
|
||||
UNREADS_AND_MENTIONS,
|
||||
TAB_LOGIN_CHANGED,
|
||||
} from 'common/communication';
|
||||
import Config from 'common/config';
|
||||
import {Logger} from 'common/log';
|
||||
|
@ -80,6 +81,7 @@ export class ViewManager {
|
|||
ipcMain.on(BROWSER_HISTORY_PUSH, this.handleBrowserHistoryPush);
|
||||
ipcMain.on(APP_LOGGED_IN, this.handleAppLoggedIn);
|
||||
ipcMain.on(APP_LOGGED_OUT, this.handleAppLoggedOut);
|
||||
ipcMain.on(TAB_LOGIN_CHANGED, this.handleTabLoginChanged);
|
||||
ipcMain.on(RELOAD_CURRENT_VIEW, this.handleReloadCurrentView);
|
||||
ipcMain.on(UNREAD_RESULT, this.handleUnreadChanged);
|
||||
ipcMain.on(UNREADS_AND_MENTIONS, this.handleUnreadsAndMentionsChanged);
|
||||
|
@ -504,6 +506,25 @@ export class ViewManager {
|
|||
flushCookiesStore();
|
||||
};
|
||||
|
||||
private handleTabLoginChanged = (event: IpcMainEvent, loggedIn: boolean) => {
|
||||
log.debug('handleTabLoggedIn', event.sender.id);
|
||||
const view = this.getViewByWebContentsId(event.sender.id);
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This method is only called when the specific view is logged in
|
||||
// so we need to call the `onLogin` for all of the views for the same server
|
||||
[...this.views.values()].
|
||||
filter((v) => v.view.server.id === view.view.server.id).
|
||||
forEach((v) => v.onLogin(loggedIn));
|
||||
|
||||
if (!loggedIn) {
|
||||
AppState.clear(view.id);
|
||||
}
|
||||
flushCookiesStore();
|
||||
};
|
||||
|
||||
private handleBrowserHistoryPush = (e: IpcMainEvent, pathName: string) => {
|
||||
log.debug('handleBrowserHistoryPush', e.sender.id, pathName);
|
||||
|
||||
|
@ -522,7 +543,7 @@ export class ViewManager {
|
|||
return;
|
||||
}
|
||||
let redirectedView = this.getView(redirectedviewId) || currentView;
|
||||
if (redirectedView !== currentView && redirectedView?.view.server.id === ServerViewState.getCurrentServer().id && redirectedView?.isLoggedIn) {
|
||||
if (redirectedView !== currentView && redirectedView?.view.server.id === ServerViewState.getCurrentServer().id && (redirectedView?.isLoggedIn || cleanedPathName === '/')) {
|
||||
log.info('redirecting to a new view', redirectedView?.id || currentView.id);
|
||||
this.showById(redirectedView?.id || currentView.id);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue