ソースを参照

fix: both encryption and excalidraw not working on Electron

Tienson Qin 4 年 前
コミット
3605ed53e3

+ 2 - 0
resources/electron-dev.html

@@ -105,5 +105,7 @@ const portal = new MagicPortal(worker);
 <script defer src="./js/interact.min.js"></script>
 <script defer src="./js/main.js"></script>
 <script defer src="./js/code-editor.js"></script>
+<script defer src="./js/age-encryption.js"></script>
+<script defer src="./js/excalidraw.js"></script>
 </body>
 </html>

+ 2 - 0
resources/electron.html

@@ -106,5 +106,7 @@ const portal = new MagicPortal(worker);
 <script defer src="./js/interact.min.js"></script>
 <script defer src="./js/main.js"></script>
 <script defer src="./js/code-editor.js"></script>
+<script defer src="./js/age-encryption.js"></script>
+<script defer src="./js/excalidraw.js"></script>
 </body>
 </html>

ファイルの差分が大きいため隠しています
+ 0 - 1
resources/js/excalidraw.min.js


+ 3 - 0
shadow-cljs.edn

@@ -61,6 +61,9 @@
               :depends-on #{:main}}
              :age-encryption
              {:entries [frontend.extensions.age-encryption]
+              :depends-on #{:main}}
+             :excalidraw
+             {:entries [frontend.extensions.excalidraw]
               :depends-on #{:main}}}
 
    :output-dir "./static/js/publishing"

+ 0 - 1
src/main/frontend/components/encryption.cljs

@@ -149,7 +149,6 @@
        [:input.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
         {:type "password"
          :auto-focus true
-         :style {:color "#000"}
          :on-change (fn [e]
                       (reset! secret (util/evalue e)))}]
 

+ 2 - 1
src/main/frontend/extensions/excalidraw.cljs

@@ -144,5 +144,6 @@
   [option]
   (let [repo (state/get-current-repo)
         granted? (state/sub [:nfs/user-granted? repo])]
-    (when-not (and (config/local-db? repo) (not granted?))
+    ;; Web granted
+    (when-not (and (config/local-db? repo) (not granted?) (not (util/electron?)))
       (draw-container option))))

+ 31 - 29
src/main/frontend/fs/watcher_handler.cljs

@@ -9,43 +9,45 @@
             [frontend.config :as config]
             [frontend.db :as db]
             [frontend.state :as state]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [frontend.encrypt :as encrypt]))
 
 (defn handle-changed!
   [type {:keys [dir path content stat] :as payload}]
   (when dir
     (let [repo (config/get-local-repo dir)
           {:keys [mtime]} stat]
-      (cond
-        (= "add" type)
-        (let [db-content (db/get-file path)]
-          (when (and (not= content db-content)
-                     ;; Avoid file overwrites
-                     ;; 1. create a new page which writes a new file
-                     ;; 2. add some new content
-                     ;; 3. file watcher notified it with the old content
-                     ;; 4. old content will overwrites the new content in step 2
-                     (not (and db-content
-                               (string/starts-with? db-content content))))
-            (file-handler/alter-file repo path content {:re-render-root? true
-                                                        :from-disk? true})))
+      (when (and content (not (encrypt/content-encrypted? content)))
+        (cond
+          (= "add" type)
+          (let [db-content (db/get-file path)]
+            (when (and (not= content db-content)
+                       ;; Avoid file overwrites
+                       ;; 1. create a new page which writes a new file
+                       ;; 2. add some new content
+                       ;; 3. file watcher notified it with the old content
+                       ;; 4. old content will overwrites the new content in step 2
+                       (not (and db-content
+                                 (string/starts-with? db-content content))))
+              (file-handler/alter-file repo path content {:re-render-root? true
+                                                          :from-disk? true})))
 
-        (and (= "change" type)
-             (nil? (db/get-file path)))
-        (js/console.warn "Can't get file in the db: " path)
+          (and (= "change" type)
+               (nil? (db/get-file path)))
+          (js/console.warn "Can't get file in the db: " path)
 
-        (and (= "change" type)
-             (not= content (db/get-file path))
-             (when-let [last-modified-at (db/get-file-last-modified-at repo path)]
-               (> mtime last-modified-at)))
+          (and (= "change" type)
+               (not= content (db/get-file path))
+               (when-let [last-modified-at (db/get-file-last-modified-at repo path)]
+                 (> mtime last-modified-at)))
 
-        (let [_ (file-handler/alter-file repo path content {:re-render-root? true
-                                                            :from-disk? true})]
-          (db/set-file-last-modified-at! repo path mtime))
+          (let [_ (file-handler/alter-file repo path content {:re-render-root? true
+                                                              :from-disk? true})]
+            (db/set-file-last-modified-at! repo path mtime))
 
-        (contains? #{"add" "change" "unlink"} type)
-        nil
+          (contains? #{"add" "change" "unlink"} type)
+          nil
 
-        :else
-        (log/error :fs/watcher-no-handler {:type type
-                                           :payload payload})))))
+          :else
+          (log/error :fs/watcher-no-handler {:type type
+                                             :payload payload}))))))

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません