Browse Source

fix `appUrlOpen` fired twice

llcc 3 years ago
parent
commit
ddef181f88
1 changed files with 11 additions and 3 deletions
  1. 11 3
      src/main/frontend/mobile/core.cljs

+ 11 - 3
src/main/frontend/mobile/core.cljs

@@ -10,6 +10,11 @@
             [frontend.util :as util]))
 
 (def *url (atom nil))
+;; FIXME: `appUrlOpen` are fired twice when receiving a same intent. 
+;; The following two variable atoms are used to compare whether
+;; they are from the same intent share.
+(def *last-shared-url (atom nil))
+(def *last-shared-seconds (atom 0))
 
 (defn- ios-init
   "Initialize iOS-specified event listeners"
@@ -62,12 +67,15 @@
   []
   (.addListener App "appUrlOpen"
                 (fn [^js data]
-                  (prn :data data)
                   (when-let [url (.-url data)]
                     (if-not (= (.-readyState js/document) "complete")
                       (reset! *url url)
-                      (deeplink/deeplink url)))))
-    
+                      (when-not (and (= @*last-shared-url url)
+                                     (<= (- (.getSeconds (js/Date.)) @*last-shared-seconds) 1))
+                        (reset! *last-shared-url url)
+                        (reset! *last-shared-seconds (.getSeconds (js/Date.)))
+                        (deeplink/deeplink url))))))
+
   (.addListener mobile-util/fs-watcher "watcher"
                 (fn [event]
                   (state/pub-event! [:file-watcher/changed event])))