Skip to content

Instantly share code, notes, and snippets.

@ibaca
Created February 22, 2013 11:00
Show Gist options
  • Save ibaca/5012631 to your computer and use it in GitHub Desktop.
Save ibaca/5012631 to your computer and use it in GitHub Desktop.
GWT.isSuperDevMode()
package com.intendia.igestion.web.util.info;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.ScriptElement;
public class DefaultRuntimeInfo implements RuntimeInfo {
@Override
public boolean isProdMode() {
return GWT.isProdMode() && !isSuperDevMode();
}
@Override
public boolean isScript() {
return GWT.isScript();
}
@Override
public boolean isAssertionEnabled() {
return getClass().desiredAssertionStatus();
}
private boolean isSuperDevMode() {
Element head = Document.get().getElementsByTagName("head").getItem(0);
Element scriptNode = head.getFirstChildElement();
if (!ScriptElement.is(scriptNode)) {
return false; // Super dev mode is always the first script
}
ScriptElement scriptElement = ScriptElement.as(scriptNode);
String scriptSrc = scriptElement.getSrc();
if (scriptSrc != null && scriptSrc.startsWith("http://localhost:")) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment