diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 33e53cf8..24bd3f1b 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="24" + android:versionName="0.4.3"> /IITC-Mobile/plugins/ File directory = new File(iitc_path + "plugins/"); File[] files = directory.listFiles(); if (files != null) { for (int i = 0; i < files.length; ++i) { - if (this.loadJS(files[i].toString(), false, view)) + String add_js = ""; + if ((add_js = this.removePluginWrapper(files[i].toString(), false)) != "") { Log.d("iitcm", "loading additional plugin " + files[i].toString()); + js += add_js; + } } } + return js; } - public void enableTracking(WebView view, boolean dev_enabled) { + public String parseTrackingPlugin(boolean dev_enabled) { Log.d("iitcm", "enable tracking..."); + String js = ""; // load plugin from external storage if dev mode are enabled if (dev_enabled) - this.loadJS(iitc_path + "dev/user-location.user.js", false, view); + js = this.removePluginWrapper(iitc_path + "dev/user-location.user.js", false); else // load plugin from asset folder - this.loadJS("user-location.user.js", true, view); + js = this.removePluginWrapper("user-location.user.js", true); + return js; } // read a file into a string @@ -226,6 +228,7 @@ public class IITC_WebViewClient extends WebViewClient { // read a file into a string // load it as javascript + // at the moment not needed, but not bad to have it in the IITC_WebViewClient API public boolean loadJS(String file, boolean asset, WebView view) { if (!file.endsWith("user.js")) return false; @@ -237,6 +240,24 @@ public class IITC_WebViewClient extends WebViewClient { return true; } + // iitc and all plugins are loaded at the same time + // so remove the wrapper functions and injection code + // TODO: it only works if the plugin is coded with the iitc plugin template + public String removePluginWrapper(String file, boolean asset) { + if (!file.endsWith("user.js")) return ""; + String js = fileToString(file, asset); + if (js == "false") return ""; + // remove the wrapper function + js = js.replace("function wrapper() {", ""); + js = js.replace("} // wrapper end", ""); + // remove the injection (should be the last 4 lines)...will be done by the iitc script + js = js.substring(0,js.lastIndexOf('\n')); + js = js.substring(0,js.lastIndexOf('\n')); + js = js.substring(0,js.lastIndexOf('\n')); + js = js.substring(0,js.lastIndexOf('\n')); + js = js.substring(0,js.lastIndexOf('\n')); + return js; + } // Check every external resource if it’s okay to load it and maybe replace // it // with our own content. This is used to block loading Niantic resources