core.cljs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (ns frontend.core
  2. (:require [rum.core :as rum]
  3. [frontend.handler :as handler]
  4. [frontend.handler.plugin :as plugin-handler]
  5. [frontend.handler.route :as route]
  6. [frontend.page :as page]
  7. [frontend.routes :as routes]
  8. [frontend.spec]
  9. [frontend.log]
  10. [frontend.util.persist-var :as persist-var]
  11. [reitit.frontend :as rf]
  12. [reitit.frontend.easy :as rfe]
  13. [logseq.api]
  14. [frontend.fs.sync :as sync]))
  15. (defn set-router!
  16. []
  17. (rfe/start!
  18. (rf/router routes/routes nil)
  19. (fn [route]
  20. (route/set-route-match! route)
  21. (plugin-handler/hook-plugin-app
  22. :route-changed (select-keys route [:template :path :parameters])))
  23. ;; set to false to enable HistoryAPI
  24. {:use-fragment true}))
  25. (defn display-welcome-message
  26. []
  27. (js/console.log
  28. "
  29. Welcome to Logseq!
  30. If you encounter any problem, feel free to file an issue on GitHub (https://github.com/logseq/logseq)
  31. or join our forum (https://discuss.logseq.com).
  32. .____
  33. | | ____ ____ ______ ____ ______
  34. | | / _ \\ / ___\\/ ___// __ \\/ ____/
  35. | |__( <_> ) /_/ >___ \\\\ ___< <_| |
  36. |_______ \\____/\\___ /____ >\\___ >__ |
  37. \\/ /_____/ \\/ \\/ |__|
  38. "))
  39. (defn start []
  40. (when-let [node (.getElementById js/document "root")]
  41. (set-router!)
  42. (rum/mount (page/current-page) node)
  43. (display-welcome-message)
  44. (persist-var/load-vars)
  45. (js/setTimeout #(sync/sync-start) 1000)))
  46. (defn ^:export init []
  47. ;; init is called ONCE when the page loads
  48. ;; this is called in the index.html and must be exported
  49. ;; so it is available even in :advanced release builds
  50. (plugin-handler/setup!
  51. #(handler/start! start))
  52. ;; popup to notify user, could be toggled in settings
  53. ;; (handler/request-notifications-if-not-asked)
  54. ;; (handler/run-notify-worker!)
  55. )
  56. (defn stop []
  57. ;; stop is called before any code is reloaded
  58. ;; this is controlled by :before-load in the config
  59. (handler/stop!)
  60. (sync/<sync-stop)
  61. (js/console.log "stop"))