From f6e6b76249653428e3bac07c808908ec6e453dd9 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Fri, 3 May 2013 23:53:46 +0200 Subject: [PATCH] made force-https an option in mobile settings. removed plugin from build --- build.py | 17 +------ mobile/.gitignore | 2 +- mobile/res/values/strings.xml | 2 + mobile/res/xml/preferences.xml | 5 ++ .../com/cradle/iitc_mobile/IITC_Mobile.java | 4 +- .../com/cradle/iitc_mobile/IITC_Settings.java | 48 +++++++++---------- .../com/cradle/iitc_mobile/IITC_WebView.java | 18 ++++++- .../iitc_mobile/IITC_WebViewClient.java | 35 +++++++------- 8 files changed, 67 insertions(+), 64 deletions(-) diff --git a/build.py b/build.py index 270acab0..a81bfe34 100755 --- a/build.py +++ b/build.py @@ -196,15 +196,6 @@ for fn in glob.glob("plugins/*.user.js"): metafn = fn.replace('.user.js', '.meta.js') saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn)) -def copytree(src, dst, symlinks=False, ignore=None): - for item in os.listdir(src): - s = os.path.join(src, item) - d = os.path.join(dst, item) - if os.path.isdir(s): - shutil.copytree(s, d, symlinks, ignore) - else: - shutil.copy2(s, d) - # if we're building mobile too if buildMobile: if buildMobile not in ['debug','release','copyonly']: @@ -228,13 +219,9 @@ if buildMobile: shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js") # copy the user location script into the mobile folder. shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js") - # also copy plugins - try: - os.makedirs("mobile/assets/plugins") - except: - pass - copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins") + shutil.rmtree("mobile/assets/plugins") + shutil.copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins", ignore=shutil.ignore_patterns('*.meta.js', 'force-https*')) if buildMobile != 'copyonly': diff --git a/mobile/.gitignore b/mobile/.gitignore index c104ea4e..42e4ba7c 100644 --- a/mobile/.gitignore +++ b/mobile/.gitignore @@ -6,6 +6,6 @@ gen/ libs/ proguard-project.txt local.properties -assets/iitc.js +assets/total-conversion-build.user.js assets/user-location.user.js assets/plugins/ diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index 26a51274..b4fc8de0 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -37,6 +37,8 @@ Nice for tablets, looks awful on smartphones Display user location Show users position on map + Force https + Disabling may improve performance Developer options Enable developer mode If enabled, all IITC sources will be loaded from external storage of the Android device. diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml index 432b0eab..c667e8f0 100644 --- a/mobile/res/xml/preferences.xml +++ b/mobile/res/xml/preferences.xml @@ -36,6 +36,11 @@ android:key="pref_plugins" android:title="@string/pref_plugins" android:dialogTitle="@string/pref_plugins_title"/> + asset_values = new ArrayList(); for (int i = 0; i < asset_array.length ; i++) { - if (asset_array[i].endsWith("user.js")) { - // find user plugin name for user readable entries - Scanner s = null; - String src = ""; - try { - s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); - } catch (IOException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); - } - if (s != null) src = s.hasNext() ? s.next() : ""; - String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript==")); - // remove new line comments and replace with space - // this way we get double spaces instead of newline + double slash - header = header.replace("\n//", " "); - // get a list of key-value...split on multiple spaces - String[] attributes = header.split(" +"); - String plugin_name = "not found"; - for (int j = 0; j < attributes.length; j++) { - // search for name and use the value - if (attributes[j].equals("@name")) plugin_name = attributes[j+1]; - } - asset_list.add(plugin_name); - // real value - asset_values.add(asset_array[i]); + // find user plugin name for user readable entries + Scanner s = null; + String src = ""; + try { + s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } + if (s != null) src = s.hasNext() ? s.next() : ""; + String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript==")); + // remove new line comments and replace with space + // this way we get double spaces instead of newline + double slash + header = header.replace("\n//", " "); + // get a list of key-value...split on multiple spaces + String[] attributes = header.split(" +"); + String plugin_name = "not found"; + for (int j = 0; j < attributes.length; j++) { + // search for name and use the value + if (attributes[j].equals("@name")) plugin_name = attributes[j+1]; + } + asset_list.add(plugin_name); + // real value + asset_values.add(asset_array[i]); } Bundle bundle = getIntent().getExtras(); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index 9da7655b..ba705db9 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -2,8 +2,10 @@ package com.cradle.iitc_mobile; import android.annotation.SuppressLint; import android.content.Context; +import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; import android.webkit.WebChromeClient; @@ -65,6 +67,20 @@ public class IITC_WebView extends WebView { } //---------------------------------------------------------------- + @Override + public void loadUrl(String url) { + if (!url.startsWith("javascript:")) { + // force https if enabled in settings + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); + if (sharedPref.getBoolean("pref_force_https", true)) + url = url.replace("http://", "https://"); + else + url = url.replace("https://", "http://"); + Log.d("iitcm", "loading url: " + url); + } + super.loadUrl(url); + } + public IITC_WebViewClient getWebViewClient() { return this.webclient; } @@ -79,7 +95,7 @@ public class IITC_WebView extends WebView { Log.d("iitcm", "not connected to wifi...load tiles from cache"); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } else { - Log.d("iitcm", "connected to wifi...load tiles network"); + Log.d("iitcm", "connected to wifi...load tiles from network"); settings.setCacheMode(WebSettings.LOAD_DEFAULT); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 60f428c5..4f86d261 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -135,27 +135,24 @@ public class IITC_WebViewClient extends WebViewClient { String[] plugin_array = plugin_list.toArray(new String[0]); for(int i = 0; i < plugin_list.size(); i++) { - if (plugin_array[i].endsWith("user.js")); - { - Log.d("iitcm", "adding plugin " + plugin_array[i]); - Scanner s = null; - String src = ""; - try { - // load plugins from external storage if dev mode are enabled - if (dev_enabled) { - File js_file = new File(dev_path + "plugins/" + plugin_array[i]); - s = new Scanner(js_file).useDelimiter("\\A"); - } - else - // load plugins from asset folder - s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); - } catch (IOException e2) { - // TODO Auto-generated catch block - e2.printStackTrace(); + Log.d("iitcm", "adding plugin " + plugin_array[i]); + Scanner s = null; + String src = ""; + try { + // load plugins from external storage if dev mode are enabled + if (dev_enabled) { + File js_file = new File(dev_path + "plugins/" + plugin_array[i]); + s = new Scanner(js_file).useDelimiter("\\A"); } - if (s != null) src = s.hasNext() ? s.next() : ""; - view.loadUrl("javascript:" + src); + else + // load plugins from asset folder + s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } + if (s != null) src = s.hasNext() ? s.next() : ""; + view.loadUrl("javascript:" + src); } }