From 2800502fb83bf871e9d3eca5dddd1a7fc1055692 Mon Sep 17 00:00:00 2001 From: Josh Hollinshead Date: Thu, 18 Jan 2018 11:05:03 +1100 Subject: [PATCH 1/5] Add support of native app external link opening (in particular for IOS) using inappbrowser "_system" approach --- addon/href-to.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/addon/href-to.js b/addon/href-to.js index e4e309b..d2b39c0 100644 --- a/addon/href-to.js +++ b/addon/href-to.js @@ -1,4 +1,5 @@ import LinkComponent from '@ember/routing/link-component'; +import { isPresent } from "@ember/utils"; export default class { @@ -12,7 +13,12 @@ export default class { maybeHandle() { if (this.shouldHandle()) { - this.handle(); + return this.handle(); + } + + // Add extra check for native app behaviour + if (this.shouldHandleAsExternalNativeLink()) { + return this.handleAsExternalNativeLink(); } } @@ -26,12 +32,41 @@ export default class { this.recognizeUrl(); } + shouldHandleAsExternalNativeLink() { + return this.isUnmodifiedLeftClick() && + this.isNotIgnored() && + this.hasNoActionHelper() && + this.hasNoDownload() && + this.isNotLinkComponent() && + + // Additional checks + this.hasUrl() && + this.isNativeBuild() && // For native app builds only + !this.recognizeUrl(); // Confirm its not an internal link + } + + // Standard ember-href-to behavour handle() { let router = this._getRouter(); router.transitionTo(this.getUrlWithoutRoot()); this.event.preventDefault(); } + /* + * In order to open external links in the mobile devices system browser, we need to + * pass '_system' through to the open method. This method has been overwritten by the + * cordova inappbrowser plugin so external links can successfully "escape" the webview + * on IOS (Works on android as well, although not explicitly required). + */ + handleAsExternalNativeLink() { + window.open(this.url, '_system'); + this.event.preventDefault(); + } + + hasUrl() { + return isPresent(this.url); + } + isUnmodifiedLeftClick() { let e = this.event; @@ -83,6 +118,10 @@ export default class { return didRecognize; } + isNativeBuild() { + return this._getPlatformService().isNativeBuild; + } + getUrlWithoutRoot() { let url = this.url; let rootUrl = this._getRootUrl(); @@ -93,6 +132,10 @@ export default class { return this.applicationInstance.lookup('service:router'); } + _getPlatformService() { + return this.applicationInstance.lookup('service:platform'); + } + _getRootUrl() { let router = this._getRouter(); let rootURL = router.get('rootURL'); From 836a806f653a97e0a7115c01c02243cf492b6c84 Mon Sep 17 00:00:00 2001 From: Josh Hollinshead Date: Fri, 19 Jan 2018 09:49:43 +1100 Subject: [PATCH 2/5] Filter out any params that are passed through that are undefined or null --- addon/helpers/href-to.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addon/helpers/href-to.js b/addon/helpers/href-to.js index aa0d354..f66fa4a 100644 --- a/addon/helpers/href-to.js +++ b/addon/helpers/href-to.js @@ -1,5 +1,6 @@ import Helper from "@ember/component/helper"; import { getOwner } from "@ember/application"; +import { isPresent } from "@ember/utils"; export function hrefTo(context, params) { let routing = getOwner(context).lookup("service:-routing"); @@ -16,7 +17,10 @@ function getParamsForGenerateURL(params) { } else { queryParams = {}; } - let models = params; // the remainder are the models + + // Filter out any items that aren't present + let models = params.filter(item => isPresent(item)); // the remainder are the models + return [targetRouteName, models, queryParams]; } From 7a88b3bff86c9028b11b4c8de318445d53127f0d Mon Sep 17 00:00:00 2001 From: Josh Hollinshead Date: Fri, 19 Jan 2018 11:56:07 +1100 Subject: [PATCH 3/5] Handle native app link clicks --- addon/href-to.js | 5 +++++ index.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addon/href-to.js b/addon/href-to.js index d2b39c0..2de834b 100644 --- a/addon/href-to.js +++ b/addon/href-to.js @@ -140,6 +140,11 @@ export default class { let router = this._getRouter(); let rootURL = router.get('rootURL'); + // Add the hash to the front of the url if we are in native app build + if (this.isNativeBuild()) { + rootURL = '#' + rootURL; + } + if (rootURL.charAt(rootURL.length - 1) !== '/') { rootURL = rootURL + '/'; } diff --git a/index.js b/index.js index 2e1d1d8..a896e42 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,9 @@ 'use strict'; module.exports = { - name: require('./package').name + name: require('./package').name, + // Uncomment when developing locally. i.e. (yarn link ember-href-to) + // isDevelopingAddon() { + // return true; + // } }; From d05401fc85ddc2b1a2bac0c199347ba5692f0178 Mon Sep 17 00:00:00 2001 From: Josh Hollinshead Date: Fri, 19 Jan 2018 12:14:44 +1100 Subject: [PATCH 4/5] Only add hash when not in testing --- addon/href-to.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/href-to.js b/addon/href-to.js index 2de834b..53ac5e2 100644 --- a/addon/href-to.js +++ b/addon/href-to.js @@ -1,3 +1,4 @@ +import Ember from "ember"; import LinkComponent from '@ember/routing/link-component'; import { isPresent } from "@ember/utils"; @@ -140,8 +141,7 @@ export default class { let router = this._getRouter(); let rootURL = router.get('rootURL'); - // Add the hash to the front of the url if we are in native app build - if (this.isNativeBuild()) { + if (this.isNativeBuild() && !Ember.testing) { rootURL = '#' + rootURL; } From 19b5268b2998eed5145ecfafbadd94b9355d9d01 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Nov 2022 09:50:12 +0000 Subject: [PATCH 5/5] Bump socket.io-parser from 3.3.0 to 3.3.3 Bumps [socket.io-parser](https://github.com/socketio/socket.io-parser) from 3.3.0 to 3.3.3. - [Release notes](https://github.com/socketio/socket.io-parser/releases) - [Changelog](https://github.com/socketio/socket.io-parser/blob/main/CHANGELOG.md) - [Commits](https://github.com/socketio/socket.io-parser/compare/3.3.0...3.3.3) --- updated-dependencies: - dependency-name: socket.io-parser dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index fdd80b6..9850368 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2653,10 +2653,15 @@ component-bind@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" -component-emitter@1.2.1, component-emitter@^1.2.1: +component-emitter@1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" +component-emitter@^1.2.1, component-emitter@~1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" + integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg== + component-inherit@0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" @@ -5054,7 +5059,7 @@ isarray@1.0.0, isarray@~1.0.0: isarray@2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" - integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4= + integrity sha512-c2cu3UxbI+b6kR3fy0nRnAhodsvR9dx7U5+znCOzdj6IfP3upFURTr0Xl5BlQZNKZjEtxrmVyfSdeE3O57smoQ== isbinaryfile@^3.0.3: version "3.0.3" @@ -5926,6 +5931,7 @@ mout@^1.0.0: ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== ms@^2.1.1: version "2.1.1" @@ -7157,11 +7163,11 @@ socket.io-client@2.2.0: to-array "0.1.4" socket.io-parser@~3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" - integrity sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng== + version "3.3.3" + resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.3.tgz#3a8b84823eba87f3f7624e64a8aaab6d6318a72f" + integrity sha512-qOg87q1PMWWTeO01768Yh9ogn7chB9zkKtQnya41Y355S0UmpXgpcrFwAgjYJxu9BdKug5r5e9YtVSeWhKBUZg== dependencies: - component-emitter "1.2.1" + component-emitter "~1.3.0" debug "~3.1.0" isarray "2.0.1"