|
@@ -34,21 +34,24 @@
|
|
|
|
|
|
(defn- create-global-config-file-if-not-exists
|
|
|
[repo-url]
|
|
|
- (let [config-dir (global-config-dir)
|
|
|
+ (when (not-empty @root-dir)
|
|
|
+ (let [config-dir (global-config-dir)
|
|
|
config-path (global-config-path)]
|
|
|
(p/let [_ (fs/mkdir-if-not-exists config-dir)
|
|
|
file-exists? (fs/create-if-not-exists repo-url config-dir config-path default-content)]
|
|
|
(when-not file-exists?
|
|
|
(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!
|
|
|
"Sets global config state from config file"
|
|
|
[]
|
|
|
- (let [config-dir (global-config-dir)
|
|
|
- config-path (global-config-path)]
|
|
|
- (p/let [config-content (fs/read-file config-dir config-path)]
|
|
|
- (set-global-config-state! config-content))))
|
|
|
+ (if (not-empty @root-dir)
|
|
|
+ (let [config-dir (global-config-dir)
|
|
|
+ config-path (global-config-path)]
|
|
|
+ (p/let [config-content (fs/read-file config-dir config-path)]
|
|
|
+ (set-global-config-state! config-content)))
|
|
|
+ (set-global-config-state! default-content)))
|
|
|
|
|
|
(defn start
|
|
|
"This component has four responsibilities on start:
|
|
@@ -58,8 +61,12 @@
|
|
|
- Start a file watcher for global config dir if it's not already started.
|
|
|
Watcher ensures client db is seeded with correct file data."
|
|
|
[{:keys [repo]}]
|
|
|
- (p/let [root-dir' (ipc/ipc "getLogseqDotDirRoot")
|
|
|
- _ (reset! root-dir root-dir')
|
|
|
- _ (restore-global-config!)
|
|
|
- _ (create-global-config-file-if-not-exists repo)
|
|
|
- _ (fs/watch-dir! (global-config-dir) {:global-dir true})]))
|
|
|
+ (-> (p/do!
|
|
|
+ (p/let [root-dir' (ipc/ipc "getLogseqDotDirRoot")]
|
|
|
+ (reset! root-dir root-dir'))
|
|
|
+ (restore-global-config!)
|
|
|
+ (create-global-config-file-if-not-exists repo)
|
|
|
+ (fs/watch-dir! (global-config-dir) {:global-dir true}))
|
|
|
+ (p/timeout 6000)
|
|
|
+ (p/catch (fn [e]
|
|
|
+ (js/console.error "cannot start global-config" e)))))
|