Skip to content

Commit

Permalink
fix(compatibility): fix the plugin can't be registered after setup
Browse files Browse the repository at this point in the history
Moved the request to get the custom logos when the plugin is mounted on
the UI. It means that the plugin is initially registered using the default image
displayed on the platform menu and after the logo can change if it is
customized. It could result in blink to change the logos.
  • Loading branch information
Desvelao committed Nov 7, 2022
1 parent 99c1930 commit 77dbe7d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,34 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
private innerAngularInitialized: boolean = false;
private stateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private hideTelemetryBanner?: () => void;
public async setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {
public setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {
const UI_THEME = core.uiSettings.get('theme:darkMode') ? 'dark' : 'light';

// Get custom logos configuration to start up the app with the correct logos
let logosInitialState={};
try{
logosInitialState = await core.http.get(`/api/logos`);
}
catch(error){
console.error('plugin.ts: Error getting logos configuration', error);
}

core.application.register({
id: `wazuh`,
title: 'Wazuh',
icon: core.http.basePath.prepend(
logosInitialState?.logos?.[SIDEBAR_LOGO] ?
getAssetURL(logosInitialState?.logos?.[SIDEBAR_LOGO]) :
getThemeAssetURL('icon.svg', UI_THEME)),
mount: async (params: AppMountParameters) => {
try {
if (!this.initializeInnerAngular) {
throw Error('Wazuh plugin method initializeInnerAngular is undefined');
}

// Get custom logos configuration to start up the app with the correct logos
let logosInitialState={};
try{
logosInitialState = await core.http.get(`/api/logos`);
}
catch(error){
console.error('plugin.ts: Error getting logos configuration', error);
}

// Update redux app state logos with the custom logos
if (logosInitialState?.logos) {
store.dispatch(updateAppConfig(logosInitialState.logos));
}
};

// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && await this.hideTelemetryBanner();
Expand Down Expand Up @@ -118,7 +117,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
id: 'wazuh',
label: 'Wazuh',
order: 0,
euiIconType: core.http.basePath.prepend(logosInitialState?.logos?.[SIDEBAR_LOGO] ? getAssetURL(logosInitialState?.logos?.[SIDEBAR_LOGO]) : getThemeAssetURL('icon.svg', UI_THEME)),
euiIconType: core.http.basePath.prepend(getThemeAssetURL('icon.svg', UI_THEME)),
},
updater$: this.stateUpdater
});
Expand Down

0 comments on commit 77dbe7d

Please sign in to comment.