From 935cf3a0ccb37b0a910c898c1c22759897a087b7 Mon Sep 17 00:00:00 2001 From: Tasos Boulis Date: Fri, 4 Nov 2022 16:11:56 +0200 Subject: [PATCH] [MM-48079] Dont show server login when GPO has preconfigured servers (#2346) * Show onboarding server screen only when teams.length is 0 * Add tests * Add more tests * Fix issue where callback would not re-evaluate variables --- package.json | 3 ++- src/jestSetup.js | 1 - src/main/app/config.ts | 4 +--- src/main/app/initialize.ts | 4 +--- src/main/app/intercom.test.js | 31 ++++++++++++++++++++++++ src/main/app/intercom.ts | 45 ++++++++++++++++++++--------------- src/types/config.ts | 1 - 7 files changed, 61 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index a0c7cf29..b8a9d22e 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,8 @@ "__CAN_UPGRADE__": false, "__IS_NIGHTLY_BUILD__": false, "__IS_MAC_APP_STORE__": false, - "__DISABLE_GPU__": false + "__DISABLE_GPU__": false, + "__SKIP_ONBOARDING_SCREENS__": false }, "setupFiles": [ "./src/jestSetup.js" diff --git a/src/jestSetup.js b/src/jestSetup.js index d52e28aa..cdaf3226 100644 --- a/src/jestSetup.js +++ b/src/jestSetup.js @@ -25,4 +25,3 @@ jest.mock('electron-log', () => ({ }, }, })); - diff --git a/src/main/app/config.ts b/src/main/app/config.ts index 1b74f974..de71a6d2 100644 --- a/src/main/app/config.ts +++ b/src/main/app/config.ts @@ -60,9 +60,7 @@ export function handleConfigUpdate(newConfig: CombinedConfig) { didCheckForAddServerModal = true; updateServerInfos(newConfig.teams); WindowManager.initializeCurrentServerName(); - if (newConfig.teams.length === 0) { - handleMainWindowIsShown(); - } + handleMainWindowIsShown(); } log.info('Log level set to:', newConfig.logLevel); diff --git a/src/main/app/initialize.ts b/src/main/app/initialize.ts index da9fef54..67569842 100644 --- a/src/main/app/initialize.ts +++ b/src/main/app/initialize.ts @@ -406,9 +406,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) { - handleMainWindowIsShown(); - } + handleMainWindowIsShown(); } } diff --git a/src/main/app/intercom.test.js b/src/main/app/intercom.test.js index f07e08a9..9d403760 100644 --- a/src/main/app/intercom.test.js +++ b/src/main/app/intercom.test.js @@ -15,6 +15,8 @@ import { handleEditServerModal, handleRemoveServerModal, handleWelcomeScreenModal, + handleMainWindowIsShown, + handleShowOnboardingScreens, } from './intercom'; jest.mock('common/config', () => ({ @@ -257,4 +259,33 @@ describe('main/app/intercom', () => { expect(ModalManager.addModal).toHaveBeenCalledWith('welcomeScreen', '/some/index.html', '/some/preload.js', [], {}, true); }); }); + + describe('handleMainWindowIsShown', () => { + it('MM-48079 should not show onboarding screen or server screen if GPO server is pre-configured', () => { + getLocalURLString.mockReturnValue('/some/index.html'); + getLocalPreload.mockReturnValue('/some/preload.js'); + WindowManager.getMainWindow.mockReturnValue({ + isVisible: () => true, + }); + + Config.set.mockImplementation((name, value) => { + Config[name] = value; + }); + Config.teams = JSON.parse(JSON.stringify([{ + name: 'test-team', + order: 0, + url: 'https://someurl.here', + }])); + + handleMainWindowIsShown(); + expect(ModalManager.addModal).not.toHaveBeenCalled(); + }); + }); + + describe('handleShowOnboardingScreens', () => { + it('MM-48079 should not show onboarding screen or server screen if GPO server is pre-configured', () => { + handleShowOnboardingScreens(false, false, true); + expect(ModalManager.addModal).not.toHaveBeenCalled(); + }); + }); }); diff --git a/src/main/app/intercom.ts b/src/main/app/intercom.ts index 25b24e94..37e9f7e3 100644 --- a/src/main/app/intercom.ts +++ b/src/main/app/intercom.ts @@ -85,31 +85,38 @@ export function handleOpenTab(event: IpcMainEvent, serverName: string, tabName: Config.set('teams', teams); } +export function handleShowOnboardingScreens(showWelcomeScreen: boolean, showNewServerModal: boolean, mainWindowIsVisible: boolean) { + log.debug('Intercom.handleShowOnboardingScreens', {showWelcomeScreen, showNewServerModal, mainWindowIsVisible}); + if (showWelcomeScreen) { + handleWelcomeScreenModal(); + return; + } + if (showNewServerModal) { + handleNewServerModal(); + } +} + export function handleMainWindowIsShown() { // eslint-disable-next-line no-undef // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const showWelcomeScreen = !(Boolean(__SKIP_ONBOARDING_SCREENS__) || Config.teams.length); + const showWelcomeScreen = () => !(Boolean(__SKIP_ONBOARDING_SCREENS__) || Config.teams.length); + const showNewServerModal = () => Config.teams.length === 0; + + /** + * The 2 lines above need to be functions, otherwise the mainWindow.once() callback from previous + * calls of this function will notification re-evaluate the booleans passed to "handleShowOnboardingScreens". + */ + const mainWindow = WindowManager.getMainWindow(); - if (mainWindow) { - if (mainWindow.isVisible()) { - if (showWelcomeScreen) { - handleWelcomeScreenModal(); - } else { - handleNewServerModal(); - } - } else { - mainWindow.once('show', () => { - if (showWelcomeScreen) { - log.debug('Intercom.handleMainWindowIsShown.show.welcomeScreenModal'); - handleWelcomeScreenModal(); - } else { - log.debug('Intercom.handleMainWindowIsShown.show.newServerModal'); - handleNewServerModal(); - } - }); - } + log.debug('intercom.handleMainWindowIsShown', {configTeams: Config.teams, showWelcomeScreen, showNewServerModal, mainWindow: Boolean(mainWindow)}); + if (mainWindow?.isVisible()) { + handleShowOnboardingScreens(showWelcomeScreen(), showNewServerModal(), true); + } else { + mainWindow?.once('show', () => { + handleShowOnboardingScreens(showWelcomeScreen(), showNewServerModal(), false); + }); } } diff --git a/src/types/config.ts b/src/types/config.ts index 2fe4daa5..f0a643ea 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -118,7 +118,6 @@ export type CombinedConfig = ConfigV3 & BuildConfig & { registryTeams: Team[]; appName: string; useNativeWindow: boolean; - } export type LocalConfiguration = Config & {