浏览代码

fix: reload app only on mobile

Tienson Qin 1 周之前
父节点
当前提交
814707054b

+ 5 - 5
src/main/frontend/components/block.cljs

@@ -2303,7 +2303,7 @@
   [:div.relative
    [:div.dnd-separator.absolute
     {:style {:left (cond-> (if (= move-to :nested) 48 20)
-                     (util/capacitor-new?)
+                     (util/capacitor?)
                      (- 20))
              :top 0
              :width "100%"
@@ -3002,7 +3002,7 @@
                                             journal-title?
                                             (do
                                               (.preventDefault e)
-                                              (when-not (util/capacitor-new?)
+                                              (when-not (util/capacitor?)
                                                 (route-handler/redirect-to-page! (:block/uuid block))))
 
                                             (ldb/journal? block)
@@ -3349,7 +3349,7 @@
                           (and top? (<= (js/Math.abs (- cursor-top element-top)) 16))
                           :top
 
-                          (> x-offset (if (util/capacitor-new?) 100 50))
+                          (> x-offset (if (util/capacitor?) 100 50))
                           :nested
 
                           :else
@@ -3392,7 +3392,7 @@
         ;; dnd block moving in current Logseq instance
         (do
           (dnd/move-blocks event blocks target-block original-block @*move-to')
-          (when (util/capacitor-new?)
+          (when (util/capacitor?)
             (state/set-state! :mobile/show-action-bar? false)
             (state/clear-selection!)))
         ;; handle DataTransfer
@@ -3675,7 +3675,7 @@
        :on-touch-cancel (fn [e]
                           (block-handler/on-touch-cancel e))}
 
-       (and (util/capacitor-new?) (not (ldb/page? block)))
+       (and (util/capacitor?) (not (ldb/page? block)))
        (assoc
         :draggable true
         :on-drag-start

+ 1 - 1
src/main/frontend/components/page.cljs

@@ -698,7 +698,7 @@
             (when (not tag-dialog?)
               [:div.ls-page-blocks
                {:style {:margin-left (if (or whiteboard? (util/mobile?)) 0 -20)}
-                :class (when-not (or sidebar? (util/capacitor-new?))
+                :class (when-not (or sidebar? (util/capacitor?))
                          "mt-4")}
                (page-blocks-cp page (merge option {:sidebar? sidebar?
                                                    :container-id (:container-id state)

+ 4 - 4
src/main/frontend/components/repo.cljs

@@ -84,7 +84,7 @@
                                      (state/pub-event! [:rtc/download-remote-graph GraphName GraphUUID GraphSchemaVersion])
 
                                      :else
-                                     (when-not (util/capacitor-new?)
+                                     (when-not (util/capacitor?)
                                        (state/pub-event! [:graph/pull-down-remote-graph repo]))))))]
       (when-let [time (some-> (or last-seen-at created-at) (safe-locale-date))]
         [:small.text-muted-foreground (str "Last opened at: " time)])]
@@ -207,7 +207,7 @@
                           (config/db-based-graph? (:url item)))))
         {remote-graphs true local-graphs false} (group-by (comp boolean :remote?) repos)]
     [:div#graphs
-     (when-not (util/capacitor-new?)
+     (when-not (util/capacitor?)
        [:h1.title (t :graph/all-graphs)])
 
      [:div.pl-1.content.mt-3
@@ -217,7 +217,7 @@
        (when (seq local-graphs)
          (repos-inner local-graphs))
 
-       (when-not (util/capacitor-new?)
+       (when-not (util/capacitor?)
          [:div.flex.flex-row.my-4
           (if util/web-platform?
             [:div.mr-8
@@ -245,7 +245,7 @@
             :background "gray"
             :disabled remotes-loading?
             :on-click (fn []
-                        (when-not (util/capacitor-new?)
+                        (when-not (util/capacitor?)
                           (file-sync/load-session-graphs))
                         (rtc-handler/<get-remote-graphs)))]]
          (repos-inner remote-graphs)])]]))

+ 2 - 2
src/main/frontend/handler/editor.cljs

@@ -932,7 +932,7 @@
           block-parent (get uuid->dom-block (:block/uuid block))
           sibling-block (when block-parent (util/get-prev-block-non-collapsed-non-embed block-parent))
           blocks' (block-handler/get-top-level-blocks blocks)
-          mobile? (util/capacitor-new?)]
+          mobile? (util/capacitor?)]
       (p/do!
        (when (and sibling-block (not mobile?))
          (let [{:keys [edit-block-f]} (move-to-prev-block repo sibling-block
@@ -1056,7 +1056,7 @@
                                       (assoc :db/id (:db/id b)))))))]
         (common-handler/copy-to-clipboard-without-id-property! repo (get block :block/format :markdown) content (when html? html) copied-blocks))
       (state/set-block-op-type! :copy)
