From 41e29b70b0bdf1b4c9b318327b84846be6bc96dd Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 17 Dec 2021 09:10:08 -0500 Subject: [PATCH] [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 --- src/common/communication.ts | 2 ++ src/main/main.ts | 17 +++++++++++++++-- src/main/views/modalManager.ts | 21 ++++++++++++++++++++- src/main/views/modalView.ts | 18 +++++++++++------- src/main/windows/windowManager.ts | 2 ++ 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/common/communication.ts b/src/common/communication.ts index b3db8100..649b50b1 100644 --- a/src/common/communication.ts +++ b/src/common/communication.ts @@ -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'; diff --git a/src/main/main.ts b/src/main/main.ts index adc130e4..61f951d5 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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(); + }); + } + } +} diff --git a/src/main/views/modalManager.ts b/src/main/views/modalManager.ts index 976cb781..dde9e229 100644 --- a/src/main/views/modalManager.ts +++ b/src/main/views/modalManager.ts @@ -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(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()); } diff --git a/src/main/views/modalView.ts b/src/main/views/modalView.ts index 5358a20e..caa1c03d 100644 --- a/src/main/views/modalView.ts +++ b/src/main/views/modalView.ts @@ -64,13 +64,17 @@ export class ModalView { 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', () => { diff --git a/src/main/windows/windowManager.ts b/src/main/windows/windowManager.ts index 5e24b85a..dd1d2869 100644 --- a/src/main/windows/windowManager.ts +++ b/src/main/windows/windowManager.ts @@ -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[]) {