[MM-52333] Create Server View State module, move into new app
module (#2739)
* Create Server View State Module * Move currentServerId to serverViewState * Move view state into server view state module * PR feedback/bug fixes
This commit is contained in:
@@ -9,6 +9,8 @@ import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
import {ServerDropdownView} from './serverDropdownView';
|
||||
|
||||
jest.mock('app/serverViewState', () => ({}));
|
||||
|
||||
jest.mock('main/utils', () => ({
|
||||
getLocalPreload: (file) => file,
|
||||
getLocalURLString: (file) => file,
|
||||
|
@@ -5,6 +5,8 @@ import {BrowserView, ipcMain, IpcMainEvent} from 'electron';
|
||||
|
||||
import {UniqueServer} from 'types/config';
|
||||
|
||||
import ServerViewState from 'app/serverViewState';
|
||||
|
||||
import AppState from 'common/appState';
|
||||
import {
|
||||
CLOSE_SERVERS_DROPDOWN,
|
||||
@@ -98,7 +100,7 @@ export class ServerDropdownView {
|
||||
this.servers,
|
||||
Config.darkMode,
|
||||
this.windowBounds,
|
||||
ServerManager.hasServers() ? ServerManager.getCurrentServer().id : undefined,
|
||||
ServerManager.hasServers() ? ServerViewState.getCurrentServer().id : undefined,
|
||||
Config.enableServerManagement,
|
||||
this.hasGPOServers,
|
||||
this.expired,
|
||||
|
@@ -6,6 +6,8 @@
|
||||
|
||||
import {dialog} from 'electron';
|
||||
|
||||
import ServerViewState from 'app/serverViewState';
|
||||
|
||||
import {BROWSER_HISTORY_PUSH, LOAD_SUCCESS, SET_ACTIVE_VIEW} from 'common/communication';
|
||||
import {TAB_MESSAGING} from 'common/views/View';
|
||||
import ServerManager from 'common/servers/serverManager';
|
||||
@@ -30,6 +32,11 @@ jest.mock('electron', () => ({
|
||||
handle: jest.fn(),
|
||||
},
|
||||
}));
|
||||
jest.mock('app/serverViewState', () => ({
|
||||
getCurrentServer: jest.fn(),
|
||||
updateCurrentView: jest.fn(),
|
||||
init: jest.fn(),
|
||||
}));
|
||||
jest.mock('common/views/View', () => ({
|
||||
getViewName: jest.fn((a, b) => `${a}-${b}`),
|
||||
TAB_MESSAGING: 'view',
|
||||
@@ -70,13 +77,11 @@ jest.mock('main/windows/mainWindow', () => ({
|
||||
on: jest.fn(),
|
||||
}));
|
||||
jest.mock('common/servers/serverManager', () => ({
|
||||
getCurrentServer: jest.fn(),
|
||||
getOrderedTabsForServer: jest.fn(),
|
||||
getAllServers: jest.fn(),
|
||||
hasServers: jest.fn(),
|
||||
getLastActiveServer: jest.fn(),
|
||||
getLastActiveTabForServer: jest.fn(),
|
||||
updateLastActive: jest.fn(),
|
||||
lookupViewByURL: jest.fn(),
|
||||
getRemoteInfo: jest.fn(),
|
||||
on: jest.fn(),
|
||||
@@ -351,7 +356,7 @@ describe('main/views/viewManager', () => {
|
||||
viewManager.showById = jest.fn();
|
||||
MainWindow.get.mockReturnValue(window);
|
||||
ServerManager.hasServers.mockReturnValue(true);
|
||||
ServerManager.getCurrentServer.mockReturnValue({id: 'server-0'});
|
||||
ServerViewState.getCurrentServer.mockReturnValue({id: 'server-0'});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -440,7 +445,7 @@ describe('main/views/viewManager', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ServerManager.getAllServers.mockReturnValue(servers);
|
||||
ServerManager.getCurrentServer.mockReturnValue(servers[0]);
|
||||
ServerViewState.getCurrentServer.mockReturnValue(servers[0]);
|
||||
urlUtils.cleanPathName.mockImplementation((base, path) => path);
|
||||
});
|
||||
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
import {BrowserView, dialog, ipcMain, IpcMainEvent, IpcMainInvokeEvent} from 'electron';
|
||||
|
||||
import ServerViewState from 'app/serverViewState';
|
||||
|
||||
import AppState from 'common/appState';
|
||||
import {SECOND, TAB_BAR_HEIGHT} from 'common/utils/constants';
|
||||
import {
|
||||
@@ -27,6 +29,7 @@ import {
|
||||
MAIN_WINDOW_CREATED,
|
||||
MAIN_WINDOW_RESIZED,
|
||||
MAIN_WINDOW_FOCUSED,
|
||||
SWITCH_TAB,
|
||||
} from 'common/communication';
|
||||
import Config from 'common/config';
|
||||
import {Logger} from 'common/log';
|
||||
@@ -74,6 +77,8 @@ export class ViewManager {
|
||||
ipcMain.on(UNREAD_RESULT, this.handleFaviconIsUnread);
|
||||
ipcMain.on(SESSION_EXPIRED, this.handleSessionExpired);
|
||||
|
||||
ipcMain.on(SWITCH_TAB, (event, viewId) => this.showById(viewId));
|
||||
|
||||
ServerManager.on(SERVERS_UPDATE, this.handleReloadConfiguration);
|
||||
}
|
||||
|
||||
@@ -127,7 +132,7 @@ export class ViewManager {
|
||||
}
|
||||
hidePrevious?.();
|
||||
MainWindow.get()?.webContents.send(SET_ACTIVE_VIEW, newView.view.server.id, newView.view.id);
|
||||
ServerManager.updateLastActive(newView.view.id);
|
||||
ServerViewState.updateCurrentView(newView.view.server.id, newView.view.id);
|
||||
} else {
|
||||
this.getViewLogger(viewId).warn(`Couldn't find a view with name: ${viewId}`);
|
||||
}
|
||||
@@ -263,8 +268,10 @@ export class ViewManager {
|
||||
private showInitial = () => {
|
||||
log.verbose('showInitial');
|
||||
|
||||
// TODO: This init should be happening elsewhere, future refactor will fix this
|
||||
ServerViewState.init();
|
||||
if (ServerManager.hasServers()) {
|
||||
const lastActiveServer = ServerManager.getCurrentServer();
|
||||
const lastActiveServer = ServerViewState.getCurrentServer();
|
||||
const lastActiveView = ServerManager.getLastActiveTabForServer(lastActiveServer.id);
|
||||
this.showById(lastActiveView.id);
|
||||
} else {
|
||||
@@ -485,7 +492,7 @@ export class ViewManager {
|
||||
return;
|
||||
}
|
||||
let redirectedView = this.getView(redirectedviewId) || currentView;
|
||||
if (redirectedView !== currentView && redirectedView?.view.server.id === ServerManager.getCurrentServer().id && redirectedView?.isLoggedIn) {
|
||||
if (redirectedView !== currentView && redirectedView?.view.server.id === ServerViewState.getCurrentServer().id && redirectedView?.isLoggedIn) {
|
||||
log.info('redirecting to a new view', redirectedView?.id || viewId);
|
||||
this.showById(redirectedView?.id || viewId);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user