[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_NAME = 'get-view-name';
|
||||||
export const GET_VIEW_WEBCONTENTS_ID = 'get-view-webcontents-id';
|
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 GET_MODAL_UNCLOSEABLE = 'get-modal-uncloseable';
|
||||||
export const MODAL_UNCLOSEABLE = 'modal-uncloseable';
|
export const MODAL_UNCLOSEABLE = 'modal-uncloseable';
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ import {RELOAD_CONFIGURATION} from 'common/communication';
|
|||||||
import Config from 'common/config';
|
import Config from 'common/config';
|
||||||
|
|
||||||
import {handleConfigUpdate} from 'main/app/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 WindowManager from 'main/windows/windowManager';
|
||||||
import AutoLauncher from 'main/AutoLauncher';
|
import AutoLauncher from 'main/AutoLauncher';
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ jest.mock('main/app/utils', () => ({
|
|||||||
updateServerInfos: jest.fn(),
|
updateServerInfos: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('main/app/intercom', () => ({
|
jest.mock('main/app/intercom', () => ({
|
||||||
handleNewServerModal: jest.fn(),
|
addNewServerModalWhenMainWindowIsShown: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('main/AutoLauncher', () => ({
|
jest.mock('main/AutoLauncher', () => ({
|
||||||
enable: jest.fn(),
|
enable: jest.fn(),
|
||||||
@@ -98,7 +98,7 @@ describe('main/app/config', () => {
|
|||||||
Config.registryConfigData = {};
|
Config.registryConfigData = {};
|
||||||
|
|
||||||
handleConfigUpdate({teams: []});
|
handleConfigUpdate({teams: []});
|
||||||
expect(handleNewServerModal).toHaveBeenCalled();
|
expect(addNewServerModalWhenMainWindowIsShown).toHaveBeenCalled();
|
||||||
|
|
||||||
Object.defineProperty(process, 'platform', {
|
Object.defineProperty(process, 'platform', {
|
||||||
value: originalPlatform,
|
value: originalPlatform,
|
||||||
|
@@ -14,7 +14,7 @@ import {setUnreadBadgeSetting} from 'main/badge';
|
|||||||
import {refreshTrayImages} from 'main/tray/tray';
|
import {refreshTrayImages} from 'main/tray/tray';
|
||||||
import WindowManager from 'main/windows/windowManager';
|
import WindowManager from 'main/windows/windowManager';
|
||||||
|
|
||||||
import {handleNewServerModal} from './intercom';
|
import {addNewServerModalWhenMainWindowIsShown} from './intercom';
|
||||||
import {handleUpdateMenuEvent, updateServerInfos, updateSpellCheckerLocales} from './utils';
|
import {handleUpdateMenuEvent, updateServerInfos, updateSpellCheckerLocales} from './utils';
|
||||||
|
|
||||||
let didCheckForAddServerModal = false;
|
let didCheckForAddServerModal = false;
|
||||||
@@ -58,7 +58,7 @@ export function handleConfigUpdate(newConfig: CombinedConfig) {
|
|||||||
updateServerInfos(newConfig.teams);
|
updateServerInfos(newConfig.teams);
|
||||||
WindowManager.initializeCurrentServerName();
|
WindowManager.initializeCurrentServerName();
|
||||||
if (newConfig.teams.length === 0) {
|
if (newConfig.teams.length === 0) {
|
||||||
handleNewServerModal();
|
addNewServerModalWhenMainWindowIsShown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -95,7 +95,9 @@ jest.mock('main/app/app', () => ({}));
|
|||||||
jest.mock('main/app/config', () => ({
|
jest.mock('main/app/config', () => ({
|
||||||
handleConfigUpdate: jest.fn(),
|
handleConfigUpdate: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('main/app/intercom', () => ({}));
|
jest.mock('main/app/intercom', () => ({
|
||||||
|
addNewServerModalWhenMainWindowIsShown: jest.fn(),
|
||||||
|
}));
|
||||||
jest.mock('main/app/utils', () => ({
|
jest.mock('main/app/utils', () => ({
|
||||||
clearAppCache: jest.fn(),
|
clearAppCache: jest.fn(),
|
||||||
getDeeplinkingURL: jest.fn(),
|
getDeeplinkingURL: jest.fn(),
|
||||||
|
@@ -63,6 +63,7 @@ import {
|
|||||||
} from './app';
|
} from './app';
|
||||||
import {handleConfigUpdate, handleDarkModeChange} from './config';
|
import {handleConfigUpdate, handleDarkModeChange} from './config';
|
||||||
import {
|
import {
|
||||||
|
addNewServerModalWhenMainWindowIsShown,
|
||||||
handleAppVersion,
|
handleAppVersion,
|
||||||
handleCloseTab,
|
handleCloseTab,
|
||||||
handleEditServerModal,
|
handleEditServerModal,
|
||||||
@@ -373,9 +374,7 @@ function initializeAfterAppReady() {
|
|||||||
// only check for non-Windows, as with Windows we have to wait for GPO teams
|
// only check for non-Windows, as with Windows we have to wait for GPO teams
|
||||||
if (process.platform !== 'win32' || typeof Config.registryConfigData !== 'undefined') {
|
if (process.platform !== 'win32' || typeof Config.registryConfigData !== 'undefined') {
|
||||||
if (Config.teams.length === 0) {
|
if (Config.teams.length === 0) {
|
||||||
setTimeout(() => {
|
addNewServerModalWhenMainWindowIsShown();
|
||||||
handleNewServerModal();
|
|
||||||
}, 200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,6 +76,19 @@ export function handleOpenTab(event: IpcMainEvent, serverName: string, tabName:
|
|||||||
Config.set('teams', teams);
|
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() {
|
export function handleNewServerModal() {
|
||||||
const html = getLocalURLString('newServer.html');
|
const html = getLocalURLString('newServer.html');
|
||||||
|
|
||||||
|
@@ -15,9 +15,11 @@ import {
|
|||||||
EMIT_CONFIGURATION,
|
EMIT_CONFIGURATION,
|
||||||
DARK_MODE_CHANGE,
|
DARK_MODE_CHANGE,
|
||||||
GET_MODAL_UNCLOSEABLE,
|
GET_MODAL_UNCLOSEABLE,
|
||||||
|
RESIZE_MODAL,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
|
|
||||||
import WindowManager from '../windows/windowManager';
|
import {getAdjustedWindowBoundaries} from 'main/utils';
|
||||||
|
import WindowManager from 'main/windows/windowManager';
|
||||||
|
|
||||||
import {ModalView} from './modalView';
|
import {ModalView} from './modalView';
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ export class ModalManager {
|
|||||||
ipcMain.handle(RETRIEVE_MODAL_INFO, this.handleInfoRequest);
|
ipcMain.handle(RETRIEVE_MODAL_INFO, this.handleInfoRequest);
|
||||||
ipcMain.on(MODAL_RESULT, this.handleModalResult);
|
ipcMain.on(MODAL_RESULT, this.handleModalResult);
|
||||||
ipcMain.on(MODAL_CANCEL, this.handleModalCancel);
|
ipcMain.on(MODAL_CANCEL, this.handleModalCancel);
|
||||||
|
ipcMain.on(RESIZE_MODAL, this.handleResizeModal);
|
||||||
|
|
||||||
ipcMain.on(EMIT_CONFIGURATION, this.handleEmitConfiguration);
|
ipcMain.on(EMIT_CONFIGURATION, this.handleEmitConfiguration);
|
||||||
}
|
}
|
||||||
@@ -118,6 +121,13 @@ export class ModalManager {
|
|||||||
return this.modalQueue.some((modal) => modal.isActive());
|
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 = () => {
|
focusCurrentModal = () => {
|
||||||
if (this.isModalDisplayed()) {
|
if (this.isModalDisplayed()) {
|
||||||
this.modalQueue[0].view.webContents.focus();
|
this.modalQueue[0].view.webContents.focus();
|
||||||
|
@@ -64,13 +64,17 @@ export class ModalView<T, T2> {
|
|||||||
this.windowAttached = win || this.window;
|
this.windowAttached = win || this.window;
|
||||||
|
|
||||||
this.windowAttached.addBrowserView(this.view);
|
this.windowAttached.addBrowserView(this.view);
|
||||||
this.view.setBounds(getWindowBoundaries(this.windowAttached));
|
|
||||||
this.view.setAutoResize({
|
// Linux sometimes doesn't have the bound initialized correctly initially, so we wait to set them
|
||||||
height: true,
|
const setBoundsFunction = () => {
|
||||||
width: true,
|
this.view.setBounds(getWindowBoundaries(this.windowAttached!));
|
||||||
horizontal: true,
|
};
|
||||||
vertical: true,
|
if (process.platform === 'linux') {
|
||||||
});
|
setTimeout(setBoundsFunction, 10);
|
||||||
|
} else {
|
||||||
|
setBoundsFunction();
|
||||||
|
}
|
||||||
|
|
||||||
this.status = Status.SHOWING;
|
this.status = Status.SHOWING;
|
||||||
if (this.view.webContents.isLoading()) {
|
if (this.view.webContents.isLoading()) {
|
||||||
this.view.webContents.once('did-finish-load', () => {
|
this.view.webContents.once('did-finish-load', () => {
|
||||||
|
@@ -19,6 +19,7 @@ import {
|
|||||||
APP_LOGGED_IN,
|
APP_LOGGED_IN,
|
||||||
GET_VIEW_NAME,
|
GET_VIEW_NAME,
|
||||||
GET_VIEW_WEBCONTENTS_ID,
|
GET_VIEW_WEBCONTENTS_ID,
|
||||||
|
RESIZE_MODAL,
|
||||||
APP_LOGGED_OUT,
|
APP_LOGGED_OUT,
|
||||||
} from 'common/communication';
|
} from 'common/communication';
|
||||||
import urlUtils from 'common/utils/url';
|
import urlUtils from 'common/utils/url';
|
||||||
@@ -183,6 +184,7 @@ export class WindowManager {
|
|||||||
}
|
}
|
||||||
this.viewManager.setLoadingScreenBounds();
|
this.viewManager.setLoadingScreenBounds();
|
||||||
this.teamDropdown?.updateWindowBounds();
|
this.teamDropdown?.updateWindowBounds();
|
||||||
|
ipcMain.emit(RESIZE_MODAL, null, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendToRenderer = (channel: string, ...args: any[]) => {
|
sendToRenderer = (channel: string, ...args: any[]) => {
|
||||||
|
Reference in New Issue
Block a user