3 fixes where global-config as incorrectly called for non desktop

These issues were introduced with #6531. The global-config component
should not be called if not in a supported platform. This fixes
re-index, switching graphs and editing config.edn for mobile.  Switching
graphs was partially fixed in #6664 but didn't address the root cause
which is the global-handler component shouldn't be called if not enabled
for a platform
pull/6703/head
Gabriel Horner 2022-09-12 21:41:15 -04:00 committed by Andelf
parent a790146804
commit f157490d61
4 changed files with 22 additions and 19 deletions

View File

@ -95,7 +95,9 @@
(let [original-content (db/get-file repo path) (let [original-content (db/get-file repo path)
write-file! (if from-disk? write-file! (if from-disk?
#(p/resolved nil) #(p/resolved nil)
#(let [path-dir (if (= (path/dirname path) (global-config-handler/global-config-dir)) #(let [path-dir (if (and
(config/global-config-enabled?)
(= (path/dirname path) (global-config-handler/global-config-dir)))
(global-config-handler/global-config-dir) (global-config-handler/global-config-dir)
(config/get-repo-dir repo))] (config/get-repo-dir repo))]
(fs/write-file! repo path-dir path content (fs/write-file! repo path-dir path content
@ -122,7 +124,7 @@
(p/let [_ (repo-config-handler/restore-repo-config! repo)] (p/let [_ (repo-config-handler/restore-repo-config! repo)]
(state/pub-event! [:shortcut/refresh])) (state/pub-event! [:shortcut/refresh]))
(= path (global-config-handler/global-config-path)) (and (config/global-config-enabled?) (= path (global-config-handler/global-config-path)))
(p/let [_ (global-config-handler/restore-global-config!)] (p/let [_ (global-config-handler/restore-global-config!)]
(state/pub-event! [:shortcut/refresh])) (state/pub-event! [:shortcut/refresh]))
@ -131,7 +133,8 @@
(when re-render-root? (ui-handler/re-render-root!))) (when re-render-root? (ui-handler/re-render-root!)))
(fn [error] (fn [error]
(when (= path (global-config-handler/global-config-path)) (when (and (config/global-config-enabled?)
(= path (global-config-handler/global-config-path)))
(state/pub-event! [:notification/show (state/pub-event! [:notification/show
{:content (str "Failed to write to file " path) {:content (str "Failed to write to file " path)
:status :error}])) :status :error}]))

View File

@ -34,24 +34,21 @@
(defn- create-global-config-file-if-not-exists (defn- create-global-config-file-if-not-exists
[repo-url] [repo-url]
(when (not-empty @root-dir) (let [config-dir (global-config-dir)
(let [config-dir (global-config-dir)
config-path (global-config-path)] config-path (global-config-path)]
(p/let [_ (fs/mkdir-if-not-exists config-dir) (p/let [_ (fs/mkdir-if-not-exists config-dir)
file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)] file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
(when-not file-exists? (when-not file-exists?
(file-common-handler/reset-file! repo-url config-path default-content) (file-common-handler/reset-file! repo-url config-path default-content)
(set-global-config-state! default-content)))))) (set-global-config-state! default-content)))))
(defn restore-global-config! (defn restore-global-config!
"Sets global config state from config file" "Sets global config state from config file"
[] []
(if (not-empty @root-dir) (let [config-dir (global-config-dir)
(let [config-dir (global-config-dir) config-path (global-config-path)]
config-path (global-config-path)] (p/let [config-content (fs/read-file config-dir config-path)]
(p/let [config-content (fs/read-file config-dir config-path)] (set-global-config-state! config-content))))
(set-global-config-state! config-content)))
(set-global-config-state! default-content)))
(defn start (defn start
"This component has four responsibilities on start: "This component has four responsibilities on start:

View File

@ -408,7 +408,8 @@
(state/set-db-restoring! true) (state/set-db-restoring! true)
(db/restore-graph! repo) (db/restore-graph! repo)
(repo-config-handler/restore-repo-config! repo) (repo-config-handler/restore-repo-config! repo)
(global-config-handler/restore-global-config!) (when (config/global-config-enabled?)
(global-config-handler/restore-global-config!))
;; Don't have to unlisten the old listener, as it will be destroyed with the conn ;; Don't have to unlisten the old listener, as it will be destroyed with the conn
(db/listen-and-persist! repo) (db/listen-and-persist! repo)
(state/pub-event! [:shortcut/refresh]) (state/pub-event! [:shortcut/refresh])

View File

@ -338,14 +338,16 @@
(fn [path handle] (fn [path handle]
(when nfs? (when nfs?
(swap! path-handles assoc path handle)))) (swap! path-handles assoc path handle))))
global-dir (global-config-handler/global-config-dir)
global-files-result (if (config/global-config-enabled?)
(fs/get-files global-dir (constantly nil))
[])
new-local-files (-> (->db-files mobile-native? electron? dir-name local-files-result) new-local-files (-> (->db-files mobile-native? electron? dir-name local-files-result)
(remove-ignore-files dir-name nfs?)) (remove-ignore-files dir-name nfs?))
new-global-files (-> (->db-files mobile-native? electron? global-dir global-files-result) new-global-files (if (config/global-config-enabled?)
(remove-ignore-files global-dir nfs?)) (p/let [global-files-result (fs/get-files
(global-config-handler/global-config-dir)
(constantly nil))
global-files (-> (->db-files mobile-native? electron? (global-config-handler/global-config-dir) global-files-result)
(remove-ignore-files (global-config-handler/global-config-dir) nfs?))]
global-files)
(p/resolved []))
new-files (concat new-local-files new-global-files) new-files (concat new-local-files new-global-files)
_ (when nfs? _ (when nfs?