Merge remote-tracking branch 'upstream/master' into whiteboards

pull/6850/head
Peng Xiao 2022-09-30 08:51:05 +08:00
commit bb2df1b3b7
13 changed files with 124 additions and 97 deletions

View File

@ -1,7 +1,8 @@
(ns logseq.graph-parser.config (ns logseq.graph-parser.config
"App config that is shared between graph-parser and rest of app" "App config that is shared between graph-parser and rest of app"
(:require [clojure.set :as set] (:require [clojure.set :as set]
[clojure.string :as string])) [clojure.string :as string]
[goog.object :as gobj]))
(def app-name (def app-name
"Copy of frontend.config/app-name. Too small to couple to main app" "Copy of frontend.config/app-name. Too small to couple to main app"
@ -9,7 +10,9 @@
(defonce asset-protocol "assets://") (defonce asset-protocol "assets://")
(defonce capacitor-protocol "capacitor://") (defonce capacitor-protocol "capacitor://")
(defonce capacitor-protocol-with-prefix (str capacitor-protocol "localhost/_capacitor_file_")) (defonce capacitor-prefix "_capacitor_file_")
(defonce capacitor-protocol-with-prefix (str capacitor-protocol "localhost/" capacitor-prefix))
(defonce capacitor-x-protocol-with-prefix (str (gobj/getValueByKeys js/globalThis "location" "href") capacitor-prefix))
(defonce local-assets-dir "assets") (defonce local-assets-dir "assets")
@ -22,14 +25,16 @@
[s] [s]
(when (string? s) (when (string? s)
(or (string/starts-with? s asset-protocol) (or (string/starts-with? s asset-protocol)
(string/starts-with? s capacitor-protocol)))) (string/starts-with? s capacitor-protocol)
(string/starts-with? s capacitor-x-protocol-with-prefix))))
(defn remove-asset-protocol (defn remove-asset-protocol
[s] [s]
(if (local-protocol-asset? s) (if (local-protocol-asset? s)
(-> s (-> s
(string/replace-first asset-protocol "") (string/replace-first asset-protocol "")
(string/replace-first capacitor-protocol-with-prefix "file://")) (string/replace-first capacitor-protocol-with-prefix "file://")
(string/replace-first capacitor-x-protocol-with-prefix "file://"))
s)) s))
(defonce default-draw-directory "draws") (defonce default-draw-directory "draws")

View File

@ -85,7 +85,7 @@
"@capacitor/status-bar": "^4.0.0", "@capacitor/status-bar": "^4.0.0",
"@excalidraw/excalidraw": "0.10.0", "@excalidraw/excalidraw": "0.10.0",
"@kanru/rage-wasm": "^0.3.0", "@kanru/rage-wasm": "^0.3.0",
"@logseq/capacitor-file-sync": "0.0.10", "@logseq/capacitor-file-sync": "0.0.11",
"@logseq/react-tweet-embed": "1.3.1-1", "@logseq/react-tweet-embed": "1.3.1-1",
"@sentry/react": "^6.18.2", "@sentry/react": "^6.18.2",
"@sentry/tracing": "^6.18.2", "@sentry/tracing": "^6.18.2",

View File

@ -37,7 +37,7 @@
"https-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.0",
"@sentry/electron": "2.5.1", "@sentry/electron": "2.5.1",
"posthog-js": "1.10.2", "posthog-js": "1.10.2",
"@logseq/rsapi": "0.0.46", "@logseq/rsapi": "0.0.48",
"electron-deeplink": "1.0.10", "electron-deeplink": "1.0.10",
"abort-controller": "3.0.0" "abort-controller": "3.0.0"
}, },

View File

