|
@@ -7,21 +7,30 @@ This component depends on TODO"
|
|
[borkdude.rewrite-edn :as rewrite]
|
|
[borkdude.rewrite-edn :as rewrite]
|
|
[frontend.fs :as fs]
|
|
[frontend.fs :as fs]
|
|
[frontend.state :as state]
|
|
[frontend.state :as state]
|
|
|
|
+ [frontend.handler.notification :as notification]
|
|
[electron.ipc :as ipc]
|
|
[electron.ipc :as ipc]
|
|
[clojure.edn :as edn]
|
|
[clojure.edn :as edn]
|
|
[clojure.set :as set]
|
|
[clojure.set :as set]
|
|
- [clojure.pprint :as pprint]))
|
|
|
|
|
|
+ [clojure.pprint :as pprint]
|
|
|
|
+ [malli.core :as m]
|
|
|
|
+ [malli.error :as me]
|
|
|
|
+ [frontend.schema.handler.plugin-config :as plugin-config-schema]
|
|
|
|
+ [lambdaisland.glogi :as log]))
|
|
|
|
|
|
(defn- plugin-config-path
|
|
(defn- plugin-config-path
|
|
[]
|
|
[]
|
|
(path/join @global-config-handler/root-dir "plugins.edn"))
|
|
(path/join @global-config-handler/root-dir "plugins.edn"))
|
|
|
|
|
|
|
|
+(def common-plugin-keys
|
|
|
|
+ "Vec of plugin keys to store in plugins.edn and to compare with installed-plugins state"
|
|
|
|
+ (->> plugin-config-schema/Plugins-edn last rest (mapv first)))
|
|
|
|
+
|
|
(defn add-or-update-plugin
|
|
(defn add-or-update-plugin
|
|
[{:keys [id] :as plugin}]
|
|
[{:keys [id] :as plugin}]
|
|
(p/let [content (fs/read-file "" (plugin-config-path))
|
|
(p/let [content (fs/read-file "" (plugin-config-path))
|
|
updated-content (-> content
|
|
updated-content (-> content
|
|
rewrite/parse-string
|
|
rewrite/parse-string
|
|
- (rewrite/assoc (keyword id) (dissoc plugin :id))
|
|
|
|
|
|
+ (rewrite/assoc (keyword id) (select-keys plugin common-plugin-keys))
|
|
str)]
|
|
str)]
|
|
;; fs protocols require repo and dir when they aren't necessary. For this component,
|
|
;; fs protocols require repo and dir when they aren't necessary. For this component,
|
|
;; neither is needed so these are nil and blank respectively
|
|
;; neither is needed so these are nil and blank respectively
|
|
@@ -36,9 +45,9 @@ This component depends on TODO"
|
|
(defn- create-plugin-config-file-if-not-exists
|
|
(defn- create-plugin-config-file-if-not-exists
|
|
[]
|
|
[]
|
|
(let [content (-> (:plugin/installed-plugins @state/state)
|
|
(let [content (-> (:plugin/installed-plugins @state/state)
|
|
- (update-vals #(select-keys % [:name :version :repo]))
|
|
|
|
- pprint/pprint
|
|
|
|
- with-out-str)]
|
|
|
|
|
|
+ (update-vals #(select-keys % common-plugin-keys))
|
|
|
|
+ pprint/pprint
|
|
|
|
+ with-out-str)]
|
|
(fs/create-if-not-exists nil @global-config-handler/root-dir (plugin-config-path) content)))
|
|
(fs/create-if-not-exists nil @global-config-handler/root-dir (plugin-config-path) content)))
|
|
|
|
|
|
(defn- determine-plugins-to-change
|
|
(defn- determine-plugins-to-change
|
|
@@ -47,7 +56,7 @@ returns map of plugins to install and uninstall"
|
|
[installed-plugins edn-plugins]
|
|
[installed-plugins edn-plugins]
|
|
(let [installed-plugins-set (->> installed-plugins
|
|
(let [installed-plugins-set (->> installed-plugins
|
|
vals
|
|
vals
|
|
- (map #(assoc (select-keys % [:name :version :repo])
|
|
|
|
|
|
+ (map #(assoc (select-keys % common-plugin-keys)
|
|
:id (keyword (:id %))))
|
|
:id (keyword (:id %))))
|
|
set)
|
|
set)
|
|
edn-plugins-set (->> edn-plugins
|
|
edn-plugins-set (->> edn-plugins
|
|
@@ -57,16 +66,28 @@ returns map of plugins to install and uninstall"
|
|
{}
|
|
{}
|
|
{:install (mapv #(assoc % :plugin-action "install")
|
|
{:install (mapv #(assoc % :plugin-action "install")
|
|
(set/difference edn-plugins-set installed-plugins-set))
|
|
(set/difference edn-plugins-set installed-plugins-set))
|
|
- :uninstall (set/difference installed-plugins-set edn-plugins-set)})))
|
|
|
|
|
|
+ :uninstall (vec (set/difference installed-plugins-set edn-plugins-set))})))
|
|
|
|
|
|
(defn open-sync-modal
|
|
(defn open-sync-modal
|
|
[]
|
|
[]
|
|
(state/pub-event! [:go/plugins])
|
|
(state/pub-event! [:go/plugins])
|
|
- (p/let [edn-plugins (fs/read-file "" (plugin-config-path))
|
|
|
|
- plugins-to-change (determine-plugins-to-change
|
|
|
|
- (:plugin/installed-plugins @state/state)
|
|
|
|
- (edn/read-string edn-plugins))]
|
|
|
|
- (state/pub-event! [:go/plugins-from-file plugins-to-change])))
|
|
|
|
|
|
+ (p/catch
|
|
|
|
+ (p/let [edn-plugins* (fs/read-file "" (plugin-config-path))
|
|
|
|
+ edn-plugins (edn/read-string edn-plugins*)]
|
|
|
|
+ (if-let [errors (->> edn-plugins (m/explain plugin-config-schema/Plugins-edn) me/humanize)]
|
|
|
|
+ (do
|
|
|
|
+ (notification/show! "Invalid plugins.edn provided. See javascript console for specific errors"
|
|
|
|
+ :error)
|
|
|
|
+ (log/error :plugin-edn-errors errors))
|
|
|
|
+ (let [plugins-to-change (determine-plugins-to-change
|
|
|
|
+ (:plugin/installed-plugins @state/state)
|
|
|
|
+ edn-plugins)]
|
|
|
|
+ (state/pub-event! [:go/plugins-from-file plugins-to-change]))))
|
|
|
|
+ (fn [e]
|
|
|
|
+ (if (= :reader-exception (:type (ex-data e)))
|
|
|
|
+ (notification/show! "Malformed plugins.edn provided. Please check the file has correct edn syntax."
|
|
|
|
+ :error)
|
|
|
|
+ (log/error :unexpected-error e)))))
|
|
|
|
|
|
;; TODO: Extract from handler.plugin
|
|
;; TODO: Extract from handler.plugin
|
|
(defn installed?
|
|
(defn installed?
|
|
@@ -89,8 +110,10 @@ returns map of plugins to install and uninstall"
|
|
|
|
|
|
(defn update-plugins
|
|
(defn update-plugins
|
|
[plugins]
|
|
[plugins]
|
|
|
|
+ (log/info :uninstall-plugins (:uninstall plugins))
|
|
(doseq [plugin (:uninstall plugins)]
|
|
(doseq [plugin (:uninstall plugins)]
|
|
(js/LSPluginCore.unregister (name (:id plugin))))
|
|
(js/LSPluginCore.unregister (name (:id plugin))))
|
|
|
|
+ (log/info :install-plugins (:install plugins))
|
|
(doseq [plugin (:install plugins)]
|
|
(doseq [plugin (:install plugins)]
|
|
(install-marketplace-plugin plugin)))
|
|
(install-marketplace-plugin plugin)))
|
|
|
|
|