Refactor config, move ipc calls to app module, some cleanup (#2669)

This commit is contained in:
Devin Binnie
2023-04-06 11:24:57 -04:00
committed by GitHub
parent 88eb2e2c70
commit 741087cb55
29 changed files with 551 additions and 638 deletions

View File

@@ -19,6 +19,7 @@ import {
UPDATE_DOWNLOADS_DROPDOWN_MENU_ITEM,
} from 'common/communication';
import {Logger} from 'common/log';
import Config from 'common/config';
import {
DOWNLOADS_DROPDOWN_FULL_WIDTH,
DOWNLOADS_DROPDOWN_MENU_FULL_HEIGHT,
@@ -26,10 +27,9 @@ import {
TAB_BAR_HEIGHT,
} from 'common/utils/constants';
import {getLocalPreload, getLocalURLString} from 'main/utils';
import WindowManager from '../windows/windowManager';
import downloadsManager from 'main/downloadsManager';
import MainWindow from 'main/windows/mainWindow';
import WindowManager from 'main/windows/windowManager';
const log = new Logger('DownloadsDropdownMenuView');
@@ -42,11 +42,11 @@ export default class DownloadsDropdownMenuView {
darkMode: boolean;
windowBounds: Electron.Rectangle;
constructor(darkMode: boolean) {
constructor() {
this.open = false;
this.item = undefined;
this.coordinates = undefined;
this.darkMode = darkMode;
this.darkMode = Config.darkMode;
ipcMain.on(OPEN_DOWNLOADS_DROPDOWN_MENU, this.handleOpen);
ipcMain.on(CLOSE_DOWNLOADS_DROPDOWN_MENU, this.handleClose);

View File

@@ -62,6 +62,7 @@ jest.mock('electron', () => {
};
});
jest.mock('main/downloadsManager', () => ({
getDownloads: jest.fn(),
onOpen: jest.fn(),
onClose: jest.fn(),
}));

View File

@@ -19,11 +19,12 @@ import {
DOWNLOADS_DROPDOWN_OPEN_FILE,
} from 'common/communication';
import {Logger} from 'common/log';
import Config from 'common/config';
import {TAB_BAR_HEIGHT, DOWNLOADS_DROPDOWN_WIDTH, DOWNLOADS_DROPDOWN_HEIGHT, DOWNLOADS_DROPDOWN_FULL_WIDTH} from 'common/utils/constants';
import {getLocalPreload, getLocalURLString} from 'main/utils';
import WindowManager from '../windows/windowManager';
import {getLocalPreload, getLocalURLString} from 'main/utils';
import downloadsManager from 'main/downloadsManager';
import WindowManager from 'main/windows/windowManager';
import MainWindow from 'main/windows/mainWindow';
const log = new Logger('DownloadsDropdownView');
@@ -36,9 +37,9 @@ export default class DownloadsDropdownView {
view: BrowserView;
windowBounds: Electron.Rectangle;
constructor(downloads: DownloadedItems, darkMode: boolean) {
this.downloads = downloads;
this.darkMode = darkMode;
constructor() {
this.downloads = downloadsManager.getDownloads();
this.darkMode = Config.darkMode;
ipcMain.on(OPEN_DOWNLOADS_DROPDOWN, this.handleOpen);
ipcMain.on(CLOSE_DOWNLOADS_DROPDOWN, this.handleClose);

View File

@@ -15,10 +15,6 @@ jest.mock('electron', () => ({
},
}));
jest.mock('common/config', () => ({
teams: [],
}));
jest.mock('main/views/webContentEvents', () => ({
addWebContentsEventListeners: jest.fn(),
}));

View File

@@ -17,7 +17,6 @@ import {
GET_MODAL_UNCLOSEABLE,
RESIZE_MODAL,
} from 'common/communication';
import Config from 'common/config';
import {Logger} from 'common/log';
import {getAdjustedWindowBoundaries} from 'main/utils';
@@ -91,7 +90,7 @@ export class ModalManager {
if (index === 0) {
WindowManager.sendToRenderer(MODAL_OPEN);
modal.show(undefined, Boolean(withDevTools));
WebContentsEventManager.addWebContentsEventListeners(modal.view.webContents, () => Config.teams.concat());
WebContentsEventManager.addWebContentsEventListeners(modal.view.webContents);
} else {
WindowManager.sendToRenderer(MODAL_CLOSE);
modal.hide();

View File

@@ -42,7 +42,7 @@ describe('main/views/teamDropdownView', () => {
MainWindow.getBounds.mockReturnValue({width: 500, height: 400, x: 0, y: 0});
});
const teamDropdownView = new TeamDropdownView([], false, true);
const teamDropdownView = new TeamDropdownView();
if (process.platform === 'darwin') {
it('should account for three dot menu, tab bar and shadow', () => {
expect(teamDropdownView.getBounds(400, 300)).toStrictEqual({x: THREE_DOT_MENU_WIDTH_MAC - MENU_SHADOW_WIDTH, y: TAB_BAR_HEIGHT - MENU_SHADOW_WIDTH, width: 400, height: 300});
@@ -55,7 +55,7 @@ describe('main/views/teamDropdownView', () => {
});
it('should change the view bounds based on open/closed state', () => {
const teamDropdownView = new TeamDropdownView([], false, true);
const teamDropdownView = new TeamDropdownView();
teamDropdownView.bounds = {width: 400, height: 300};
teamDropdownView.handleOpen();
expect(teamDropdownView.view.setBounds).toBeCalledWith(teamDropdownView.bounds);
@@ -65,7 +65,7 @@ describe('main/views/teamDropdownView', () => {
describe('addGpoToTeams', () => {
it('should return teams with "isGPO": false when no config.registryTeams exist', () => {
const teamDropdownView = new TeamDropdownView([], false, true);
const teamDropdownView = new TeamDropdownView();
const teams = [{
name: 'team-1',
url: 'https://mattermost.team-1.com',
@@ -86,7 +86,7 @@ describe('main/views/teamDropdownView', () => {
}]);
});
it('should return teams with "isGPO": true if they exist in config.registryTeams', () => {
const teamDropdownView = new TeamDropdownView([], false, true);
const teamDropdownView = new TeamDropdownView();
const teams = [{
name: 'team-1',
url: 'https://mattermost.team-1.com',

View File

@@ -15,9 +15,12 @@ import {
RECEIVE_DROPDOWN_MENU_SIZE,
SET_ACTIVE_VIEW,
} from 'common/communication';
import Config from 'common/config';
import {Logger} from 'common/log';
import {TAB_BAR_HEIGHT, THREE_DOT_MENU_WIDTH, THREE_DOT_MENU_WIDTH_MAC, MENU_SHADOW_WIDTH} from 'common/utils/constants';
import {getLocalPreload, getLocalURLString} from 'main/utils';
import * as AppState from '../appState';
import WindowManager from '../windows/windowManager';
import MainWindow from '../windows/mainWindow';
@@ -38,10 +41,10 @@ export default class TeamDropdownView {
windowBounds?: Electron.Rectangle;
isOpen: boolean;
constructor(teams: TeamWithTabs[], darkMode: boolean, enableServerManagement: boolean) {
this.teams = this.addGpoToTeams(teams, []);
this.darkMode = darkMode;
this.enableServerManagement = enableServerManagement;
constructor() {
this.teams = this.addGpoToTeams(Config.teams, []);
this.darkMode = Config.darkMode;
this.enableServerManagement = Config.enableServerManagement;
this.isOpen = false;
this.windowBounds = MainWindow.getBounds();