From ef4f212fc1482136dba1e690ec589b315b4a377f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 8 Nov 2016 12:37:03 -0500 Subject: build 0.7.0 --- .../LaunchMyApp-PhoneGap-Plugin.iws | 1242 -------------------- .../cordova-plugin-customurlscheme/README.md | 41 +- .../atlassian-ide-plugin.xml | 5 - .../cordova-plugin-customurlscheme/package.json | 4 +- .../cordova-plugin-customurlscheme/plugin.xml | 52 +- .../android/nl/xservices/plugins/LaunchMyApp.java | 49 +- .../src/windows/hooks/prepare-manifest.js | 30 + .../src/wp8/CompositeUriMapper.cs | 46 + .../src/wp8/CustomUriMapperCommand.cs | 9 + .../src/wp8/ICustomUriMapper.cs | 7 + .../src/wp8/hooks/add-uri-mapper.js | 80 ++ .../www/android/LaunchMyApp.js | 26 +- .../www/wp8/LaunchMyApp.js | 12 + 13 files changed, 339 insertions(+), 1264 deletions(-) delete mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/LaunchMyApp-PhoneGap-Plugin.iws delete mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/atlassian-ide-plugin.xml create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/src/windows/hooks/prepare-manifest.js create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CompositeUriMapper.cs create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CustomUriMapperCommand.cs create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/ICustomUriMapper.cs create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/hooks/add-uri-mapper.js create mode 100644 StoneIsland/plugins/cordova-plugin-customurlscheme/www/wp8/LaunchMyApp.js (limited to 'StoneIsland/plugins/cordova-plugin-customurlscheme') diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/LaunchMyApp-PhoneGap-Plugin.iws b/StoneIsland/plugins/cordova-plugin-customurlscheme/LaunchMyApp-PhoneGap-Plugin.iws deleted file mode 100644 index 9879f7f4..00000000 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/LaunchMyApp-PhoneGap-Plugin.iws +++ /dev/null @@ -1,1242 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - 5050 - - - - - - - - - - 1380298653954 - - - 1380299229689 - - - 1380302935690 - - - 1380305538088 - - - 1380305862564 - - - 1380306489891 - - - 1380307532008 - - - 1380307669209 - - - 1380311306948 - - - 1380311921427 - - - 1380317008739 - - - 1380317829887 - - - 1380353871771 - - - 1380358237732 - - - 1380358605885 - - - 1380376149014 - - - 1380378153190 - - - 1380383948466 - - - 1380393159906 - - - 1380393508799 - - - 1380393757355 - - - 1380393772924 - - - 1380402190419 - - - 1380402398063 - - - 1380402815702 - - - 1380488689110 - - - 1380488797067 - - - 1380488875151 - - - 1380489049263 - - - 1380489820453 - - - 1380567506465 - - - 1380567576964 - - - 1380567665822 - - - 1383169425770 - - - 1383172326587 - - - 1383174045796 - - - 1390857761557 - - - 1390857936690 - - - 1391028041914 - - - 1402048017666 - - - 1417632494865 - - - 1417703047123 - - - 1417706007258 - - - 1434477311221 - - - 1434530307503 - - - 1434577022103 - - - 1435161053225 - - - 1440664137793 - - - 1440664585797 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/README.md b/StoneIsland/plugins/cordova-plugin-customurlscheme/README.md index 2de829c2..d7222e90 100644 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/README.md +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/README.md @@ -1,6 +1,6 @@ # Custom URL scheme PhoneGap Plugin #### launch your app by a link like this: `mycoolapp://` -for iOS and Android, by [Eddy Verbruggen](http://www.x-services.nl) +for iOS, Android and WP, by [Eddy Verbruggen](http://www.x-services.nl) - This repo is for PhoneGap 3.0.0 and up - For PhoneGap 2.9.0 and lower, [switch to the phonegap-2.9.0-and-lower branch](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin/tree/phonegap-2.9.0-and-lower) @@ -10,11 +10,15 @@ for iOS and Android, by [Eddy Verbruggen](http://www.x-services.nl) 2. [Manually](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#manually) 2. [PhoneGap Build](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#phonegap-build) 3. [Usage](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#3-usage) + 2. [iOS](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#ios-usage) + 2. [Meteor](https://github.com/EddyVerbruggen/Custom-URL-scheme#meteor--getlastintent-android-only) 4. [URL Scheme hints](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#4-url-scheme-hints) 5. [License](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#5-license) -### BEWARE: [This Apache Cordova issue](https://issues.apache.org/jira/browse/CB-7606) causes problems with Cordova-iOS 3.7.0: the `handleOpenURL` function is not invoked upon cold start. Use a higher or lower version than 3.7.0. +### BEWARE: +### - [This Apache Cordova issue](https://issues.apache.org/jira/browse/CB-7606) causes problems with Cordova-iOS 3.7.0: the `handleOpenURL` function is not invoked upon cold start. Use a higher or lower version than 3.7.0. +### - As of iOS 9.2, the dialog `Open in "mycoolapp"?` no longer blocks JS, so if you have a short timeout that opens the app store, the user will be taken to the store before they have a chance to see and answer the dialog. [See below](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin#ios-usage) for available solutions. ## 1. Description @@ -32,6 +36,8 @@ This plugin allows you to start your app by calling it with a URL like `mycoolap ### Android specifics * Unlike iOS, there is no way to use config.xml to define a scheme for your app. Now there is. * Tested on Android 4.3, will most likely work with 2.2 and up. +* If you're trying to launch your app from an In-App Browser it opened previously, then [use this In-App Browser plugin fork](https://github.com/Innovation-District/cordova-plugin-inappbrowser) which allows that. +* In case you have a multi-page app (multiple HTML files, and all implementing handleOpenURL), set the preference `CustomURLSchemePluginClearsAndroidIntent` to `true` in `config.xml` so the function won't be triggered multiple times. Note that this may interfere with other plugins requiring the intent data. ## 2. Installation @@ -168,6 +174,37 @@ function handleOpenURL(url) { A more useful implementation would mean parsing the URL, saving any params to sessionStorage and redirecting the app to the correct page inside your app. All this happens before the first page is loaded. +### iOS Usage +A common method of deeplinking is to give the user the URL of a webpage (for instance http://linker.myapp.com/pathfoo) that opens the app if installed or the app store if not. This can be done in the following ways, depending on the desired UX: + +1. The page content has a button that says "Install app" and when clicked opens the app store by doing `location.href = 'itms-apps://itunes.apple.com/us/app/mycoolapp/idfoo'`. On page load, do `location.href = 'mycoolapp://pathfoo'`. If the user has the app, they will see a dialog that says `Open in "mycoolapp"? [Cancel] [Open]`. If the user does not have the app, they will see an alert that says `Cannot Open Page: Safari cannot open the page because the address is invalid`. Once they dismiss the alert, they see the button that opens the app store, and they tap it. +2. The page has two buttons: one that opens the app, and one that opens the app store. +3. On page load, open a Universal Link using [cordova-universal-links-plugin](https://github.com/nordnet/cordova-universal-links-plugin). (A Universal Link either opens the app or the app store.) Then fall back to one of the above methods if Univeral Links is not supported. + +You can also use a service that provides pages that do #3 for you, such as [Branch](https://branch.io/). + +### CSP - or: `handleOpenURL` doesn't work +The Whitelist plugin will prevent inline JS from executing, unless you whitelist the url scheme. Please see [this SO issue](http://stackoverflow.com/questions/34257097/using-handleopenurl-with-custom-url-scheme-in-cordova/34281420#34281420) for details. + +### Meteor / getLastIntent (Android only) +When running a [meteor](meteor.com) app in the cordova environment, `handleOpenURL` doesn't get called after a cold start, because cordova resets the javascript world during startup and our timer waiting for `handleOpenURL` gets vanished (see [#98](https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/98)). To get the intent by which the app was started in a meteor cordova app you need to ask for it from the meteor side with `getLastIntent` like this. +```javascript +Meteor.startup(function() { + if (Meteor.isCordova) { + window.plugins.launchmyapp.getLastIntent(function(url) { + if (intent.indexOf('mycoolapp://' > -1)) { + console.log("received url: " + url); + } else { + return console.log("ignore intent: " + url); + } + }, function(error) { + return console.log("no intent received"); + }); + return; + } +}); +``` + ## 4. URL Scheme hints Please choose a URL_SCHEME which which complies to these restrictions: - Don't use an already registered scheme (like `fb`, `twitter`, `comgooglemaps`, etc). diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/atlassian-ide-plugin.xml b/StoneIsland/plugins/cordova-plugin-customurlscheme/atlassian-ide-plugin.xml deleted file mode 100644 index 858eed55..00000000 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/atlassian-ide-plugin.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/package.json b/StoneIsland/plugins/cordova-plugin-customurlscheme/package.json index de90c8e2..3d0a4eaf 100644 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/package.json +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-customurlscheme", - "version": "4.0.0", + "version": "4.2.0", "description": "Launch your app by using this URL: mycoolapp://, you can add a path and even pass params like this: mycoolerapp://somepath?foo=bar", "cordova": { "id": "cordova-plugin-customurlscheme", @@ -40,4 +40,4 @@ "url": "https://github.com/EddyVerbruggen/Custom-URL-scheme/issues" }, "homepage": "https://github.com/EddyVerbruggen/Custom-URL-scheme#readme" -} \ No newline at end of file +} diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/plugin.xml b/StoneIsland/plugins/cordova-plugin-customurlscheme/plugin.xml index 1e43e724..0fde67b0 100755 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/plugin.xml +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/plugin.xml @@ -2,7 +2,7 @@ + version="4.2.0"> Custom URL scheme @@ -47,6 +47,10 @@ + + + + @@ -59,16 +63,24 @@ - + + + + + + + - + @@ -76,14 +88,20 @@ - + - + + + + + + + @@ -104,4 +122,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java index 9d3f3d63..3a52d287 100644 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/android/nl/xservices/plugins/LaunchMyApp.java @@ -4,6 +4,8 @@ import android.content.Intent; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaActivity; import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CordovaInterface; +import org.apache.cordova.CordovaWebView; import org.apache.cordova.PluginResult; import org.json.JSONArray; import org.json.JSONException; @@ -16,19 +18,52 @@ import java.util.Locale; public class LaunchMyApp extends CordovaPlugin { private static final String ACTION_CHECKINTENT = "checkIntent"; + private static final String ACTION_CLEARINTENT = "clearIntent"; + private static final String ACTION_GETLASTINTENT = "getLastIntent"; + + private String lastIntentString = null; + + /** + * We don't want to interfere with other plugins requiring the intent data, + * but in case of a multi-page app your app may receive the same intent data + * multiple times, that's why you'll get an option to reset it (null it). + * + * Add this to config.xml to enable that behaviour (default false): + * + */ + private boolean resetIntent; + + @Override + public void initialize(final CordovaInterface cordova, CordovaWebView webView){ + this.resetIntent = preferences.getBoolean("resetIntent", false) || + preferences.getBoolean("CustomURLSchemePluginClearsAndroidIntent", false); + } @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - if (ACTION_CHECKINTENT.equalsIgnoreCase(action)) { + if (ACTION_CLEARINTENT.equalsIgnoreCase(action)) { + final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); + if (resetIntent){ + intent.setData(null); + } + return true; + } else if (ACTION_CHECKINTENT.equalsIgnoreCase(action)) { final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent(); final String intentString = intent.getDataString(); - if (intentString != null && intentString.contains("://") && intent.getScheme() != null) { + if (intentString != null && intent.getScheme() != null) { + lastIntentString = intentString; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, intent.getDataString())); - intent.setData(null); } else { callbackContext.error("App was not started via the launchmyapp URL scheme. Ignoring this errorcallback is the best approach."); } return true; + } else if (ACTION_GETLASTINTENT.equalsIgnoreCase(action)) { + if(lastIntentString != null) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, lastIntentString)); + } else { + callbackContext.error("No intent received so far."); + } + return true; } else { callbackContext.error("This plugin only responds to the " + ACTION_CHECKINTENT + " action."); return false; @@ -38,8 +73,10 @@ public class LaunchMyApp extends CordovaPlugin { @Override public void onNewIntent(Intent intent) { final String intentString = intent.getDataString(); - if (intentString != null && intentString.contains("://") && intent.getScheme() != null) { - intent.setData(null); + if (intentString != null && intent.getScheme() != null) { + if (resetIntent){ + intent.setData(null); + } try { StringWriter writer = new StringWriter(intentString.length() * 2); escapeJavaStyleString(writer, intentString, true, false); @@ -133,4 +170,4 @@ public class LaunchMyApp extends CordovaPlugin { private static String hex(char ch) { return Integer.toHexString(ch).toUpperCase(Locale.ENGLISH); } -} \ No newline at end of file +} diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/windows/hooks/prepare-manifest.js b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/windows/hooks/prepare-manifest.js new file mode 100644 index 00000000..06e237f7 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/windows/hooks/prepare-manifest.js @@ -0,0 +1,30 @@ +module.exports = function(context) { + var fs = context.requireCordovaModule('fs'), + et = context.requireCordovaModule('elementtree'), + path = context.requireCordovaModule('path'), + xml= context.requireCordovaModule('cordova-common').xmlHelpers, + projectRoot = path.join(context.opts.projectRoot, "platforms", "windows"); + + var MANIFEST_WINDOWS = 'package.windows.appxmanifest', + MANIFEST_PHONE = 'package.phone.appxmanifest', + MANIFEST_WINDOWS10 = 'package.windows10.appxmanifest', + MANIFEST_WINDOWS80 = 'package.windows80.appxmanifest'; + + function updateManifestFile(manifestPath) { + var doc = xml.parseElementtreeSync(manifestPath); + var root = doc.getroot(); + var app = root.find('./Applications/Application'); + if (!app) { + throw new Error(manifestPath + ' has incorrect XML structure.'); + } + if (!app.find('./Extensions')) { + app.append(new et.Element('Extensions')); + } + fs.writeFileSync(manifestPath, doc.write({indent: 4}), 'utf-8'); + } + + [MANIFEST_PHONE, MANIFEST_WINDOWS80, MANIFEST_WINDOWS, MANIFEST_WINDOWS10] + .forEach(function(manifestFile) { + updateManifestFile(path.join(projectRoot, manifestFile)); + }); +} diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CompositeUriMapper.cs b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CompositeUriMapper.cs new file mode 100644 index 00000000..8db593b8 --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CompositeUriMapper.cs @@ -0,0 +1,46 @@ +using System; +using System.Linq; +using System.Windows.Navigation; + +internal class CompositeUriMapper : UriMapperBase +{ + public static string launchUrl; + + public override Uri MapUri(Uri uri) + { + string launchUri = uri.ToString(); + if (launchUri.StartsWith("/Protocol?encodedLaunchUri=")) + { + int launchUrlIndex = launchUri.IndexOf("encodedLaunchUri="); + launchUrl = System.Net.HttpUtility.UrlDecode(launchUri.Substring(launchUrlIndex+17)); + return new Uri("/MainPage.xaml", UriKind.Relative); + } + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + var types = assemblies.SelectMany(a => + { + try + { + return a.ExportedTypes.Where(et => typeof(ICustomUriMapper).IsAssignableFrom(et)); + } + catch + { + return Enumerable.Empty(); + } + }); + + foreach (var type in types) + { + if (type != typeof(ICustomUriMapper)) + { + var worker = (ICustomUriMapper)Activator.CreateInstance(type); + var mappedUri = worker.CustomMapUri(uri); + if (mappedUri != null) + { + return mappedUri; + } + } + } + + return uri; + } +} \ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CustomUriMapperCommand.cs b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CustomUriMapperCommand.cs new file mode 100644 index 00000000..2004f2ec --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/CustomUriMapperCommand.cs @@ -0,0 +1,9 @@ +using System; +using WPCordovaClassLib.Cordova.Commands; + +namespace Cordova.Extension.Commands +{ + public class CustomUriMapperCommand : BaseCommand + { + } +} \ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/ICustomUriMapper.cs b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/ICustomUriMapper.cs new file mode 100644 index 00000000..2cc31e5c --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/ICustomUriMapper.cs @@ -0,0 +1,7 @@ +using System; +using System.Linq; + +public interface ICustomUriMapper +{ + Uri CustomMapUri(Uri uri); +} diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/hooks/add-uri-mapper.js b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/hooks/add-uri-mapper.js new file mode 100644 index 00000000..1c1db69c --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/src/wp8/hooks/add-uri-mapper.js @@ -0,0 +1,80 @@ +module.exports = function (context) { + var deferred = context.requireCordovaModule('q').defer(), + fs = context.requireCordovaModule('fs'), + path = context.requireCordovaModule('path'), + projectRoot = context.opts.projectRoot; + + // While on AppBuilder this may work, the Cordova CLI doesn't like it + // (or at least not all versions of it). + var appXaml = path.join(projectRoot, "App.xaml.cs"); + var mainPageXaml = path.join(projectRoot, "MainPage.xaml.cs"); + try { + fs.statSync(appXaml); + fs.statSync(mainPageXaml); + } catch (err) { + appXaml = path.join(projectRoot, "platforms", "wp8", "App.xaml.cs"); + mainPageXaml = path.join(projectRoot, "platforms", "wp8", "MainPage.xaml.cs"); + try { + fs.statSync(appXaml); + fs.statSync(mainPageXaml); + } catch (err2) { + console.error("Custom URL Scheme plugin couldn't find your App's xaml file! Try to adjust the file manually according to the 'add-uri-mapper.js' hook."); + return; + } + } + + fs.readFile(appXaml, 'utf8', function (err,data) { + if (err) { + console.error("Error while configuring the Custom URL Scheme: " + err); + deferred.reject(err); + return; + } + + var result = data.replace(/^(\s*?)(RootFrame.NavigationFailed\s*?\+=\s*?RootFrame_NavigationFailed;)/gm, + "$1$2\n\n$1// Assign the URI-mapper class to the application frame\n$1RootFrame.UriMapper = new CompositeUriMapper();"); + + fs.writeFile(appXaml, result, 'utf8', function (err) { + if (err){ + deferred.reject(err); + } else{ + deferred.resolve(); + } + }); + }); + + fs.readFile(mainPageXaml, 'utf8', function (err,data) { + if (err) { + console.error("Error while configuring the Custom URL Scheme: " + err); + deferred.reject(err); + return; + } + + // first add a line to refer to a new method + var result = data.replace(/^(\s*?)(this.CordovaView.Loaded\s*?\+=\s*?CordovaView_Loaded;)/gm, + "$1$2\n\n$1// Wire a handler so we can check for our custom scheme\n$1this.CordovaView.Browser.LoadCompleted += CordovaBrowser_LoadCompleted;"); + + // now add that new method + result = result.replace(/^(\s*?)(\/\/ Constructor)/gm, + "$1void CordovaBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) {\n"+ + "$1\tif (CompositeUriMapper.launchUrl != null) {\n" + + "$1\t\tstring handleOpenURL = string.Format(\"(function() {{ document.addEventListener('deviceready', function() {{ if (typeof handleOpenURL === 'function') {{ handleOpenURL(\\\"{0}\\\"); }} }}); }})()\", CompositeUriMapper.launchUrl);\n" + + "$1\t\ttry {\n" + + "$1\t\t\tthis.CordovaView.CordovaBrowser.InvokeScript(\"eval\", new string[] { handleOpenURL });\n" + + "$1\t\t} catch (Exception) {}\n" + + "$1\t\tCompositeUriMapper.launchUrl = null;\n" + + "$1\t}\n" + + "$1\tthis.CordovaView.Browser.LoadCompleted -= CordovaBrowser_LoadCompleted;\n" + + "$1}\n\n" + + "$1$2"); + + fs.writeFile(mainPageXaml, result, 'utf8', function (err) { + if (err){ + deferred.reject(err); + } else{ + deferred.resolve(); + } + }); + }); + + return deferred.promise; +} \ No newline at end of file diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/www/android/LaunchMyApp.js b/StoneIsland/plugins/cordova-plugin-customurlscheme/www/android/LaunchMyApp.js index 19dbdc0b..18fe0112 100644 --- a/StoneIsland/plugins/cordova-plugin-customurlscheme/www/android/LaunchMyApp.js +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/www/android/LaunchMyApp.js @@ -4,10 +4,18 @@ var remainingAttempts = 10; function waitForAndCallHandlerFunction(url) { - if (typeof window.handleOpenURL == "function") { + if (typeof window.handleOpenURL === "function") { + // Clear the intent when we have a handler (note that this is only done when the preference 'CustomURLSchemePluginClearsAndroidIntent' is 'true' in config.xml + cordova.exec( + null, + null, + "LaunchMyApp", + "clearIntent", + []); + window.handleOpenURL(url); } else if (remainingAttempts-- > 0) { - setTimeout(function(){waitForAndCallHandlerFunction(url)}, 500); + setTimeout(function(){waitForAndCallHandlerFunction(url);}, 500); } } @@ -21,4 +29,18 @@ } document.addEventListener("deviceready", triggerOpenURL, false); + + var launchmyapp = { + getLastIntent: function(success, failure) { + cordova.exec( + success, + failure, + "LaunchMyApp", + "getLastIntent", + []); + } + } + + module.exports = launchmyapp; + }()); diff --git a/StoneIsland/plugins/cordova-plugin-customurlscheme/www/wp8/LaunchMyApp.js b/StoneIsland/plugins/cordova-plugin-customurlscheme/www/wp8/LaunchMyApp.js new file mode 100644 index 00000000..a8172f0f --- /dev/null +++ b/StoneIsland/plugins/cordova-plugin-customurlscheme/www/wp8/LaunchMyApp.js @@ -0,0 +1,12 @@ +(function () { + function activatedHandlerWinUI(e) { + if (typeof handleOpenURL == 'function' && e.uri) { + handleOpenURL(e.uri.rawUri); + } + }; + + if (typeof Windows != 'undefined') { + var wui = Windows.UI.WebUI.WebUIApplication; + wui.addEventListener("activated", activatedHandlerWinUI, false); + } +}()); \ No newline at end of file -- cgit v1.2.3-70-g09d2