Can access read global config file from UI

Only for reload case
pull/6650/head
Gabriel Horner 2022-09-01 11:45:02 -04:00 committed by Andelf
parent 5b50e229e0
commit 9c0bb02dcd
6 changed files with 57 additions and 15 deletions

View File

@ -144,6 +144,14 @@
:on-click #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!))) :on-click #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
:-for "config_edn"})) :-for "config_edn"}))
(defn edit-global-config-edn []
(row-with-button-action
{:left-label (t :settings-page/custom-global-configuration)
:button-label (t :settings-page/edit-global-config-edn)
:href (rfe/href :file {:path (config/get-global-config-path)})
:on-click #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
:-for "global_config_edn"}))
(defn edit-custom-css [] (defn edit-custom-css []
(row-with-button-action (row-with-button-action
{:left-label (t :settings-page/custom-theme) {:left-label (t :settings-page/custom-theme)
@ -538,6 +546,8 @@
(version-row t version) (version-row t version)
(language-row t preferred-language) (language-row t preferred-language)
(theme-modes-row t switch-theme system-theme? dark?) (theme-modes-row t switch-theme system-theme? dark?)
;; TODO: Disable for mobile
(edit-global-config-edn)
(when current-repo (edit-config-edn)) (when current-repo (edit-config-edn))
(when current-repo (edit-custom-css)) (when current-repo (edit-custom-css))
(when current-repo (edit-export-css)) (when current-repo (edit-export-css))

View File

@ -6,7 +6,8 @@
[frontend.util :as util] [frontend.util :as util]
[logseq.graph-parser.config :as gp-config] [logseq.graph-parser.config :as gp-config]
[logseq.graph-parser.util :as gp-util] [logseq.graph-parser.util :as gp-util]
[shadow.resource :as rc])) [shadow.resource :as rc]
["path" :as path]))
(goog-define DEV-RELEASE false) (goog-define DEV-RELEASE false)
(defonce dev-release? DEV-RELEASE) (defonce dev-release? DEV-RELEASE)
@ -375,6 +376,14 @@
(when repo (when repo
(get-file-path repo (str app-name "/" config-file))))) (get-file-path repo (str app-name "/" config-file)))))
(defn get-global-config-dir
[]
(path/join (state/get-root-dir) "config"))
(defn get-global-config-path
[]
(path/join (state/get-root-dir) "config" "config.edn"))
(defn get-metadata-path (defn get-metadata-path
([] ([]
(get-metadata-path (state/get-current-repo))) (get-metadata-path (state/get-current-repo)))

View File

@ -152,9 +152,11 @@
:settings-page/git-switcher-label "Enable Git auto commit" :settings-page/git-switcher-label "Enable Git auto commit"
:settings-page/git-commit-delay "Git auto commit seconds" :settings-page/git-commit-delay "Git auto commit seconds"
:settings-page/edit-config-edn "Edit config.edn" :settings-page/edit-config-edn "Edit config.edn"
:settings-page/edit-global-config-edn "Edit global config.edn"
:settings-page/edit-custom-css "Edit custom.css" :settings-page/edit-custom-css "Edit custom.css"
:settings-page/edit-export-css "Edit export.css" :settings-page/edit-export-css "Edit export.css"
:settings-page/custom-configuration "Custom configuration" :settings-page/custom-configuration "Custom configuration"
:settings-page/custom-global-configuration "Custom global configuration"
:settings-page/custom-theme "Custom theme" :settings-page/custom-theme "Custom theme"
:settings-page/export-theme "Export theme" :settings-page/export-theme "Export theme"
:settings-page/show-brackets "Show brackets" :settings-page/show-brackets "Show brackets"

View File

@ -595,8 +595,10 @@
(state/set-state! :plugin/indicator-text "LOADING") (state/set-state! :plugin/indicator-text "LOADING")
(-> (p/let [root (get-ls-dotdir-root) (->
_ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root})) (p/let [root (get-ls-dotdir-root)
_ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root}))
_ (state/set-state! :config/root-dir root)
clear-commands! (fn [pid] clear-commands! (fn [pid]
;; commands ;; commands

View File

@ -38,10 +38,10 @@
%) files)] %) files)]
(if-let [file (:file/file ignore-file)] (if-let [file (:file/file ignore-file)]
(p/let [content (.text file)] (p/let [content (.text file)]
(when content (when content
(let [paths (set (common-handler/ignore-files content (map :file/path files)))] (let [paths (set (common-handler/ignore-files content (map :file/path files)))]
(when (seq paths) (when (seq paths)
(filter (fn [f] (contains? paths (:file/path f))) files))))) (filter (fn [f] (contains? paths (:file/path f))) files)))))
(p/resolved files)) (p/resolved files))
(p/resolved files)))) (p/resolved files))))
@ -331,13 +331,27 @@
(p/let [handle (when-not electron? (idb/get-item handle-path))] (p/let [handle (when-not electron? (idb/get-item handle-path))]
(when (or handle electron? mobile-native?) ; electron doesn't store the file handle (when (or handle electron? mobile-native?) ; electron doesn't store the file handle
(p/let [_ (when handle (nfs/verify-permission repo handle true)) (p/let [_ (when handle (nfs/verify-permission repo handle true))
files-result (fs/get-files (if nfs? handle local-files-result
(config/get-local-dir repo)) (fs/get-files (if nfs? handle
(fn [path handle] (config/get-local-dir repo))
(when nfs? (fn [path handle]
(swap! path-handles assoc path handle)))) (when nfs?
new-files (-> (->db-files mobile-native? electron? dir-name files-result) (swap! path-handles assoc path handle))))
(remove-ignore-files dir-name nfs?)) global-dir (config/get-global-config-dir)
global-dir-exists? (fs/dir-exists? global-dir)
;; TODO: Handle nfs?
global-files-result (if global-dir-exists?
(fs/get-files global-dir
(fn [path handle]
(when nfs?
(swap! path-handles assoc path handle))))
[])
new-local-files (-> (->db-files mobile-native? electron? dir-name local-files-result)
(remove-ignore-files dir-name nfs?))
new-global-files (-> (->db-files mobile-native? electron? global-dir global-files-result)
(remove-ignore-files global-dir nfs?))
new-files (concat new-local-files new-global-files)
_ (when nfs? _ (when nfs?
(let [file-paths (set (map :file/path new-files))] (let [file-paths (set (map :file/path new-files))]
(swap! path-handles (fn [handles] (swap! path-handles (fn [handles]
@ -347,7 +361,7 @@
(string/replace-first path (str dir-name "/") "")))) (string/replace-first path (str dir-name "/") ""))))
(into {}))))) (into {})))))
(set-files! @path-handles))] (set-files! @path-handles))]
(handle-diffs! repo nfs? old-files new-files handle-path path-handles re-index?)))) (handle-diffs! repo nfs? old-files new-files handle-path path-handles re-index?))))
(p/catch (fn [error] (p/catch (fn [error]
(log/error :nfs/load-files-error repo) (log/error :nfs/load-files-error repo)
(log/error :exception error))) (log/error :exception error)))

View File

@ -99,6 +99,7 @@
:document/mode? document-mode? :document/mode? document-mode?
:config {} :config {}
:config/root-dir nil
:block/component-editing-mode? false :block/component-editing-mode? false
:editor/hidden-editors #{} ;; page names :editor/hidden-editors #{} ;; page names
:editor/draw-mode? false :editor/draw-mode? false
@ -317,6 +318,10 @@
(when-not (mobile-util/native-platform?) (when-not (mobile-util/native-platform?)
"local"))) "local")))
(defn get-root-dir
[]
(:config/root-dir @state))
(def default-config (def default-config
"Default config for a repo-specific, user config" "Default config for a repo-specific, user config"
{:feature/enable-search-remove-accents? true {:feature/enable-search-remove-accents? true