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') { if (process.platform === 'darwin' || process.platform === 'win32') {
nativeTheme.on('updated', this.handleUpdateTheme); 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 {handleMainWindowIsShown} from './intercom';
import {handleUpdateMenuEvent, setLoggingLevel, updateServerInfos, updateSpellCheckerLocales} from './utils'; import {handleUpdateMenuEvent, setLoggingLevel, updateServerInfos, updateSpellCheckerLocales} from './utils';
let didCheckForAddServerModal = false;
// //
// config event handlers // config event handlers
// //
@@ -63,12 +61,9 @@ export function handleConfigUpdate(newConfig: CombinedConfig) {
}); });
} }
if (process.platform === 'win32' && !didCheckForAddServerModal && typeof Config.registryConfigData !== 'undefined') { updateServerInfos(newConfig.teams);
didCheckForAddServerModal = true; WindowManager.initializeCurrentServerName();
updateServerInfos(newConfig.teams); handleMainWindowIsShown();
WindowManager.initializeCurrentServerName();
handleMainWindowIsShown();
}
handleUpdateMenuEvent(); handleUpdateMenuEvent();
if (newConfig.trayIconTheme) { if (newConfig.trayIconTheme) {

View File

@@ -97,6 +97,7 @@ jest.mock('common/config', () => ({
once: jest.fn(), once: jest.fn(),
on: jest.fn(), on: jest.fn(),
init: jest.fn(), init: jest.fn(),
initRegistry: jest.fn(),
})); }));
jest.mock('common/utils/url', () => ({ 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 // wait for registry config data to load and app ready event
await Promise.all([ await Promise.all([
app.whenReady(), app.whenReady(),
Config.initRegistry(),
]); ]);
// no need to continue initializing if app is quitting // no need to continue initializing if app is quitting
@@ -425,10 +426,7 @@ function initializeAfterAppReady() {
callback(urlUtils.isTrustedURL(requestingURL, serverURL)); callback(urlUtils.isTrustedURL(requestingURL, serverURL));
}); });
// only check for non-Windows, as with Windows we have to wait for GPO teams handleMainWindowIsShown();
if (process.platform !== 'win32' || typeof Config.registryConfigData !== 'undefined') {
handleMainWindowIsShown();
}
} }
function handleStartDownload() { function handleStartDownload() {

View File

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