diff --git a/src/status_im/browser/core.cljs b/src/status_im/browser/core.cljs index 3b9014fcd8..cc1a9f42fd 100644 --- a/src/status_im/browser/core.cljs +++ b/src/status_im/browser/core.cljs @@ -212,11 +212,6 @@ (utils.universal-links/handle-url cofx link) {:browser/show-browser-selection link})) -(fx/defn handle-universal-link - [cofx link] - (when (utils.universal-links/universal-link? link) - (utils.universal-links/handle-url cofx link))) - (fx/defn update-browser-on-nav-change [cofx url error?] (let [browser (get-current-browser (:db cofx)) @@ -228,7 +223,6 @@ (fx/merge cofx (update-browser-history browser resolved-url) (handle-pdf url) - (handle-universal-link url) (resolve-url {:error? error? :resolved-url (when resolved-ens url)})))))) (fx/defn update-browser-name @@ -239,24 +233,29 @@ (fx/defn navigation-state-changed [cofx event error?] - (let [{:strs [url loading title]} (js->clj event)] - (fx/merge cofx - (update-browser-option :loading? loading) - (update-browser-name title) - (update-browser-on-nav-change url error?)))) + (let [{:strs [url loading title]} (js->clj event) + deep-link? (utils.universal-links/deep-link? url)] + (if (utils.universal-links/universal-link? url) + (when-not (and deep-link? platform/ios?) ;; ios webview handles this + (utils.universal-links/handle-url cofx url)) + (fx/merge cofx + (update-browser-option :loading? loading) + (update-browser-name title) + (update-browser-on-nav-change url error?))))) (fx/defn open-url-in-current-browser "Opens a url in the current browser, which mean no new entry is added to the home page and history of the current browser is updated so that the user can navigate back to the origin url" - ;; TODO(yenda) is that desirable ? [cofx url] (let [browser (get-current-browser (:db cofx)) normalized-url (http/normalize-and-decode-url url)] - (fx/merge cofx - (update-browser-option :url-editing? false) - (update-browser-history browser normalized-url) - (resolve-url nil)))) + (if (utils.universal-links/universal-link? normalized-url) + (utils.universal-links/handle-url cofx normalized-url) + (fx/merge cofx + (update-browser-option :url-editing? false) + (update-browser-history browser normalized-url) + (resolve-url nil))))) (fx/defn open-url "Opens a url in the browser. If a host can be extracted from the url and @@ -268,12 +267,14 @@ browser {:browser-id (or host (random/id)) :history-index 0 :history [normalized-url]}] - (fx/merge cofx - {:db (assoc db :browser/options - {:browser-id (:browser-id browser)})} - (navigate-to-browser) - (update-browser browser) - (resolve-url nil)))) + (if (utils.universal-links/universal-link? normalized-url) + (utils.universal-links/handle-url cofx normalized-url) + (fx/merge cofx + {:db (assoc db :browser/options + {:browser-id (:browser-id browser)})} + (navigate-to-browser) + (update-browser browser) + (resolve-url nil))))) (fx/defn open-existing-browser "Opens an existing browser with it's history" diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 45f8fcd772..6739b5ad72 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -238,6 +238,8 @@ (def regx-bold #"\*[^*]+\*") (def regx-italic #"~[^~]+~") (def regx-backquote #"`[^`]+`") +(def regx-universal-link #"((^https?://get.status.im/)|(^status-im://))[\x00-\x7F]+$") +(def regx-deep-link #"(^status-im://)[\x00-\x7F]+$") (def ^:const lines-collapse-threshold 20) (def ^:const chars-collapse-threshold 600) diff --git a/src/status_im/utils/universal_links/core.cljs b/src/status_im/utils/universal_links/core.cljs index cb1d29448a..972d379bdc 100644 --- a/src/status_im/utils/universal_links/core.cljs +++ b/src/status_im/utils/universal_links/core.cljs @@ -14,7 +14,8 @@ [status-im.utils.config :as config] [status-im.utils.fx :as fx] [taoensso.timbre :as log] - [status-im.utils.platform :as platform])) + [status-im.utils.platform :as platform] + [status-im.constants :as constants])) ;; TODO(yenda) investigate why `handle-universal-link` event is ;; dispatched 7 times for the same link @@ -44,7 +45,11 @@ (defn universal-link? [url] (boolean - (re-matches #"((^https?://get.status.im/)|(^status-im://))[\x00-\x7F]+$" url))) + (re-matches constants/regx-universal-link url))) + +(defn deep-link? [url] + (boolean + (re-matches constants/regx-deep-link url))) (defn open! [url] (log/info "universal-links: opening " url) diff --git a/test/cljs/status_im/test/utils/universal_links/core.cljs b/test/cljs/status_im/test/utils/universal_links/core.cljs index d62c1f88c8..aecc616752 100644 --- a/test/cljs/status_im/test/utils/universal_links/core.cljs +++ b/test/cljs/status_im/test/utils/universal_links/core.cljs @@ -53,6 +53,9 @@ (testing "status-im://blah" (testing "it returns true" (is (links/universal-link? "status-im://blah")))) + (testing "status-im://blah" + (testing "it returns true" + (is (links/deep-link? "status-im://blah")))) (testing "http://get.status.im/blah" (testing "it returns true" (is (links/universal-link? "http://get.status.im/blah")))) @@ -70,7 +73,10 @@ (is (not (links/universal-link? "https://not.status.im/blah"))))) (testing "https://not.status.im/blah" (testing "it returns false" - (is (not (links/universal-link? "https://not.status.im/blah")))))) + (is (not (links/universal-link? "https://not.status.im/blah"))))) + (testing "http://get.status.im/blah" + (testing "it returns false" + (is (not (links/deep-link? "http://get.status.im/blah")))))) (deftest process-stored-event (testing "the url is in the database"