|
@@ -9,69 +9,85 @@
|
|
|
[frontend.state :as state]
|
|
|
[frontend.util :as util]))
|
|
|
|
|
|
+(def *url (atom nil))
|
|
|
+
|
|
|
(defn- ios-init
|
|
|
+ "Initialize iOS-specified event listeners"
|
|
|
[]
|
|
|
(let [path (fs/iOS-ensure-documents!)]
|
|
|
(println "iOS container path: " path))
|
|
|
|
|
|
- ;; Keyboard watcher
|
|
|
- ;; (.addListener Keyboard "keyboardWillShow"
|
|
|
- ;; #(state/pub-event! [:mobile/keyboard-will-show]))
|
|
|
- ;; (.addListener Keyboard "keyboardDidShow"
|
|
|
- ;; #(state/pub-event! [:mobile/keyboard-did-show]))
|
|
|
- )
|
|
|
+ (.addEventListener js/window
|
|
|
+ "load"
|
|
|
+ (fn [_event]
|
|
|
+ (when @*url
|
|
|
+ (js/setTimeout #(deeplink/deeplink @*url)
|
|
|
+ 1000))))
|
|
|
+
|
|
|
+ (.removeAllListeners mobile-util/file-sync)
|
|
|
+
|
|
|
+ (.addListener mobile-util/file-sync "debug"
|
|
|
+ (fn [event]
|
|
|
+ (js/console.log "🔄" event))))
|
|
|
|
|
|
-(defn init!
|
|
|
+(defn- android-init
|
|
|
+ "Initialize Android-specified event listeners"
|
|
|
[]
|
|
|
;; patch back navigation
|
|
|
- (when (mobile-util/native-android?)
|
|
|
- (.addListener App "backButton"
|
|
|
- #(let [href js/window.location.href]
|
|
|
- (when (true? (cond
|
|
|
- (state/get-left-sidebar-open?)
|
|
|
- (state/set-left-sidebar-open! false)
|
|
|
+ (.addListener App "backButton"
|
|
|
+ #(let [href js/window.location.href]
|
|
|
+ (when (true? (cond
|
|
|
+ (state/get-left-sidebar-open?)
|
|
|
+ (state/set-left-sidebar-open! false)
|
|
|
|
|
|
- (state/settings-open?)
|
|
|
- (state/close-settings!)
|
|
|
+ (state/settings-open?)
|
|
|
+ (state/close-settings!)
|
|
|
|
|
|
- (state/modal-opened?)
|
|
|
- (state/close-modal!)
|
|
|
+ (state/modal-opened?)
|
|
|
+ (state/close-modal!)
|
|
|
|
|
|
- :else true))
|
|
|
+ :else true))
|
|
|
|
|
|
- (if (or (string/ends-with? href "#/")
|
|
|
- (string/ends-with? href "/")
|
|
|
- (not (string/includes? href "#/")))
|
|
|
- (.exitApp App)
|
|
|
- (js/window.history.back))))))
|
|
|
+ (if (or (string/ends-with? href "#/")
|
|
|
+ (string/ends-with? href "/")
|
|
|
+ (not (string/includes? href "#/")))
|
|
|
+ (.exitApp App)
|
|
|
+ (js/window.history.back)))))
|
|
|
|
|
|
- (when (mobile-util/native-ios?)
|
|
|
- (ios-init)
|
|
|
- (.removeAllListeners mobile-util/file-sync)
|
|
|
+ (.addEventListener js/window "sendIntentReceived"
|
|
|
+ #(intent/handle-received)))
|
|
|
|
|
|
- (.addListener App "appUrlOpen"
|
|
|
- (fn [^js data]
|
|
|
- (when-let [url (.-url data)]
|
|
|
- (deeplink/deeplink url))))
|
|
|
+(defn- general-init
|
|
|
+ "Initialize event listeners used by both iOS and Android"
|
|
|
+ []
|
|
|
+ (.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)))))
|
|
|
+
|
|
|
+ (.addListener mobile-util/fs-watcher "watcher"
|
|
|
+ (fn [event]
|
|
|
+ (state/pub-event! [:file-watcher/changed event])))
|
|
|
|
|
|
- (.addListener mobile-util/file-sync "debug"
|
|
|
- (fn [event]
|
|
|
- (js/console.log "🔄" event))))
|
|
|
+ (.addEventListener js/window "statusTap"
|
|
|
+ #(util/scroll-to-top true))
|
|
|
+
|
|
|
+ (.addListener App "appStateChange"
|
|
|
+ (fn [^js state]
|
|
|
+ (when (state/get-current-repo)
|
|
|
+ (let [is-active? (.-isActive state)]
|
|
|
+ (when-not is-active?
|
|
|
+ (editor-handler/save-current-block!)))))))
|
|
|
+
|
|
|
+(defn init! []
|
|
|
+ (when (mobile-util/native-android?)
|
|
|
+ (android-init))
|
|
|
+
|
|
|
+ (when (mobile-util/native-ios?)
|
|
|
+ (ios-init))
|
|
|
|
|
|
(when (mobile-util/is-native-platform?)
|
|
|
- (.addListener mobile-util/fs-watcher "watcher"
|
|
|
- (fn [event]
|
|
|
- (state/pub-event! [:file-watcher/changed event])))
|
|
|
-
|
|
|
- (.addEventListener js/window "statusTap"
|
|
|
- #(util/scroll-to-top true))
|
|
|
-
|
|
|
- (.addListener App "appStateChange"
|
|
|
- (fn [^js state]
|
|
|
- (when (state/get-current-repo)
|
|
|
- (let [is-active? (.-isActive state)]
|
|
|
- (when is-active?
|
|
|
- (editor-handler/save-current-block!))))))
|
|
|
-
|
|
|
- (.addEventListener js/window "sendIntentReceived"
|
|
|
- #(intent/handle-received))))
|
|
|
+ (general-init)))
|