core.cljs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. (ns frontend.mobile.core
  2. (:require [frontend.mobile.util :as mobile-util]
  3. [frontend.state :as state]
  4. ["@capacitor/app" :refer [^js App]]
  5. ["@capacitor/keyboard" :refer [^js Keyboard]]
  6. [reitit.frontend.easy :as rfe]
  7. [clojure.string :as string]
  8. [frontend.handler.notification :as notification]
  9. [frontend.fs.capacitor-fs :as fs]))
  10. (defn init!
  11. []
  12. ;; patch back navigation
  13. (when (mobile-util/native-android?)
  14. (.addListener App "backButton"
  15. #(let [href js/window.location.href]
  16. (when (true? (cond
  17. (state/get-left-sidebar-open?)
  18. (state/set-left-sidebar-open! false)
  19. (state/settings-open?)
  20. (state/close-settings!)
  21. (state/modal-opened?)
  22. (state/close-modal!)
  23. :else true))
  24. (if (or (string/ends-with? href "#/")
  25. (string/ends-with? href "/")
  26. (not (string/includes? href "#/")))
  27. (.exitApp App)
  28. (js/window.history.back))))))
  29. (when (mobile-util/native-ios?)
  30. (let [path (fs/iOS-ensure-documents!)]
  31. (println "iOS container path: " path))
  32. ;; keyboard watcher
  33. (.addListener Keyboard "keyboardWillShow"
  34. #(when (state/get-left-sidebar-open?)
  35. (state/set-left-sidebar-open! false)))))