Pārlūkot izejas kodu

Can access read global config file from UI

Only for reload case
Gabriel Horner 3 gadi atpakaļ
vecāks
revīzija
9c0bb02dcd

+ 10 - 0
src/main/frontend/components/settings.cljs

@@ -144,6 +144,14 @@
      :on-click     #(js/setTimeout (fn [] (ui-handler/toggle-settings-modal!)))
      :-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 []
   (row-with-button-action
     {:left-label   (t :settings-page/custom-theme)
@@ -538,6 +546,8 @@
      (version-row t version)
      (language-row t preferred-language)
      (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-custom-css))
      (when current-repo (edit-export-css))

+ 10 - 1
src/main/frontend/config.cljs

@@ -6,7 +6,8 @@
             [frontend.util :as util]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.util :as gp-util]
-            [shadow.resource :as rc]))
+            [shadow.resource :as rc]
+            ["path" :as path]))
 
 (goog-define DEV-RELEASE false)
 (defonce dev-release? DEV-RELEASE)
@@ -375,6 +376,14 @@
    (when repo
      (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
   ([]
    (get-metadata-path (state/get-current-repo)))

+ 2 - 0
src/main/frontend/dicts.cljc

@@ -152,9 +152,11 @@
         :settings-page/git-switcher-label "Enable Git auto commit"
         :settings-page/git-commit-delay "Git auto commit seconds"
         :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-export-css "Edit export.css"
         :settings-page/custom-configuration "Custom configuration"
+        :settings-page/custom-global-configuration "Custom global configuration"
         :settings-page/custom-theme "Custom theme"
         :settings-page/export-theme "Export theme"
         :settings-page/show-brackets "Show brackets"

+ 4 - 2
src/main/frontend/handler/plugin.cljs

@@ -595,8 +595,10 @@
 
   (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]
                                 ;; commands

+ 26 - 12
src/main/frontend/handler/web/nfs.cljs

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

+ 5 - 0
src/main/frontend/state.cljs

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