[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:
@@ -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';
|
||||
|
||||
|
@@ -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,
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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(),
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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');
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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[]) => {
|
||||
|
Reference in New Issue
Block a user