Detecting Super Dev Mode from GWT Application

I think the title says it all:

Is there some flag that allows my GWT app to check if it is running in Super Dev mode (something like strings GWT.isProdMode()

maybe)?

+4


source to share


8 answers


There is an open question about the availability of a public access tool such as GWT.isProdMode()

.



At the same time, if you really need to know, there is a named lazy binding property superdevmode

that you can use in your rules <replace-with>

or <generate-with>

.

+4


source


As mentioned, there is a property superdevmode

you can use.

Here's a real-world example:

  1. Create a class containing a method that says we're not in SuperDevMode:

    public class SuperDevModeIndicator {
        public boolean isSuperDevMode() {
            return false;
        }
    }
    
          

  2. Extend the previous class and override the method to say we 're in SuperDevMode:

    public class SuperDevModeIndicatorTrue extends SuperDevModeIndicator {
        @Override
        public boolean isSuperDevMode() {
            return true;
        }
    }
    
          

  3. Use only one appropriate class depending on the property superdevmode

    - use lazy binding - put this in your *.gwt.xml

    :

    <!-- deferred binding for Super Dev Mode indicator -->
    <replace-with class="com.adam.project.client.SuperDevModeIndicatorTrue">
      <when-type-is class="com.adam.project.client.SuperDevModeIndicator"/>
      <when-property-is name="superdevmode" value="on" />
    </replace-with>
    
          

  4. SuperDevModeIndicator

    class SuperDevModeIndicator

    using lazy binding:

    SuperDevModeIndicator superDevModeIndicator = GWT.create(SuperDevModeIndicator.class);
    
          

  5. Use it to check if you are in SuperDevMode or not:

    superDevModeIndicator.isSuperDevMode();
    
          



Voila!

You will find documentation on deferred binding here .

+6


source


There might be an "official" way, but this should work:

Storage stockStore = Storage.getSessionStorageIfSupported();
if (stockStore != null)
{
    boolean isSuperDevMode = stockStore.getItem("__gwtDevModeHook:" + GWT.getModuleName()) != null);
}

      

+2


source


You can use the GWTHelper.isSuperDevMode () method implemented below.

public final class GWTHelper {

    public static boolean isSuperDevMode() {
        final Storage storage = Storage.getSessionStorageIfSupported();
        if (storage == null) {
            return false;
        }
        final String devModeKey = "__gwtDevModeHook:" + GWT.getModuleName();
        return storage.getItem(devModeKey) != null;
    }

}

      

Source: https://gwt.googlesource.com/gwt/+/master/dev/core/src/com/google/gwt/core/linker/DevModeRedirectHook.js

0


source


To check if there is a dev app server: GWT.getHostPageBaseURL () returns http://127.0.0.1:8888/

Server side: request.getRemoteHost () should return the same (although I haven't tested this).

To check Super Dev mode (vs dev app server without SDM): If GWT.getModuleBaseURL () and GWT.getModuleBaseForStaticFiles () are different, you are in Super Dev mode.

property name = "superdevmode" solution didn't work for me.

0


source


I used the following method:

private static native boolean isSuperDevMode()/*-{ return typeof $wnd.__gwt_sdm !== 'undefined'; }-*/;

Works in GWT 2.7.0.

0


source


My decision:

GWT.getModuleBaseForStaticFiles().contains("9876")

      

0


source


May I suggest:

public boolean isSuperDevMode()
{
    return Window.Location.getPort().equals("8888");
}

      

-1


source







All Articles