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.
- Sometimes the Navbar Instance is loaded before the Background Instance, so instance.created is not triggered. Why?!
- 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 comments
Greg Katechis
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
Vlad
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
Vlad
is there any update regarding this?
0