Remove WindowManager, separate functionality into smaller modules (#2682)
* Move sendToRenderer to respective singletons * Move to using ViewManager call for getting view by webContentsId * Move show and create logic to main window, handle deep linking seperately * Move resizing logic and event handing to mainWindow * Move server switching logic to main/app * Move tab switching logic to main/app, rely on showById for most usage * Migrate remaining functions, remove windowManager objects, set up imports for self-contained singletons * Fix E2E tests * Update src/main/app/servers.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> --------- Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import {app, dialog, IpcMainEvent, IpcMainInvokeEvent, Menu} from 'electron';
|
||||
|
||||
import {Team, MattermostTeam} from 'types/config';
|
||||
import {MattermostTeam} from 'types/config';
|
||||
import {MentionData} from 'types/notification';
|
||||
|
||||
import Config from 'common/config';
|
||||
@@ -14,10 +14,10 @@ import {displayMention} from 'main/notifications';
|
||||
import {getLocalPreload, getLocalURLString} from 'main/utils';
|
||||
import ServerManager from 'common/servers/serverManager';
|
||||
import ModalManager from 'main/views/modalManager';
|
||||
import WindowManager from 'main/windows/windowManager';
|
||||
import MainWindow from 'main/windows/mainWindow';
|
||||
|
||||
import {handleAppBeforeQuit} from './app';
|
||||
import {handleNewServerModal, switchServer} from './servers';
|
||||
|
||||
const log = new Logger('App.Intercom');
|
||||
|
||||
@@ -35,49 +35,6 @@ export function handleQuit(e: IpcMainEvent, reason: string, stack: string) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
export function handleSwitchServer(event: IpcMainEvent, serverId: string) {
|
||||
log.silly('handleSwitchServer', serverId);
|
||||
WindowManager.switchServer(serverId);
|
||||
}
|
||||
|
||||
export function handleSwitchTab(event: IpcMainEvent, tabId: string) {
|
||||
log.silly('handleSwitchTab', {tabId});
|
||||
WindowManager.switchTab(tabId);
|
||||
}
|
||||
|
||||
export function handleCloseTab(event: IpcMainEvent, tabId: string) {
|
||||
log.debug('handleCloseTab', {tabId});
|
||||
|
||||
const tab = ServerManager.getTab(tabId);
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
ServerManager.setTabIsOpen(tabId, false);
|
||||
const nextTab = ServerManager.getLastActiveTabForServer(tab.server.id);
|
||||
WindowManager.switchTab(nextTab.id);
|
||||
}
|
||||
|
||||
export function handleOpenTab(event: IpcMainEvent, tabId: string) {
|
||||
log.debug('handleOpenTab', {tabId});
|
||||
|
||||
ServerManager.setTabIsOpen(tabId, true);
|
||||
WindowManager.switchTab(tabId);
|
||||
}
|
||||
|
||||
export function handleGetOrderedServers() {
|
||||
return ServerManager.getOrderedServers().map((srv) => srv.toMattermostTeam());
|
||||
}
|
||||
|
||||
export function handleGetOrderedTabsForServer(event: IpcMainInvokeEvent, serverId: string) {
|
||||
return ServerManager.getOrderedTabsForServer(serverId).map((tab) => tab.toMattermostTab());
|
||||
}
|
||||
|
||||
export function handleGetLastActive() {
|
||||
const server = ServerManager.getCurrentServer();
|
||||
const tab = ServerManager.getLastActiveTabForServer(server.id);
|
||||
return {server: server.id, tab: tab.id};
|
||||
}
|
||||
|
||||
function handleShowOnboardingScreens(showWelcomeScreen: boolean, showNewServerModal: boolean, mainWindowIsVisible: boolean) {
|
||||
log.debug('handleShowOnboardingScreens', {showWelcomeScreen, showNewServerModal, mainWindowIsVisible});
|
||||
|
||||
@@ -126,101 +83,6 @@ export function handleMainWindowIsShown() {
|
||||
}
|
||||
}
|
||||
|
||||
export function handleNewServerModal() {
|
||||
log.debug('handleNewServerModal');
|
||||
|
||||
const html = getLocalURLString('newServer.html');
|
||||
|
||||
const preload = getLocalPreload('desktopAPI.js');
|
||||
|
||||
const mainWindow = MainWindow.get();
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
const modalPromise = ModalManager.addModal<MattermostTeam[], Team>('newServer', html, preload, ServerManager.getAllServers().map((team) => team.toMattermostTeam()), mainWindow, !ServerManager.hasServers());
|
||||
if (modalPromise) {
|
||||
modalPromise.then((data) => {
|
||||
const newTeam = ServerManager.addServer(data);
|
||||
WindowManager.switchServer(newTeam.id, true);
|
||||
}).catch((e) => {
|
||||
// e is undefined for user cancellation
|
||||
if (e) {
|
||||
log.error(`there was an error in the new server modal: ${e}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.warn('There is already a new server modal');
|
||||
}
|
||||
}
|
||||
|
||||
export function handleEditServerModal(e: IpcMainEvent, id: string) {
|
||||
log.debug('handleEditServerModal', id);
|
||||
|
||||
const html = getLocalURLString('editServer.html');
|
||||
|
||||
const preload = getLocalPreload('desktopAPI.js');
|
||||
|
||||
const mainWindow = MainWindow.get();
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
const server = ServerManager.getServer(id);
|
||||
if (!server) {
|
||||
return;
|
||||
}
|
||||
const modalPromise = ModalManager.addModal<{currentTeams: MattermostTeam[]; team: MattermostTeam}, Team>(
|
||||
'editServer',
|
||||
html,
|
||||
preload,
|
||||
{
|
||||
currentTeams: ServerManager.getAllServers().map((team) => team.toMattermostTeam()),
|
||||
team: server.toMattermostTeam(),
|
||||
},
|
||||
mainWindow);
|
||||
if (modalPromise) {
|
||||
modalPromise.then((data) => ServerManager.editServer(id, data)).catch((e) => {
|
||||
// e is undefined for user cancellation
|
||||
if (e) {
|
||||
log.error(`there was an error in the edit server modal: ${e}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.warn('There is already an edit server modal');
|
||||
}
|
||||
}
|
||||
|
||||
export function handleRemoveServerModal(e: IpcMainEvent, id: string) {
|
||||
log.debug('handleRemoveServerModal', id);
|
||||
|
||||
const html = getLocalURLString('removeServer.html');
|
||||
|
||||
const preload = getLocalPreload('desktopAPI.js');
|
||||
|
||||
const server = ServerManager.getServer(id);
|
||||
if (!server) {
|
||||
return;
|
||||
}
|
||||
const mainWindow = MainWindow.get();
|
||||
if (!mainWindow) {
|
||||
return;
|
||||
}
|
||||
const modalPromise = ModalManager.addModal<string, boolean>('removeServer', html, preload, server.name, mainWindow);
|
||||
if (modalPromise) {
|
||||
modalPromise.then((remove) => {
|
||||
if (remove) {
|
||||
ServerManager.removeServer(server.id);
|
||||
}
|
||||
}).catch((e) => {
|
||||
// e is undefined for user cancellation
|
||||
if (e) {
|
||||
log.error(`there was an error in the edit server modal: ${e}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.warn('There is already an edit server modal');
|
||||
}
|
||||
}
|
||||
|
||||
export function handleWelcomeScreenModal() {
|
||||
log.debug('handleWelcomeScreenModal');
|
||||
|
||||
@@ -236,7 +98,7 @@ export function handleWelcomeScreenModal() {
|
||||
if (modalPromise) {
|
||||
modalPromise.then((data) => {
|
||||
const newTeam = ServerManager.addServer(data);
|
||||
WindowManager.switchServer(newTeam.id, true);
|
||||
switchServer(newTeam.id, true);
|
||||
}).catch((e) => {
|
||||
// e is undefined for user cancellation
|
||||
if (e) {
|
||||
|
Reference in New Issue
Block a user