Markus A.
Markus A.

Reputation: 12742

Detecting Super Dev Mode from within GWT app

I guess the title says it all:

Is there some kind of flag that allows my GWT app to check whether it is currently running in Super Dev Mode (something along the lines of GWT.isProdMode(), maybe)?

Upvotes: 4

Views: 1980

Answers (9)

dac2009
dac2009

Reputation: 3561

This is a pretty good solution.

boolean superdevmode = "on".equals(System.getProperty("superdevmode"));

Upvotes: 1

Thomas Broyer
Thomas Broyer

Reputation: 64541

There's an open issue about having a public accessor like GWT.isProdMode().

In the mean time, if you really need to know, there's a deferred binding property named superdevmode that you can use in your <replace-with> or <generate-with> rules.

Upvotes: 5

Alexander Tarasov
Alexander Tarasov

Reputation: 1

My solution is:

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

Upvotes: 0

Adam
Adam

Reputation: 5589

As it was already mentioned, there is a superdevmode property that you can use.

Here is a real-life example:

  1. Create a class containing a method that tells that we are not in SuperDevMode:

    public class SuperDevModeIndicator {
        public boolean isSuperDevMode() {
            return false;
        }
    }
    
  2. Extend previous class and override a method to tell that we are in SuperDevMode:

    public class SuperDevModeIndicatorTrue extends SuperDevModeIndicator {
        @Override
        public boolean isSuperDevMode() {
            return true;
        }
    }
    
  3. Use only one, appropriate class depending on a superdevmode property - use deferred 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. Instantiate SuperDevModeIndicator class via deferred binding:

    SuperDevModeIndicator superDevModeIndicator = GWT.create(SuperDevModeIndicator.class);
    
  5. Use it to check whether you are in SuperDevMode or not:

    superDevModeIndicator.isSuperDevMode();
    

Voila!

Here you will find documentation on Deferred binding.

Upvotes: 7

Moronicus
Moronicus

Reputation: 44

May I suggest:

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

Upvotes: -1

MeTTeO
MeTTeO

Reputation: 2098

I used following method:

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

Works in GWT 2.7.0.

Upvotes: 0

timmacp
timmacp

Reputation: 193

To check for dev app server: GWT.getHostPageBaseURL() returns http://127.0.0.1:8888/

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

To check for Super Dev Mode (vs dev app server without SDM): If GWT.getModuleBaseURL() & GWT.getModuleBaseForStaticFiles() differ, you're in Super Dev Mode.

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

Upvotes: 0

St&#233;phane B.
St&#233;phane B.

Reputation: 3270

You could use 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

Upvotes: 0

JPelletier
JPelletier

Reputation: 2109

Maybe there is an "official" way, but this should work:

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

Upvotes: 2

Related Questions