Migrate viewManager to singleton (#2656)
This commit is contained in:
@@ -5,7 +5,7 @@ import {app, dialog} from 'electron';
|
||||
|
||||
import CertificateStore from 'main/certificateStore';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
|
||||
import {handleAppWillFinishLaunching, handleAppCertificateError, certificateErrorCallbacks} from 'main/app/app';
|
||||
import {getDeeplinkingURL, openDeepLink} from 'main/app/utils';
|
||||
@@ -21,13 +21,6 @@ jest.mock('electron', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('common/config', () => ({
|
||||
teams: [{
|
||||
name: 'test-team',
|
||||
url: 'http://server-1.com',
|
||||
}],
|
||||
}));
|
||||
|
||||
jest.mock('main/app/utils', () => ({
|
||||
getDeeplinkingURL: jest.fn(),
|
||||
openDeepLink: jest.fn(),
|
||||
@@ -46,11 +39,14 @@ jest.mock('main/i18nManager', () => ({
|
||||
}));
|
||||
jest.mock('main/tray/tray', () => ({}));
|
||||
jest.mock('main/windows/windowManager', () => ({
|
||||
getViewNameByWebContentsId: jest.fn(),
|
||||
getServerNameByWebContentsId: jest.fn(),
|
||||
viewManager: {
|
||||
views: new Map(),
|
||||
},
|
||||
showMainWindow: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/windows/mainWindow', () => ({
|
||||
get: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/views/viewManager', () => ({
|
||||
getView: jest.fn(),
|
||||
getViewByWebContentsId: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/windows/mainWindow', () => ({
|
||||
get: jest.fn(),
|
||||
@@ -71,7 +67,6 @@ describe('main/app/app', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
WindowManager.viewManager.views.clear();
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
@@ -104,10 +99,19 @@ describe('main/app/app', () => {
|
||||
const mainWindow = {};
|
||||
const promise = Promise.resolve({});
|
||||
const certificate = {};
|
||||
const view = {
|
||||
tab: {
|
||||
server: {
|
||||
name: 'test-team',
|
||||
url: new URL(testURL),
|
||||
},
|
||||
},
|
||||
load: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
MainWindow.get.mockReturnValue(mainWindow);
|
||||
WindowManager.getServerNameByWebContentsId.mockReturnValue('test-team');
|
||||
ViewManager.getViewByWebContentsId.mockReturnValue(view);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -166,12 +170,9 @@ describe('main/app/app', () => {
|
||||
|
||||
it('should load URL using MattermostView when trusting certificate', async () => {
|
||||
dialog.showMessageBox.mockResolvedValue({response: 0});
|
||||
const load = jest.fn();
|
||||
WindowManager.viewManager.views.set('view-name', {load});
|
||||
WindowManager.getViewNameByWebContentsId.mockReturnValue('view-name');
|
||||
await handleAppCertificateError(event, webContents, testURL, 'error-1', certificate, callback);
|
||||
expect(callback).toHaveBeenCalledWith(true);
|
||||
expect(load).toHaveBeenCalledWith(testURL);
|
||||
expect(view.load).toHaveBeenCalledWith(testURL);
|
||||
});
|
||||
|
||||
it('should explicitly untrust if user selects More Details and then cancel with the checkbox checked', async () => {
|
||||
|
@@ -5,13 +5,13 @@ import {app, BrowserWindow, Event, dialog, WebContents, Certificate, Details} fr
|
||||
|
||||
import {Logger} from 'common/log';
|
||||
import urlUtils from 'common/utils/url';
|
||||
import Config from 'common/config';
|
||||
|
||||
import updateManager from 'main/autoUpdater';
|
||||
import CertificateStore from 'main/certificateStore';
|
||||
import {localizeMessage} from 'main/i18nManager';
|
||||
import {destroyTray} from 'main/tray/tray';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
import {getDeeplinkingURL, openDeepLink, resizeScreen} from './utils';
|
||||
@@ -95,10 +95,9 @@ export async function handleAppCertificateError(event: Event, webContents: WebCo
|
||||
// update the callback
|
||||
const errorID = `${origin}:${error}`;
|
||||
|
||||
const serverName = WindowManager.getServerNameByWebContentsId(webContents.id);
|
||||
const server = Config.teams.find((team) => team.name === serverName);
|
||||
if (server) {
|
||||
const serverURL = urlUtils.parseURL(server.url);
|
||||
const view = ViewManager.getViewByWebContentsId(webContents.id);
|
||||
if (view?.tab.server) {
|
||||
const serverURL = urlUtils.parseURL(view.tab.server.url);
|
||||
if (serverURL && serverURL.origin !== origin) {
|
||||
log.warn(`Ignoring certificate for unmatched origin ${origin}, will not trust`);
|
||||
callback(false);
|
||||
@@ -159,10 +158,8 @@ export async function handleAppCertificateError(event: Event, webContents: WebCo
|
||||
CertificateStore.save();
|
||||
certificateErrorCallbacks.get(errorID)(true);
|
||||
|
||||
const viewName = WindowManager.getViewNameByWebContentsId(webContents.id);
|
||||
if (viewName) {
|
||||
const view = WindowManager.viewManager?.views.get(viewName);
|
||||
view?.load(url);
|
||||
if (view) {
|
||||
view.load(url);
|
||||
} else {
|
||||
webContents.loadURL(url);
|
||||
}
|
||||
|
@@ -44,6 +44,9 @@ jest.mock('main/badge', () => ({
|
||||
jest.mock('main/tray/tray', () => ({
|
||||
refreshTrayImages: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/views/viewManager', () => ({
|
||||
reloadConfiguration: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/views/loadingScreen', () => ({}));
|
||||
jest.mock('main/windows/windowManager', () => ({
|
||||
handleUpdateConfig: jest.fn(),
|
||||
|
@@ -12,6 +12,7 @@ import {Logger, setLoggingLevel} from 'common/log';
|
||||
import AutoLauncher from 'main/AutoLauncher';
|
||||
import {setUnreadBadgeSetting} from 'main/badge';
|
||||
import {refreshTrayImages} from 'main/tray/tray';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
import LoadingScreen from 'main/views/loadingScreen';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
|
||||
@@ -36,8 +37,8 @@ export function handleConfigUpdate(newConfig: CombinedConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowManager.handleUpdateConfig();
|
||||
if (app.isReady()) {
|
||||
ViewManager.reloadConfiguration();
|
||||
WindowManager.sendToRenderer(RELOAD_CONFIGURATION);
|
||||
}
|
||||
|
||||
|
@@ -162,6 +162,7 @@ jest.mock('main/windows/windowManager', () => ({
|
||||
getServerNameByWebContentsId: jest.fn(),
|
||||
getServerURLFromWebContentsId: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/views/viewManager', () => ({}));
|
||||
jest.mock('main/windows/settingsWindow', () => ({
|
||||
show: jest.fn(),
|
||||
}));
|
||||
|
@@ -56,6 +56,7 @@ import SettingsWindow from 'main/windows/settingsWindow';
|
||||
import TrustedOriginsStore from 'main/trustedOrigins';
|
||||
import {refreshTrayImages, setupTray} from 'main/tray/tray';
|
||||
import UserActivityMonitor from 'main/UserActivityMonitor';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
@@ -238,7 +239,7 @@ function initializeInterCommunicationEventListeners() {
|
||||
ipcMain.on(NOTIFY_MENTION, handleMentionNotification);
|
||||
ipcMain.handle('get-app-version', handleAppVersion);
|
||||
ipcMain.on(UPDATE_SHORTCUT_MENU, handleUpdateMenuEvent);
|
||||
ipcMain.on(FOCUS_BROWSERVIEW, WindowManager.focusBrowserView);
|
||||
ipcMain.on(FOCUS_BROWSERVIEW, ViewManager.focusCurrentView);
|
||||
ipcMain.on(UPDATE_LAST_ACTIVE, handleUpdateLastActive);
|
||||
|
||||
if (process.platform !== 'darwin') {
|
||||
@@ -351,7 +352,7 @@ function initializeAfterAppReady() {
|
||||
// listen for status updates and pass on to renderer
|
||||
UserActivityMonitor.on('status', (status) => {
|
||||
log.debug('UserActivityMonitor.on(status)', status);
|
||||
WindowManager.sendToMattermostViews(USER_ACTIVITY_UPDATE, status);
|
||||
ViewManager.sendToAllViews(USER_ACTIVITY_UPDATE, status);
|
||||
});
|
||||
|
||||
// start monitoring user activity (needs to be started after the app is ready)
|
||||
|
@@ -30,6 +30,7 @@ jest.mock('main/utils', () => ({
|
||||
getLocalPreload: jest.fn(),
|
||||
getLocalURLString: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/views/viewManager', () => ({}));
|
||||
jest.mock('main/views/modalManager', () => ({
|
||||
addModal: jest.fn(),
|
||||
}));
|
||||
|
@@ -14,6 +14,7 @@ import {ping} from 'common/utils/requests';
|
||||
import {displayMention} from 'main/notifications';
|
||||
import {getLocalPreload, getLocalURLString} from 'main/utils';
|
||||
import ModalManager from 'main/views/modalManager';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
@@ -26,7 +27,7 @@ export function handleReloadConfig() {
|
||||
log.debug('handleReloadConfig');
|
||||
|
||||
Config.reload();
|
||||
WindowManager.handleUpdateConfig();
|
||||
ViewManager.reloadConfiguration();
|
||||
}
|
||||
|
||||
export function handleAppVersion() {
|
||||
|
@@ -60,6 +60,7 @@ jest.mock('main/server/serverInfo', () => ({
|
||||
ServerInfo: jest.fn(),
|
||||
}));
|
||||
jest.mock('main/tray/tray', () => ({}));
|
||||
jest.mock('main/views/viewManager', () => ({}));
|
||||
jest.mock('main/windows/mainWindow', () => ({}));
|
||||
jest.mock('main/windows/windowManager', () => ({}));
|
||||
|
||||
|
@@ -27,6 +27,7 @@ import {createMenu as createAppMenu} from 'main/menus/app';
|
||||
import {createMenu as createTrayMenu} from 'main/menus/tray';
|
||||
import {ServerInfo} from 'main/server/serverInfo';
|
||||
import {setTrayMenu} from 'main/tray/tray';
|
||||
import ViewManager from 'main/views/viewManager';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
@@ -110,7 +111,7 @@ export function handleUpdateMenuEvent() {
|
||||
const aMenu = createAppMenu(Config, updateManager);
|
||||
Menu.setApplicationMenu(aMenu);
|
||||
aMenu.addListener('menu-will-close', () => {
|
||||
WindowManager.focusBrowserView();
|
||||
ViewManager.focusCurrentView();
|
||||
WindowManager.sendToRenderer(APP_MENU_WILL_CLOSE);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user