[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
This commit is contained in:
Tasos Boulis
2022-11-04 16:11:56 +02:00
committed by GitHub
parent 5ab1eceade
commit 935cf3a0cc
7 changed files with 61 additions and 28 deletions

View File

@@ -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);
});
}
}