fix: both encryption and excalidraw not working on Electron

pull/1437/head
Tienson Qin 2021-03-11 00:30:39 +08:00
parent 81b50400d8
commit 3605ed53e3
7 changed files with 40 additions and 33 deletions

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

@ -144,5 +144,6 @@
[option] [option]
(let [repo (state/get-current-repo) (let [repo (state/get-current-repo)
granted? (state/sub [:nfs/user-granted? 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)))) (draw-container option))))

View File

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