Recent searches


No recent searches

instance.created gets triggered before the instance ist fully loaded



Posted May 09, 2024

We have different versions of one NavBar-App with different Icons. I'm trying to set the AppIcon from a background instance, but this isnt working as expected.

 

  1. Sometimes the Navbar Instance is loaded before the Background Instance, so instance.created is not triggered. Why?!
  2. Even if the background Instance is loaded first and the instance.created event ist triggered with a navbar-instance, the navbar-instance is obviously not fully loaded since navbarClient.set('iconSymbol', appSymbol) or navbarClient.invoke('preloadPane') does not work. Only if i use it within a settimeout block

 

async function setNavBarSymbol() {

   const appData = await client.metadata()

   const parameters = appData.settings;

   const appSymbol = parameters['SymbolID'];

   const instancesData = await client.get('instances');

   const instances = instancesData.instances;

   for (let instanceGuid in instances) {

      if (instances[instanceGuid].location === 'nav_bar') {

         client.instance(instanceGuid).set('iconSymbol', appSymbol);

      }

   }

}

 

This does not work:

 

client.on('instance.created', async function (data) {

   await setNavBarSymbol();

});

 

This does work:

 

client.on('instance.created', async function (data) {

   setTimeout(async () => {

      await setNavBarSymbol();

   }, 2000);

});

 

It makes no sense to me to trigger the instance.created event if the instance is not fully loaded.

 

Please fix that or provide me a better solution without a settimeout, which is not reliable

 


0

3

3 comments

image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Vlad! I would recommend using instance.registered instead of instance.created. This ensures that the new location has been loaded and is not in a transient state.

0


Hi Greg,

instance.registered is not triggered if the app is only displayed in the navbar, only when you click on the app. This is also stated in the documentation: "Fires when an app instance is loaded and registers a SDK client."
I want to change the app icon when the page is loaded, even before the navbar app is used, so instance.registered is not an option.

0


is there any update regarding this? 

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post