Change PWA annotations dynamically

Hi,
i would like to change the value of @PWA dynamically.

For example, I have this annotation on my FormLogin:

@PWA(name = "Standard",
        enableInstallPrompt = true)
public class FormLogin extends VerticalLayout  { ... }

And install prompt show “Standard” text.

But I want to change dynamically the pwa name (f.e. from “Standard” to “Customer”) after reading a properties file.
I found how change annotation (checking in debug), but I don’t see the change on install prompt. It remains with “Standard” text.

I put this inside FormLogin:

@SuppressWarnings("unchecked")
public static Object changeAnnotationValue(Annotation annotation, String key, Object newValue){
		Object handler = Proxy.getInvocationHandler(annotation);
		Field f;
		try {
			f = handler.getClass().getDeclaredField("memberValues");
		} catch (NoSuchFieldException | SecurityException e) {
			throw new IllegalStateException(e);
		}
		f.setAccessible(true);
		Map<String, Object> memberValues;
		try {
			memberValues = (Map<String, Object>) f.get(handler);
		} catch (IllegalArgumentException | IllegalAccessException e) {
			throw new IllegalStateException(e);
		}
		Object oldValue = memberValues.get(key);
		if (oldValue == null || oldValue.getClass() != newValue.getClass()) {
			throw new IllegalArgumentException();
		}
		memberValues.put(key,newValue);
		return oldValue;
}

and I check the effective change:

annotations =  FormLogin.class.getAnnotations();
for (Annotation ann : annotations) {
			if (ann instanceof PWA) {
				System.out.println(((PWA) ann).name());
			}
}

System.out show me “Customer” but when page loads I always see “Standard”

Thanks in advance

In development mode, the framework reads the annotation value quite early during the deployment phase which is probably before your custom code has run. It gets even more challenging in production mode because then the annotation may be read by vaadin-maven-plugin during the build.

Thanks for your reply.
I’m already in Production Mode.

The framework certainly reads the annotation before my code because I put it in the constructor of the annotated class, but I don’t know where I can put the custom properties to change it at runtime.
My final target is to create one app and install it in different location changing only the properties file…

I’ve also tried with a manifest file but it doesn’t work.

I’ve put a file named manifest.json in the src/main/webapp directory as documentation said, and changed the @Pwa annotation:

@PWA(name = "Standard",
     shortName = "Standard",
     manifestPath = "manifest.json"
    )

This is my manifest.json:

{
  "name": "customer",
  "enableInstallPrompt": "true"
}

but I also have install prompt with “Standard” label

I don’t have much concrete help I can give, but it sounds like the underlying need is “How can I change the text in the install prompt, so that different users see a different text?”. The PWA annotation is just a way of specifying the text, and as annotations generally tend to be, it’s not very flexible during runtime.

I found the solution, reading the error and warning message in Chrome dev tools.

A correct configuration of manifest.json:

{
  "name": "customer",
  "short_name": "customer",
  "description": "customer",
  "display": "standalone",
  "start_url": "",
  "icons": [{
      "src": "icons/48x48/iconSpecial.png",
      "sizes": "48x48",
      "type": "image/png"
     }, {
      "src": "icons/144x144/iconSpecial.png",
      "sizes": "144x144",
      "type": "image/png"
  }]
}

I suggest to modifiy the documentation with some additional information