fix: files not saved when onboarding while canceld the file picker

pull/3027/head
Tienson Qin 2021-10-27 18:55:36 +08:00
parent 7282c15ee1
commit 12fe2f9fad
4 changed files with 62 additions and 61 deletions

View File

@ -117,10 +117,13 @@
(let [result (.showOpenDialogSync dialog (bean/->js
{:properties ["openDirectory" "createDirectory" "promptToCreate"]}))
path (first result)]
(.. ^js window -webContents
(send "open-dir-confirmed"
(bean/->js {:opened? true})))
(get-files path)))
(if path
(do
(.. ^js window -webContents
(send "open-dir-confirmed"
(bean/->js {:opened? true})))
(get-files path))
(throw (js/Error "path empty")))))
(defmethod handle :getFiles [window [_ path]]
(get-files path))

View File

@ -129,15 +129,12 @@
(defn open-dir
[ok-handler]
(let [record (get-record)]
(->
(p/let [result (protocol/open-dir record ok-handler)]
(if (or (util/electron?)
(mobile-util/is-native-platform?))
(let [[dir & paths] (bean/->clj result)]
[(:path dir) paths])
result))
(p/catch (fn [error]
(js/console.error error))))))
(p/let [result (protocol/open-dir record ok-handler)]
(if (or (util/electron?)
(mobile-util/is-native-platform?))
(let [[dir & paths] (bean/->clj result)]
[(:path dir) paths])
result))))
(defn get-files
[path-or-handle ok-handler]

View File

@ -133,54 +133,55 @@
root-handle (first result)
dir-name (if nfs?
(gobj/get root-handle "name")
root-handle)
repo (str config/local-db-prefix dir-name)
root-handle-path (str config/local-handle-prefix dir-name)
_ (when nfs?
(idb/set-item! root-handle-path root-handle)
(nfs/add-nfs-file-handle! root-handle-path root-handle))
result (nth result 1)
files (-> (->db-files mobile-native? electron? dir-name result)
remove-ignore-files)
_ (when nfs?
(let [file-paths (set (map :file/path files))]
(swap! path-handles (fn [handles]
(->> handles
(filter (fn [[path _handle]]
(or
(contains? file-paths
(string/replace-first path (str dir-name "/") ""))
(let [last-part (last (string/split path "/"))]
(contains? #{config/app-name
config/default-draw-directory
(config/get-journals-directory)
(config/get-pages-directory)}
last-part)))))
(into {})))))
root-handle)]
(when-not (string/blank? dir-name)
(p/let [repo (str config/local-db-prefix dir-name)
root-handle-path (str config/local-handle-prefix dir-name)
_ (when nfs?
(idb/set-item! root-handle-path root-handle)
(nfs/add-nfs-file-handle! root-handle-path root-handle))
result (nth result 1)
files (-> (->db-files mobile-native? electron? dir-name result)
remove-ignore-files)
_ (when nfs?
(let [file-paths (set (map :file/path files))]
(swap! path-handles (fn [handles]
(->> handles
(filter (fn [[path _handle]]
(or
(contains? file-paths
(string/replace-first path (str dir-name "/") ""))
(let [last-part (last (string/split path "/"))]
(contains? #{config/app-name
config/default-draw-directory
(config/get-journals-directory)
(config/get-pages-directory)}
last-part)))))
(into {})))))
(set-files! @path-handles))
markup-files (filter-markup-and-built-in-files files)]
(-> (p/all (map (fn [file]
(p/let [content (if nfs?
(.text (:file/file file))
(:file/content file))
content (encrypt/decrypt content)]
(assoc file :file/content content))) markup-files))
(p/then (fn [result]
(let [files (map #(dissoc % :file/file) result)]
(repo-handler/start-repo-db-if-not-exists! repo {:db-type :local-native-fs})
(p/let [_ (repo-handler/load-repo-to-db! repo
{:first-clone? true
:nfs-files files})]
(state/add-repo! {:url repo :nfs? true})
(state/set-loading-files! false)
(and ok-handler (ok-handler))
(when (util/electron?)
(fs/watch-dir! dir-name))
(state/pub-event! [:graph/added repo])))))
(p/catch (fn [error]
(log/error :nfs/load-files-error repo)
(log/error :exception error)))))
(set-files! @path-handles))
markup-files (filter-markup-and-built-in-files files)]
(-> (p/all (map (fn [file]
(p/let [content (if nfs?
(.text (:file/file file))
(:file/content file))
content (encrypt/decrypt content)]
(assoc file :file/content content))) markup-files))
(p/then (fn [result]
(let [files (map #(dissoc % :file/file) result)]
(repo-handler/start-repo-db-if-not-exists! repo {:db-type :local-native-fs})
(p/let [_ (repo-handler/load-repo-to-db! repo
{:first-clone? true
:nfs-files files})]
(state/add-repo! {:url repo :nfs? true})
(state/set-loading-files! false)
(and ok-handler (ok-handler))
(when (util/electron?)
(fs/watch-dir! dir-name))
(state/pub-event! [:graph/added repo])))))
(p/catch (fn [error]
(log/error :nfs/load-files-error repo)
(log/error :exception error)))))))
(p/catch (fn [error]
(if (contains? #{"AbortError" "Error"} (gobj/get error "name"))
(state/set-loading-files! false)

View File

@ -414,7 +414,7 @@
(defn add-repo!
[repo]
(when repo
(when (not (string/blank? repo))
(update-state! [:me :repos]
(fn [repos]
(->> (conj repos repo)