@ -47,6 +47,9 @@
(defn decrypt-with-passphrase [passphrase data] (defn decrypt-with-passphrase [passphrase data]
(rsapi/ageDecryptWithPassphrase passphrase data)) (rsapi/ageDecryptWithPassphrase passphrase data))
(defn cancel-all-requests []
(rsapi/cancelAllRequests))
(defonce progress-notify-chan "file-sync-progress") (defonce progress-notify-chan "file-sync-progress")
(set-progress-callback (fn [error progress-info] (set-progress-callback (fn [error progress-info]
(when-not error (when-not error

View File

@ -579,6 +579,9 @@
(defmethod handle :decrypt-with-passphrase [_ args] (defmethod handle :decrypt-with-passphrase [_ args]
(apply rsapi/decrypt-with-passphrase (rest args))) (apply rsapi/decrypt-with-passphrase (rest args)))
(defmethod handle :cancel-all-requests [_ args]
(apply rsapi/cancel-all-requests (rest args)))
(defmethod handle :default [args] (defmethod handle :default [args]
(logger/error "Error: no ipc handler for:" args)) (logger/error "Error: no ipc handler for:" args))

View File

@ -1895,7 +1895,14 @@
priority (priority-cp t) priority (priority-cp t)
tags (block-tags-cp t) tags (block-tags-cp t)
bg-color (:background-color properties) bg-color (:background-color properties)
heading (:heading properties) ;; `heading-level` is for backward compatiblity, will remove it in later releases
heading-level (:block/heading-level t)
heading (or
(and heading-level
(<= heading-level 6)
heading-level)
(:heading properties))
heading (if (true? heading) 2 heading)
elem (if heading elem (if heading
(keyword (str "h" heading (keyword (str "h" heading
(when block-ref? ".inline"))) (when block-ref? ".inline")))

View File

@ -306,11 +306,8 @@
(ui/icon "chevron-left" {:style {:font-size 24}}))])]])) (ui/icon "chevron-left" {:style {:font-size 24}}))])]]))
(defn- sort-files (defn- sort-files
[progress files] [files]
(sort-by (fn [f] (sort-by (fn [f] (or (:size f) 0)) > files))
(let [percent (or (:percent (get progress f)) 0)]
(if (= percent 100) -1 percent)))
> files))
(rum/defcs ^:large-vars/cleanup-todo indicator < (rum/defcs ^:large-vars/cleanup-todo indicator <
rum/reactive rum/reactive
@ -331,8 +328,8 @@
sync-progress (state/sub [:file-sync/progress (second @fs-sync/graphs-txid)]) sync-progress (state/sub [:file-sync/progress (second @fs-sync/graphs-txid)])
_ (rum/react file-sync-handler/refresh-file-sync-component) _ (rum/react file-sync-handler/refresh-file-sync-component)
synced-file-graph? (file-sync-handler/synced-file-graph? current-repo) synced-file-graph? (file-sync-handler/synced-file-graph? current-repo)
uploading-files (sort-files sync-progress (:current-local->remote-files sync-state)) uploading-files (sort-files (:current-local->remote-files sync-state))
downloading-files (sort-files sync-progress (:current-remote->local-files sync-state)) downloading-files (sort-files (:current-remote->local-files sync-state))
queuing-files (:queued-local->remote-files sync-state) queuing-files (:queued-local->remote-files sync-state)
history-files (:history sync-state) history-files (:history sync-state)
status (:state sync-state) status (:state sync-state)
@ -525,56 +522,49 @@
[:div.cp__file-sync-related-normal-modal [:div.cp__file-sync-related-normal-modal
[:div.flex.justify-center.pb-4 [:span.icon-wrap (ui/icon "cloud-download")]] [:div.flex.justify-center.pb-4 [:span.icon-wrap (ui/icon "cloud-download")]]
[:h1.mb-5.text-2xl.text-center.font-bold "Sync a remote graph to local"] [:h1.mb-5.text-2xl.text-center.font-bold (util/format "Sync graph \"%s\" to local"
(:GraphName graph))]
[:div.folder-tip.flex.flex-col.items-center (ui/button
{:style {:border-bottom-right-radius 0 :border-bottom-left-radius 0}} "Open a local directory"
[:h3 :class "block w-full py-4 mt-4"
[:span.flex.space-x-2.leading-none.pb-1 :on-click #(do
(ui/icon "cloud-lock") (state/close-modal!)
[:span (:GraphName graph)] (fs-sync/<sync-stop)
[:span.scale-75 (ui/icon "arrow-right")] (->
[:span (ui/icon "folder")]]] (page-handler/ls-dir-files!
[:h4.px-2.-mb-1.5 [:strong "UUID: "] (:GraphUUID graph)]] (fn [{:keys [url]}]
(file-sync-handler/init-remote-graph url graph)
(js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200))
[:div.-mt-1 {:empty-dir?-or-pred
(ui/button (fn [ret]
"Open a local directory" (let [empty-dir? (nil? (second ret))]
:class "w-full rounded-t-none py-4" (if-let [root (first ret)]
:on-click #(do
(state/close-modal!)
(fs-sync/<sync-stop)
(->
(page-handler/ls-dir-files!
(fn [{:keys [url]}]
(file-sync-handler/init-remote-graph url graph)
(js/setTimeout (fn [] (repo-handler/refresh-repos!)) 200))
{:empty-dir?-or-pred ;; verify directory
(fn [ret] (-> (if empty-dir?
(let [empty-dir? (nil? (second ret))] (p/resolved nil)
(if-let [root (first ret)] (if (util/electron?)
(ipc/ipc :readGraphTxIdInfo root)
(fs-util/read-graphs-txid-info root)))
;; verify directory (p/then (fn [^js info]
(-> (if empty-dir? (when (and (not empty-dir?)
(p/resolved nil) (or (nil? info)
(if (util/electron?) (nil? (second info))
(ipc/ipc :readGraphTxIdInfo root) (not= (second info) (:GraphUUID graph))))
(fs-util/read-graphs-txid-info root))) (if (js/confirm "This directory is not empty, are you sure to sync the remote graph to it? Make sure to back up the directory first.")
(p/resolved nil)
(throw (js/Error. nil)))))))
(p/then (fn [^js info] ;; cancel pick a directory
(when (and (not empty-dir?) (throw (js/Error. nil)))))})
(or (nil? info) (p/catch (fn [])))))
(nil? (second info))
(not= (second info) (:GraphUUID graph))))
(if (js/confirm "This directory is not empty, are you sure to sync the remote graph to it? Make sure to back up the directory first.")
(p/resolved nil)
(throw (js/Error. nil)))))))
;; cancel pick a directory [:div.text-xs.opacity-50.px-1.flex-row.flex.items-center.p-2
(throw (js/Error. nil)))))}) (ui/icon "alert-circle")
(p/catch (fn []))))) [:span.ml-1 " An empty directory or an existing remote graph!"]]])
[:p.text-xs.opacity-50.px-1 (ui/icon "alert-circle") " An empty directory or an existing remote graph!"]]])
(defn pick-dest-to-sync-panel [graph] (defn pick-dest-to-sync-panel [graph]
(fn [] (fn []

View File

@ -54,6 +54,8 @@
:block/repeated? :block/repeated?
:block/created-at :block/created-at
:block/updated-at :block/updated-at
;; TODO: remove this in later releases
:block/heading-level
:block/file :block/file
{:block/page [:db/id :block/name :block/original-name :block/journal-day]} {:block/page [:db/id :block/name :block/original-name :block/journal-day]}
{:block/_parent ...}]) {:block/_parent ...}])

