Fix the issue where we sometimes need to wait for GPO teams properly (#2621)

This commit is contained in:
Devin Binnie
2023-03-20 16:24:07 -04:00
committed by GitHub
parent a4444bda1e
commit c85a4497b6
5 changed files with 31 additions and 42 deletions

View File

@@ -106,9 +106,17 @@ export class Config extends EventEmitter {
if (process.platform === 'darwin' || process.platform === 'win32') {
nativeTheme.on('updated', this.handleUpdateTheme);
}
this.registryConfig = new RegistryConfig();
this.registryConfig.once(REGISTRY_READ_EVENT, this.loadRegistry);
this.registryConfig.init();
}
initRegistry = () => {
return new Promise<void>((resolve) => {
this.registryConfig = new RegistryConfig();
this.registryConfig.once(REGISTRY_READ_EVENT, (data) => {
this.loadRegistry(data);
resolve();
});
this.registryConfig.init();
});
}
/**

View File

@@ -17,8 +17,6 @@ import WindowManager from 'main/windows/windowManager';
import {handleMainWindowIsShown} from './intercom';
import {handleUpdateMenuEvent, setLoggingLevel, updateServerInfos, updateSpellCheckerLocales} from './utils';
let didCheckForAddServerModal = false;
//
// config event handlers
//
@@ -63,12 +61,9 @@ export function handleConfigUpdate(newConfig: CombinedConfig) {
});
}
if (process.platform === 'win32' && !didCheckForAddServerModal && typeof Config.registryConfigData !== 'undefined') {
didCheckForAddServerModal = true;
updateServerInfos(newConfig.teams);
WindowManager.initializeCurrentServerName();
handleMainWindowIsShown();
}
updateServerInfos(newConfig.teams);
WindowManager.initializeCurrentServerName();
handleMainWindowIsShown();
handleUpdateMenuEvent();
if (newConfig.trayIconTheme) {

View File

@@ -97,6 +97,7 @@ jest.mock('common/config', () => ({
once: jest.fn(),
on: jest.fn(),
init: jest.fn(),
initRegistry: jest.fn(),
}));
jest.mock('common/utils/url', () => ({

View File

@@ -117,6 +117,7 @@ export async function initialize() {
// wait for registry config data to load and app ready event
await Promise.all([
app.whenReady(),
Config.initRegistry(),
]);
// no need to continue initializing if app is quitting
@@ -425,10 +426,7 @@ function initializeAfterAppReady() {
callback(urlUtils.isTrustedURL(requestingURL, serverURL));
});
// only check for non-Windows, as with Windows we have to wait for GPO teams
if (process.platform !== 'win32' || typeof Config.registryConfigData !== 'undefined') {
handleMainWindowIsShown();
}
handleMainWindowIsShown();
}
function handleStartDownload() {

View File

@@ -4,11 +4,10 @@
import {app, dialog, IpcMainEvent, IpcMainInvokeEvent, Menu} from 'electron';
import log from 'electron-log';
import {Team, TeamWithIndex, RegistryConfig as RegistryConfigType} from 'types/config';
import {Team, TeamWithIndex} from 'types/config';
import {MentionData} from 'types/notification';
import Config from 'common/config';
import {REGISTRY_READ_EVENT} from 'common/config/RegistryConfig';
import {getDefaultTeamWithTabsFromTeam} from 'common/tabs/TabView';
import {ping} from 'common/utils/requests';
@@ -89,36 +88,24 @@ export function handleOpenTab(event: IpcMainEvent, serverName: string, tabName:
export function handleShowOnboardingScreens(showWelcomeScreen: boolean, showNewServerModal: boolean, mainWindowIsVisible: boolean) {
log.debug('Intercom.handleShowOnboardingScreens', {showWelcomeScreen, showNewServerModal, mainWindowIsVisible});
const showWelcomeScreenFunc = () => {
if (showWelcomeScreen) {
handleWelcomeScreenModal();
if (showWelcomeScreen) {
handleWelcomeScreenModal();
if (process.env.NODE_ENV === 'test') {
const welcomeScreen = ModalManager.modalQueue.find((modal) => modal.key === 'welcomeScreen');
if (welcomeScreen?.view.webContents.isLoading()) {
welcomeScreen?.view.webContents.once('did-finish-load', () => {
app.emit('e2e-app-loaded');
});
} else {
if (process.env.NODE_ENV === 'test') {
const welcomeScreen = ModalManager.modalQueue.find((modal) => modal.key === 'welcomeScreen');
if (welcomeScreen?.view.webContents.isLoading()) {
welcomeScreen?.view.webContents.once('did-finish-load', () => {
app.emit('e2e-app-loaded');
}
});
} else {
app.emit('e2e-app-loaded');
}
return;
}
if (showNewServerModal) {
handleNewServerModal();
}
};
if (process.platform === 'win32' && !Config.registryConfigData) {
Config.registryConfig.once(REGISTRY_READ_EVENT, (data: Partial<RegistryConfigType>) => {
if (data.teams?.length === 0) {
showWelcomeScreenFunc();
}
});
} else {
showWelcomeScreenFunc();
return;
}
if (showNewServerModal) {
handleNewServerModal();
}
}