1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 13:22:08 +01:00

Check, whether proxy settings are satisfied before trying to connect vie WebView

This commit is contained in:
vanitasvitae 2016-06-06 18:29:52 +02:00
parent da80c11b66
commit bb0bf6d93b
2 changed files with 29 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import android.widget.Toast;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.OrbotStatusReceiver;
import java.io.File;
@ -156,14 +157,27 @@ public class ContextMenuWebView extends NestedWebView {
@Override
public void reload() {
OrbotHelper.requestStartTor(context.getApplicationContext());
AppSettings settings = new AppSettings(context);
if(settings.isProxyOrbot()) {
if(OrbotStatusReceiver.isInCorrectState(settings.isLoadImages())) {
super.reload();
} else {
OrbotHelper.requestStartTor(context.getApplicationContext());
}
}
super.reload();
}
@Override
public void loadUrl(String url) {
if(!OrbotStatusReceiver.isProxySet())
OrbotHelper.requestStartTor(context.getApplicationContext());
AppSettings settings = new AppSettings(context);
if(settings.isProxyOrbot()) {
if(OrbotStatusReceiver.isInCorrectState(settings.isLoadImages())) {
super.loadUrl(url);
} else {
OrbotHelper.requestStartTor(context.getApplicationContext());
}
}
super.loadUrl(url);
}
}

View file

@ -147,4 +147,16 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
return proxySet;
}
/**
* Return true if actual state represents desired state
* @param orbotProxyActive desired state; true if app should proxy through tor, false if no proxy used
* @return boolean
*/
public static boolean isInCorrectState(boolean orbotProxyActive) {
if(orbotProxyActive) {
return host != null && !host.equals("") && port > 0 && proxySet;
} else {
return (host.equals("") || host == null) && port < 1 && !proxySet;
}
}
}