View File

@ -657,7 +657,8 @@
(<update-remote-files [this graph-uuid base-path filepaths local-txid] "local -> remote, return err or txid") (<update-remote-files [this graph-uuid base-path filepaths local-txid] "local -> remote, return err or txid")
(<delete-remote-files [this graph-uuid base-path filepaths local-txid] "return err or txid") (<delete-remote-files [this graph-uuid base-path filepaths local-txid] "return err or txid")
(<encrypt-fnames [this graph-uuid fnames]) (<encrypt-fnames [this graph-uuid fnames])
(<decrypt-fnames [this graph-uuid fnames])) (<decrypt-fnames [this graph-uuid fnames])
(<cancel-all-requests [this]))
(defprotocol IRemoteAPI (defprotocol IRemoteAPI
(<user-info [this] "user info") (<user-info [this] "user info")
@ -718,6 +719,8 @@
(recur (dec n))) (recur (dec n)))
r)))) r))))
(declare <rsapi-cancel-all-requests)
(deftype RSAPI [^:mutable graph-uuid' ^:mutable private-key' ^:mutable public-key'] (deftype RSAPI [^:mutable graph-uuid' ^:mutable private-key' ^:mutable public-key']
IToken IToken
(<get-token [this] (<get-token [this]
@ -765,6 +768,7 @@
(<update-local-files [this graph-uuid base-path filepaths] (<update-local-files [this graph-uuid base-path filepaths]
(println "update-local-files" graph-uuid base-path filepaths) (println "update-local-files" graph-uuid base-path filepaths)
(go (go
(<! (<rsapi-cancel-all-requests))
(let [token (<! (<get-token this))] (let [token (<! (<get-token this))]
(<! (p->c (ipc/ipc "update-local-files" graph-uuid base-path filepaths token)))))) (<! (p->c (ipc/ipc "update-local-files" graph-uuid base-path filepaths token))))))
(<download-version-files [this graph-uuid base-path filepaths] (<download-version-files [this graph-uuid base-path filepaths]
@ -782,6 +786,7 @@
(<update-remote-files [this graph-uuid base-path filepaths local-txid] (<update-remote-files [this graph-uuid base-path filepaths local-txid]
(go (go
(<! (<rsapi-cancel-all-requests))
(let [token (<! (<get-token this))] (let [token (<! (<get-token this))]
(<! (<retry-rsapi (<! (<retry-rsapi
#(p->c (ipc/ipc "update-remote-files" graph-uuid base-path filepaths local-txid token))))))) #(p->c (ipc/ipc "update-remote-files" graph-uuid base-path filepaths local-txid token)))))))
@ -794,10 +799,12 @@
#(p->c (ipc/ipc "delete-remote-files" graph-uuid base-path filepaths local-txid token))))))) #(p->c (ipc/ipc "delete-remote-files" graph-uuid base-path filepaths local-txid token)))))))
(<encrypt-fnames [_ graph-uuid fnames] (go (js->clj (<! (p->c (ipc/ipc "encrypt-fnames" graph-uuid fnames)))))) (<encrypt-fnames [_ graph-uuid fnames] (go (js->clj (<! (p->c (ipc/ipc "encrypt-fnames" graph-uuid fnames))))))
(<decrypt-fnames [_ graph-uuid fnames] (go (<decrypt-fnames [_ graph-uuid fnames] (go
(let [r (<! (p->c (ipc/ipc "decrypt-fnames" graph-uuid fnames)))] (let [r (<! (p->c (ipc/ipc "decrypt-fnames" graph-uuid fnames)))]
(if (instance? ExceptionInfo r) (if (instance? ExceptionInfo r)
(ex-info "decrypt-failed" {:fnames fnames} (ex-cause r)) (ex-info "decrypt-failed" {:fnames fnames} (ex-cause r))
(js->clj r)))))) (js->clj r)))))
(<cancel-all-requests [_]
(p->c (ipc/ipc "cancel-all-requests"))))
(deftype ^:large-vars/cleanup-todo CapacitorAPI [^:mutable graph-uuid' ^:mutable private-key ^:mutable public-key'] (deftype ^:large-vars/cleanup-todo CapacitorAPI [^:mutable graph-uuid' ^:mutable private-key ^:mutable public-key']
@ -873,10 +880,10 @@
(let [token (<! (<get-token this)) (let [token (<! (<get-token this))
r (<! (<retry-rsapi r (<! (<retry-rsapi
#(p->c (.updateLocalVersionFiles mobile-util/file-sync #(p->c (.updateLocalVersionFiles mobile-util/file-sync
(clj->js {:graphUUID graph-uuid (clj->js {:graphUUID graph-uuid
:basePath base-path :basePath base-path
:filePaths filepaths :filePaths filepaths
:token token})))))] :token token})))))]
r))) r)))
(<delete-local-files [_ graph-uuid base-path filepaths] (<delete-local-files [_ graph-uuid base-path filepaths]
@ -903,15 +910,15 @@
(<delete-remote-files [this graph-uuid _base-path filepaths local-txid] (<delete-remote-files [this graph-uuid _base-path filepaths local-txid]
(go (go
(let [token (<! (<get-token this)) (let [token (<! (<get-token this))
r (<! (p->c (.deleteRemoteFiles mobile-util/file-sync r (<! (p->c (.deleteRemoteFiles mobile-util/file-sync
(clj->js {:graphUUID graph-uuid (clj->js {:graphUUID graph-uuid
:filePaths filepaths :filePaths filepaths
:txid local-txid :txid local-txid
:token token}))))] :token token}))))]
(if (instance? ExceptionInfo r) (if (instance? ExceptionInfo r)
r r
(get (js->clj r) "txid"))))) (get (js->clj r) "txid")))))
(<encrypt-fnames [_ graph-uuid fnames] (<encrypt-fnames [_ graph-uuid fnames]
(go (go
@ -927,7 +934,9 @@
:filePaths fnames}))))] :filePaths fnames}))))]
(if (instance? ExceptionInfo r) (if (instance? ExceptionInfo r)
(ex-info "decrypt-failed" {:fnames fnames} (ex-cause r)) (ex-info "decrypt-failed" {:fnames fnames} (ex-cause r))
(get (js->clj r) "value")))))) (get (js->clj r) "value")))))
(<cancel-all-requests [_]
(p->c (.cancelAllRequests mobile-util/file-sync))))
(def rsapi (cond (def rsapi (cond
(util/electron?) (util/electron?)
@ -942,6 +951,11 @@
:else :else
nil)) nil))
(defn <rsapi-cancel-all-requests []
(go
(when rsapi
(<! (<cancel-all-requests rsapi)))))
;;; ### remote & rs api exceptions ;;; ### remote & rs api exceptions
(defn sync-stop-when-api-flying? (defn sync-stop-when-api-flying?
[exp] [exp]
@ -2803,6 +2817,7 @@
(when ops-chan (async/close! ops-chan)) (when ops-chan (async/close! ops-chan))
(stop-local->remote! local->remote-syncer) (stop-local->remote! local->remote-syncer)
(stop-remote->local! remote->local-syncer) (stop-remote->local! remote->local-syncer)
(<! (<rsapi-cancel-all-requests))
(debug/pprint ["stop sync-manager, graph-uuid" graph-uuid "base-path" base-path]) (debug/pprint ["stop sync-manager, graph-uuid" graph-uuid "base-path" base-path])
(swap! *sync-state sync-state--update-state ::stop) (swap! *sync-state sync-state--update-state ::stop)
(loop [] (loop []

View File

@ -2795,7 +2795,8 @@
value (gobj/get input "value") value (gobj/get input "value")
c (util/nth-safe value (dec current-pos)) c (util/nth-safe value (dec current-pos))
[key-code k code is-processed?] [key-code k code is-processed?]
(if (and (mobile-util/native-android?) (if (and c
(mobile-util/native-android?)
(or (= key-code 229) (or (= key-code 229)
(= key-code 0))) (= key-code 0)))
[(.charCodeAt value (dec current-pos)) [(.charCodeAt value (dec current-pos))

View File

@ -163,12 +163,13 @@
state/set-state! :sync-graph/init? false))) state/set-state! :sync-graph/init? false)))
(defmethod handle :graph/switch [[_ graph opts]] (defmethod handle :graph/switch [[_ graph opts]]
(if (or (not (false? (get @outliner-file/*writes-finished? graph))) (let [opts (if (false? (:persist? opts)) opts (assoc opts :persist? true))]
(:sync-graph/init? @state/state)) (if (or (not (false? (get @outliner-file/*writes-finished? graph)))
(graph-switch-on-persisted graph opts) (:sync-graph/init? @state/state))
(notification/show! (graph-switch-on-persisted graph opts)
"Please wait seconds until all changes are saved for the current graph." (notification/show!
:warning))) "Please wait seconds until all changes are saved for the current graph."
:warning))))
(defmethod handle :graph/pick-dest-to-sync [[_ graph]] (defmethod handle :graph/pick-dest-to-sync [[_ graph]]
(state/set-modal! (state/set-modal!

View File

@ -233,24 +233,24 @@
;; file-sync ;; file-sync
:file-sync/jstour-inst nil :file-sync/jstour-inst nil
:file-sync/remote-graphs {:loading false :graphs nil}
:file-sync/sync-manager nil
:file-sync/sync-state-manager nil
:file-sync/sync-state nil
:file-sync/sync-uploading-files nil
:file-sync/sync-downloading-files nil
:file-sync/onboarding-state (or (storage/get :file-sync/onboarding-state) :file-sync/onboarding-state (or (storage/get :file-sync/onboarding-state)
{:welcome false}) {:welcome false})
:encryption/graph-parsing? false :file-sync/remote-graphs {:loading false :graphs nil}
:file-sync/sync-manager nil
:ui/loading? {} :file-sync/sync-state nil
:file-sync/sync-uploading-files nil
:file-sync/sync-downloading-files nil
:file-sync/set-remote-graph-password-result {} :file-sync/set-remote-graph-password-result {}
;; graph-uuid -> {file-path -> payload} ;; graph-uuid -> {file-path -> payload}
:file-sync/progress {} :file-sync/progress {}
:file-sync/start {} :file-sync/start {}
;; graph -> epoch ;; graph -> epoch
:file-sync/last-synced-at {} :file-sync/last-synced-at {}
:encryption/graph-parsing? false
:ui/loading? {}
:feature/enable-sync? (storage/get :logseq-sync-enabled) :feature/enable-sync? (storage/get :logseq-sync-enabled)
:file/rename-event-chan (async/chan 100) :file/rename-event-chan (async/chan 100)

View File

@ -480,10 +480,10 @@
resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.3.0.tgz#de96b1fda1f781ff401d43b50d0f95b7338c4399" resolved "https://registry.yarnpkg.com/@kanru/rage-wasm/-/rage-wasm-0.3.0.tgz#de96b1fda1f781ff401d43b50d0f95b7338c4399"
integrity sha512-2LMRS27nNJPqFNpRQL7kXG0kgBeIPo63KM6u0Xu6Es5XIS7LP4MFtdHkCg8Pt7IhMM7GuOa2YnzAZgKBxE1lcw== integrity sha512-2LMRS27nNJPqFNpRQL7kXG0kgBeIPo63KM6u0Xu6Es5XIS7LP4MFtdHkCg8Pt7IhMM7GuOa2YnzAZgKBxE1lcw==
"@logseq/capacitor-file-sync@0.0.10": "@logseq/capacitor-file-sync@0.0.11":
version "0.0.10" version "0.0.11"
resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.10.tgz#36575b369a4fff83e71b282c19cc948d60309809" resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.11.tgz#aa84f320d73c292d8dd9e483e0ccf73baa2e021b"
integrity sha512-O4bCHLym7+DnqCoO57D1Ii6ec6tcZBjp8SzFEYCKE9mvHsX5aFmCA61XUHgNEFovocQ3gBMJvi6GKSJBcGwT3Q== integrity sha512-ZCV/2fp8iPpShk+rk+6aH3aFZID7BKhSlyw/f4fcSCapbh6im638GR2fi9RPRc1eg+0vbtrx6UzG7Vbw+Kz2aQ==
"@logseq/react-tweet-embed@1.3.1-1": "@logseq/react-tweet-embed@1.3.1-1":
version "1.3.1-1" version "1.3.1-1"