Просмотр исходного кода

fix: disable custom.js on mobile

Tienson Qin 3 лет назад
Родитель
Сommit
60d1a48fb0

+ 1 - 1
capacitor.config.ts

@@ -17,7 +17,7 @@ const config: CapacitorConfig = {
     // do not commit this into source control
     // source: https://capacitorjs.com/docs/guides/live-reload
     , server: {
-       url: "http://192.168.0.104:3001" //process.env.LOGSEQ_APP_SERVER_URL,
+       url: process.env.LOGSEQ_APP_SERVER_URL,
        cleartext: true
     }
 };

+ 9 - 6
src/main/frontend/fs/capacitor_fs.cljs

@@ -100,12 +100,15 @@
     nil)
   (read-file [this dir path _options]
     (let [path (str dir path)]
-      (p/let [content (.readFile Filesystem
-                                 (clj->js
-                                  {:path path
-                                   :directory (.-ExternalStorage Directory)
-                                   :encoding (.-UTF8 Encoding)}))]
-        content)))
+      (->
+       (p/let [content (.readFile Filesystem
+                                  (clj->js
+                                   {:path path
+                                    :directory (.-ExternalStorage Directory)
+                                    :encoding (.-UTF8 Encoding)}))]
+         content)
+       (p/catch (fn [error]
+                  (js/alert error))))))
   (write-file! [this repo dir path content {:keys [ok-handler error-handler] :as opts}]
     (let [path (cond
                  (= (util/platform) "ios")

+ 22 - 20
src/main/frontend/handler/repo.cljs

@@ -28,7 +28,8 @@
             [lambdaisland.glogi :as log]
             [promesa.core :as p]
             [shadow.resource :as rc]
-            [clojure.set :as set]))
+            [clojure.set :as set]
+            [frontend.mobile.util :as mobile]))
 
 ;; Project settings should be checked in two situations:
 ;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
@@ -554,25 +555,26 @@
 
 (defn setup-local-repo-if-not-exists!
   []
-  (if js/window.pfs
-    (let [repo config/local-repo]
-      (p/do! (fs/mkdir-if-not-exists (str "/" repo))
-             (state/set-current-repo! repo)
-             (db/start-db-conn! nil repo)
-             (when-not config/publishing?
-               (let [dummy-notes (get-in dicts/dicts [:en :tutorial/dummy-notes])]
-                 (create-dummy-notes-page repo dummy-notes)))
-             (when-not config/publishing?
-               (let [tutorial (get-in dicts/dicts [:en :tutorial/text])
-                     tutorial (string/replace-first tutorial "$today" (date/today))]
-                 (create-today-journal-if-not-exists repo {:content tutorial})))
-             (create-config-file-if-not-exists repo)
-             (create-contents-file repo)
-             (create-favorites-file repo)
-             (create-custom-theme repo)
-             (state/set-db-restoring! false)
-             (ui-handler/re-render-root!)))
-    (js/setTimeout setup-local-repo-if-not-exists! 100)))
+  (when-not (mobile/is-native-platform?)
+    (if js/window.pfs
+      (let [repo config/local-repo]
+        (p/do! (fs/mkdir-if-not-exists (str "/" repo))
+               (state/set-current-repo! repo)
+               (db/start-db-conn! nil repo)
+               (when-not config/publishing?
+                 (let [dummy-notes (get-in dicts/dicts [:en :tutorial/dummy-notes])]
+                   (create-dummy-notes-page repo dummy-notes)))
+               (when-not config/publishing?
+                 (let [tutorial (get-in dicts/dicts [:en :tutorial/text])
+                       tutorial (string/replace-first tutorial "$today" (date/today))]
+                   (create-today-journal-if-not-exists repo {:content tutorial})))
+               (create-config-file-if-not-exists repo)
+               (create-contents-file repo)
+               (create-favorites-file repo)
+               (create-custom-theme repo)
+               (state/set-db-restoring! false)
+               (ui-handler/re-render-root!)))
+      (js/setTimeout setup-local-repo-if-not-exists! 100))))
 
 (defn periodically-pull-current-repo
   []

+ 32 - 30
src/main/frontend/handler/ui.cljs

@@ -13,7 +13,8 @@
             [goog.object :as gobj]
             [clojure.string :as string]
             [rum.core :as rum]
-            [clojure.edn :as edn]))
+            [clojure.edn :as edn]
+            [frontend.mobile.util :as mobile]))
 
 ;; sidebars
 (defn close-left-sidebar!
@@ -122,37 +123,38 @@
 
 (defn exec-js-if-exists-&-allowed!
   [t]
-  (when-let [href (or
+  (when-not mobile/is-native-platform?
+    (when-let [href (or
                      (state/get-custom-js-link)
                      (config/get-custom-js-path))]
-    (let [k (str "ls-js-allowed-" href)
-          execed #(swap! *js-execed conj href)
-          execed? (contains? @*js-execed href)
-          ask-allow #(let [r (js/confirm (t :plugin/custom-js-alert))]
-                       (if r
-                         (storage/set k (js/Date.now))
-                         (storage/set k false))
-                       r)
-          allowed! (storage/get k)
-          should-ask? (or (nil? allowed!)
-                          (> (- (js/Date.now) allowed!) 604800000))]
-      (when (and (not execed?)
-                 (not= false allowed!))
-        (if (string/starts-with? href "http")
-          (when (or (not should-ask?)
-                    (ask-allow))
-            (load href #(do (js/console.log "[custom js]" href) (execed))))
-          (util/p-handle
-            (fs/read-file (if (util/electron?) "" (config/get-repo-dir (state/get-current-repo))) href)
-            #(when-let [scripts (and % (string/trim %))]
-               (when-not (string/blank? scripts)
-                 (if (or (not should-ask?) (ask-allow))
-                   (try
-                     (do
-                       (js/eval scripts)
-                       (execed))
-                     (catch js/Error e
-                       (js/console.error "[custom js]" e))))))))))))
+      (let [k (str "ls-js-allowed-" href)
+            execed #(swap! *js-execed conj href)
+            execed? (contains? @*js-execed href)
+            ask-allow #(let [r (js/confirm (t :plugin/custom-js-alert))]
+                         (if r
+                           (storage/set k (js/Date.now))
+                           (storage/set k false))
+                         r)
+            allowed! (storage/get k)
+            should-ask? (or (nil? allowed!)
+                            (> (- (js/Date.now) allowed!) 604800000))]
+        (when (and (not execed?)
+                   (not= false allowed!))
+          (if (string/starts-with? href "http")
+            (when (or (not should-ask?)
+                      (ask-allow))
+              (load href #(do (js/console.log "[custom js]" href) (execed))))
+            (util/p-handle
+             (fs/read-file (if (util/electron?) "" (config/get-repo-dir (state/get-current-repo))) href)
+             #(when-let [scripts (and % (string/trim %))]
+                (when-not (string/blank? scripts)
+                  (if (or (not should-ask?) (ask-allow))
+                    (try
+                      (do
+                        (js/eval scripts)
+                        (execed))
+                      (catch js/Error e
+                        (js/console.error "[custom js]" e)))))))))))))
 
 (defn toggle-wide-mode!
   []