[MM-40574] Fix for race condition where new server modal didn't show initially on Linux, resizing issues (#1865)

* FIx for linux modal sizing

* Fix race condition, merge'd
This commit is contained in:
Devin Binnie 2021-12-17 09:10:08 -05:00 committed by Devin Binnie
parent 36bc2a4e31
commit 41e29b70b0
5 changed files with 50 additions and 10 deletions

View file

@ -101,3 +101,5 @@ export const APP_LOGGED_IN = 'app-logged-in';
export const APP_LOGGED_OUT = 'app-logged-out';
export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checker-languages';
export const RESIZE_MODAL = 'resize-modal';

View file

@ -324,7 +324,7 @@ function handleConfigSynchronize() {
updateServerInfos(config.teams);
WindowManager.initializeCurrentServerName();
if (config.teams.length === 0) {
handleNewServerModal();
addNewServerModalWhenMainWindowIsShown();
}
}
}
@ -798,7 +798,7 @@ function initializeAfterAppReady() {
if (process.platform !== 'win32' || typeof config.registryConfigData !== 'undefined') {
if (config.teams.length === 0) {
setTimeout(() => {
handleNewServerModal();
addNewServerModalWhenMainWindowIsShown();
}, 200);
}
}
@ -982,3 +982,16 @@ function handleUpdateLastActive(event: IpcMainEvent, serverName: string, viewNam
function handleGetAvailableSpellCheckerLanguages() {
return session.defaultSession.availableSpellCheckerLanguages;
}
function addNewServerModalWhenMainWindowIsShown() {
const mainWindow = WindowManager.getMainWindow();
if (mainWindow) {
if (mainWindow.isVisible()) {
handleNewServerModal();
} else {
mainWindow.once('show', () => {
handleNewServerModal();
});
}
}
}

View file

@ -6,7 +6,18 @@ import {IpcMainEvent, IpcMainInvokeEvent} from 'electron/main';
import {CombinedConfig} from 'types/config';
import {RETRIEVE_MODAL_INFO, MODAL_CANCEL, MODAL_RESULT, MODAL_OPEN, MODAL_CLOSE, EMIT_CONFIGURATION, DARK_MODE_CHANGE} from 'common/communication';
import {
RETRIEVE_MODAL_INFO,
MODAL_CANCEL,
MODAL_RESULT,
MODAL_OPEN,
MODAL_CLOSE,
EMIT_CONFIGURATION,
DARK_MODE_CHANGE,
RESIZE_MODAL,
} from 'common/communication';
import {getAdjustedWindowBoundaries} from 'main/utils';
import * as WindowManager from '../windows/windowManager';
@ -37,6 +48,7 @@ export function addModal<T, T2>(key: string, html: string, preload: string, data
ipcMain.handle(RETRIEVE_MODAL_INFO, handleInfoRequest);
ipcMain.on(MODAL_RESULT, handleModalResult);
ipcMain.on(MODAL_CANCEL, handleModalCancel);
ipcMain.on(RESIZE_MODAL, handleResizeModal);
function findModalByCaller(event: IpcMainInvokeEvent) {
if (modalQueue.length) {
@ -99,6 +111,13 @@ function handleModalCancel(event: IpcMainEvent, data: unknown) {
}
}
function handleResizeModal(event: IpcMainEvent, bounds: Electron.Rectangle) {
if (modalQueue.length) {
const currentModal = modalQueue[0];
currentModal.view.setBounds(getAdjustedWindowBoundaries(bounds.width, bounds.height));
}
}
function filterActive() {
modalQueue = modalQueue.filter((modal) => modal.isActive());
}

View file

@ -64,13 +64,17 @@ export class ModalView<T, T2> {
this.windowAttached = win || this.window;
this.windowAttached.addBrowserView(this.view);
this.view.setBounds(getWindowBoundaries(this.windowAttached));
this.view.setAutoResize({
height: true,
width: true,
horizontal: true,
vertical: true,
});
// Linux sometimes doesn't have the bound initialized correctly initially, so we wait to set them
const setBoundsFunction = () => {
this.view.setBounds(getWindowBoundaries(this.windowAttached!));
};
if (process.platform === 'linux') {
setTimeout(setBoundsFunction, 10);
} else {
setBoundsFunction();
}
this.status = Status.SHOWING;
if (this.view.webContents.isLoading()) {
this.view.webContents.once('did-finish-load', () => {

View file

@ -18,6 +18,7 @@ import {
UPDATE_SHORTCUT_MENU,
BROWSER_HISTORY_PUSH,
APP_LOGGED_IN,
RESIZE_MODAL,
APP_LOGGED_OUT,
} from 'common/communication';
import urlUtils from 'common/utils/url';
@ -188,6 +189,7 @@ function handleResizeMainWindow() {
}
status.viewManager.setLoadingScreenBounds();
status.teamDropdown?.updateWindowBounds();
ipcMain.emit(RESIZE_MODAL, null, bounds);
}
export function sendToRenderer(channel: string, ...args: any[]) {