-      (when-not (util/capacitor-new?)
+      (when-not (util/capacitor?)
         (notification/show! "Copied!" :success)))))
 
 (defn copy-block-refs

+ 1 - 1
src/main/frontend/handler/events/ui.cljs

@@ -90,7 +90,7 @@
 
 (defmethod events/handle :redirect-to-home [_]
   (page-handler/create-today-journal!)
-  (when (util/capacitor-new?)
+  (when (util/capacitor?)
     (mobile-state/redirect-to-tab! "home")))
 
 (defmethod events/handle :page/show-delete-dialog [[_ selected-rows ok-handler]]

+ 1 - 1
src/main/frontend/mobile/haptics.cljs

@@ -7,7 +7,7 @@
   ([]
    (haptics :light))
   ([impact-style]
-   (when (util/capacitor-new?)
+   (when (util/capacitor?)
      (let [style (cond
                    (= impact-style :light)
                    {:style (.-Light ImpactStyle)}

+ 10 - 9
src/main/frontend/persist_db/browser.cljs

@@ -103,18 +103,19 @@
 
 (defn- reload-app-if-old-db-worker-exists
   []
-  (when-let [client-id @state/*db-worker-client-id]
-    (js/navigator.locks.request client-id #js {:mode "exclusive"
-                                               :ifAvailable true}
-                                (fn [lock]
-                                  (when-not lock
-                                    (js/window.location.reload))))))
+  (when (util/capacitor?)
+    (when-let [client-id @state/*db-worker-client-id]
+      (js/navigator.locks.request client-id #js {:mode "exclusive"
+                                                 :ifAvailable true}
+                                  (fn [lock]
+                                    (when-not lock
+                                      (js/window.location.reload)))))))
 
 (defn start-db-worker!
   []
-  (p/do!
-   (reload-app-if-old-db-worker-exists)
-   (when-not util/node-test?
+  (when-not util/node-test?
+    (p/do!
+     (reload-app-if-old-db-worker-exists)
      (let [worker-url (if config/publishing? "static/js/db-worker.js" "js/db-worker.js")
            worker (js/Worker. (str worker-url "?electron=" (util/electron?) "&publishing=" config/publishing?))
            _ (set-worker-fs worker)

+ 4 - 4
src/main/frontend/util.cljc

@@ -77,7 +77,7 @@
        (when-not node-test?
          (safe-re-find #"Mobi" js/navigator.userAgent)))
      (def mobile? (memoize mobile*?))
-     (def capacitor-new? (memoize #(and js/window (gobj/get js/window "isCapacitorNew"))))))
+     (def capacitor? (memoize #(and js/window (gobj/get js/window "isCapacitorNew"))))))
 
 #?(:cljs
    (extend-protocol IPrintWithWriter
@@ -103,11 +103,11 @@
 
 #?(:cljs (defn app-scroll-container-node
            ([]
-            (if (capacitor-new?)
+            (if (capacitor?)
               (mobile-page-scroll)
               (gdom/getElement "main-content-container")))
            ([el]
-            (if (capacitor-new?)
+            (if (capacitor?)
               (mobile-page-scroll el)
               (if (some-> el (.closest "#main-content-container"))
                 (app-scroll-container-node)
@@ -1491,7 +1491,7 @@ Arg *stop: atom, reset to true to stop the loop"
      ([schedule?]
       (when (mobile?)
         (let [f #(when-let [node (or (get-keep-keyboard-input-el "in-modal")
-                                  (get-keep-keyboard-input-el))]
+                                     (get-keep-keyboard-input-el))]
                    (.focus node))]
           (if schedule? (schedule f) (f)))))))