[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 GitHub
parent 9b1ee66c8c
commit c4e63fb3f9
9 changed files with 48 additions and 17 deletions

View File

@@ -98,6 +98,7 @@ export const GET_AVAILABLE_SPELL_CHECKER_LANGUAGES = 'get-available-spell-checke
export const GET_VIEW_NAME = 'get-view-name';
export const GET_VIEW_WEBCONTENTS_ID = 'get-view-webcontents-id';
export const RESIZE_MODAL = 'resize-modal';
export const GET_MODAL_UNCLOSEABLE = 'get-modal-uncloseable';
export const MODAL_UNCLOSEABLE = 'modal-uncloseable';

View File

@@ -7,7 +7,7 @@ import {RELOAD_CONFIGURATION} from 'common/communication';
import Config from 'common/config';
import {handleConfigUpdate} from 'main/app/config';
import {handleNewServerModal} from 'main/app/intercom';
import {addNewServerModalWhenMainWindowIsShown} from 'main/app/intercom';
import WindowManager from 'main/windows/windowManager';
import AutoLauncher from 'main/AutoLauncher';
@@ -32,7 +32,7 @@ jest.mock('main/app/utils', () => ({
updateServerInfos: jest.fn(),
}));
jest.mock('main/app/intercom', () => ({
handleNewServerModal: jest.fn(),
addNewServerModalWhenMainWindowIsShown: jest.fn(),
}));
jest.mock('main/AutoLauncher', () => ({
enable: jest.fn(),
@@ -98,7 +98,7 @@ describe('main/app/config', () => {
Config.registryConfigData = {};
handleConfigUpdate({teams: []});
expect(handleNewServerModal).toHaveBeenCalled();
expect(addNewServerModalWhenMainWindowIsShown).toHaveBeenCalled();
Object.defineProperty(process, 'platform', {
value: originalPlatform,

View File

@@ -14,7 +14,7 @@ import {setUnreadBadgeSetting} from 'main/badge';
import {refreshTrayImages} from 'main/tray/tray';
import WindowManager from 'main/windows/windowManager';
import {handleNewServerModal} from './intercom';
import {addNewServerModalWhenMainWindowIsShown} from './intercom';
import {handleUpdateMenuEvent, updateServerInfos, updateSpellCheckerLocales} from './utils';
let didCheckForAddServerModal = false;
@@ -58,7 +58,7 @@ export function handleConfigUpdate(newConfig: CombinedConfig) {
updateServerInfos(newConfig.teams);
WindowManager.initializeCurrentServerName();
if (newConfig.teams.length === 0) {
handleNewServerModal();
addNewServerModalWhenMainWindowIsShown();
}
}

View File

@@ -95,7 +95,9 @@ jest.mock('main/app/app', () => ({}));
jest.mock('main/app/config', () => ({
handleConfigUpdate: jest.fn(),
}));
jest.mock('main/app/intercom', () => ({}));
jest.mock('main/app/intercom', () => ({
addNewServerModalWhenMainWindowIsShown: jest.fn(),
}));
jest.mock('main/app/utils', () => ({
clearAppCache: jest.fn(),
getDeeplinkingURL: jest.fn(),

View File

@@ -63,6 +63,7 @@ import {
} from './app';
import {handleConfigUpdate, handleDarkModeChange} from './config';
import {
addNewServerModalWhenMainWindowIsShown,
handleAppVersion,
handleCloseTab,
handleEditServerModal,
@@ -373,9 +374,7 @@ function initializeAfterAppReady() {
// only check for non-Windows, as with Windows we have to wait for GPO teams
if (process.platform !== 'win32' || typeof Config.registryConfigData !== 'undefined') {
if (Config.teams.length === 0) {
setTimeout(() => {
handleNewServerModal();
}, 200);
addNewServerModalWhenMainWindowIsShown();
}
}
}

View File

@@ -76,6 +76,19 @@ export function handleOpenTab(event: IpcMainEvent, serverName: string, tabName:
Config.set('teams', teams);
}
export function addNewServerModalWhenMainWindowIsShown() {
const mainWindow = WindowManager.getMainWindow();
if (mainWindow) {
if (mainWindow.isVisible()) {
handleNewServerModal();
} else {
mainWindow.once('show', () => {
handleNewServerModal();
});
}
}
}
export function handleNewServerModal() {
const html = getLocalURLString('newServer.html');

View File

@@ -15,9 +15,11 @@ import {
EMIT_CONFIGURATION,
DARK_MODE_CHANGE,
GET_MODAL_UNCLOSEABLE,
RESIZE_MODAL,
} from 'common/communication';
import WindowManager from '../windows/windowManager';
import {getAdjustedWindowBoundaries} from 'main/utils';
import WindowManager from 'main/windows/windowManager';
import {ModalView} from './modalView';
@@ -33,6 +35,7 @@ export class ModalManager {
ipcMain.handle(RETRIEVE_MODAL_INFO, this.handleInfoRequest);
ipcMain.on(MODAL_RESULT, this.handleModalResult);
ipcMain.on(MODAL_CANCEL, this.handleModalCancel);
ipcMain.on(RESIZE_MODAL, this.handleResizeModal);
ipcMain.on(EMIT_CONFIGURATION, this.handleEmitConfiguration);
}
@@ -118,6 +121,13 @@ export class ModalManager {
return this.modalQueue.some((modal) => modal.isActive());
}
handleResizeModal = (event: IpcMainEvent, bounds: Electron.Rectangle) => {
if (this.modalQueue.length) {
const currentModal = this.modalQueue[0];
currentModal.view.setBounds(getAdjustedWindowBoundaries(bounds.width, bounds.height));
}
}
focusCurrentModal = () => {
if (this.isModalDisplayed()) {
this.modalQueue[0].view.webContents.focus();

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

@@ -19,6 +19,7 @@ import {
APP_LOGGED_IN,
GET_VIEW_NAME,
GET_VIEW_WEBCONTENTS_ID,
RESIZE_MODAL,
APP_LOGGED_OUT,
} from 'common/communication';
import urlUtils from 'common/utils/url';
@@ -183,6 +184,7 @@ export class WindowManager {
}
this.viewManager.setLoadingScreenBounds();
this.teamDropdown?.updateWindowBounds();
ipcMain.emit(RESIZE_MODAL, null, bounds);
}
sendToRenderer = (channel: string, ...args: any[]) => {