浏览代码

Fix bug with certain plugins and misc cleanup

- Plugins that used effects weren't loading correctly e.g.
  logseq-power-plugin
- Cleaned up translation, docs and some fn naming
Gabriel Horner 3 年之前
父节点
当前提交
2685cd1325

+ 1 - 1
bb.edn

@@ -4,7 +4,7 @@
   {:git/url "https://github.com/babashka/spec.alpha"
   {:git/url "https://github.com/babashka/spec.alpha"
    :sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
    :sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
   metosin/malli
   metosin/malli
-  {:mvn/version "0.8.9"}
+  {:mvn/version "0.9.1"}
   logseq/bb-tasks
   logseq/bb-tasks
   #_{:local/root "../bb-tasks"}
   #_{:local/root "../bb-tasks"}
   {:git/url "https://github.com/logseq/bb-tasks"
   {:git/url "https://github.com/logseq/bb-tasks"

+ 2 - 2
deps.edn

@@ -6,7 +6,7 @@
   datascript-transit/datascript-transit {:mvn/version "0.3.0"}
   datascript-transit/datascript-transit {:mvn/version "0.3.0"}
   ;; TODO: bump to mvn/version when released
   ;; TODO: bump to mvn/version when released
   borkdude/rewrite-edn                  {:git/url "https://github.com/borkdude/rewrite-edn"
   borkdude/rewrite-edn                  {:git/url "https://github.com/borkdude/rewrite-edn"
-                                         :sha "80f246139b1a43b6f2cbab329521d060ee7c1b7b"}
+                                         :sha     "80f246139b1a43b6f2cbab329521d060ee7c1b7b"}
   funcool/promesa                       {:mvn/version "4.0.2"}
   funcool/promesa                       {:mvn/version "4.0.2"}
   medley/medley                         {:mvn/version "1.4.0"}
   medley/medley                         {:mvn/version "1.4.0"}
   metosin/reitit-frontend               {:mvn/version "0.3.10"}
   metosin/reitit-frontend               {:mvn/version "0.3.10"}
@@ -31,7 +31,7 @@
   instaparse/instaparse                 {:mvn/version "1.4.10"}
   instaparse/instaparse                 {:mvn/version "1.4.10"}
   org.clojars.mmb90/cljs-cache          {:mvn/version "0.1.4"}
   org.clojars.mmb90/cljs-cache          {:mvn/version "0.1.4"}
   logseq/graph-parser                   {:local/root "deps/graph-parser"}
   logseq/graph-parser                   {:local/root "deps/graph-parser"}
-  metosin/malli                         {:mvn/version "0.8.9"}}
+  metosin/malli                         {:mvn/version "0.9.1"}}
 
 
  :aliases {:cljs {:extra-paths ["src/dev-cljs/" "src/test/" "src/electron/"]
  :aliases {:cljs {:extra-paths ["src/dev-cljs/" "src/test/" "src/electron/"]
                   :extra-deps  {org.clojure/clojurescript        {:mvn/version "1.11.54"}
                   :extra-deps  {org.clojure/clojurescript        {:mvn/version "1.11.54"}

+ 4 - 2
docs/dev-practices.md

@@ -165,8 +165,10 @@ aren't readable.
 
 
 ## Data validation and generation
 ## Data validation and generation
 
 
-We use both [spec](https://github.com/clojure/spec.alpha) and [malli](https://github.com/metosin/malli) for data validation and (and generation someday). malli has the advantage that its schema
-is data and can be used for additional purposes. See plugin-config for an example.
+We use both [spec](https://github.com/clojure/spec.alpha) and
+[malli](https://github.com/metosin/malli) for data validation and (and
+generation someday). malli has the advantage that its schema is data and can be
+used for additional purposes. See plugin-config for an example.
 
 
 Specs should go under `src/main/frontend/spec/` and be compatible with clojure
 Specs should go under `src/main/frontend/spec/` and be compatible with clojure
 and clojurescript. See `frontend.spec.storage` for an example.
 and clojurescript. See `frontend.spec.storage` for an example.

+ 1 - 0
scripts/src/logseq/tasks/malli.clj

@@ -7,6 +7,7 @@
             [clojure.edn :as edn]))
             [clojure.edn :as edn]))
 
 
 (defn validate-plugins-edn
 (defn validate-plugins-edn
+  "Validate a plugins.edn file"
   [file]
   [file]
   (if-let [errors (->> file
   (if-let [errors (->> file
                        slurp
                        slurp

+ 7 - 3
src/electron/electron/plugin.cljs

@@ -76,8 +76,8 @@
                        {:response-transform
                        {:response-transform
                         (fn [res]
                         (fn [res]
                           (if (= 404 (.-status res))
                           (if (= 404 (.-status res))
-                            ;; Fall back to fetching the latest For these rare
-                            ;; cases, previous logseq versions did not store the
+                            ;; Fall back to fetching the latest for these rare
+                            ;; cases. Previous logseq versions did not store the
                             ;; plugin's git tag required to correctly install it
                             ;; plugin's git tag required to correctly install it
                             (let [repo' (some-> repo (string/trim) (string/replace #"^/+(.+?)/+$" "$1"))
                             (let [repo' (some-> repo (string/trim) (string/replace #"^/+(.+?)/+$" "$1"))
                                   api #(str "https://api.github.com/repos/" repo' "/" %)]
                                   api #(str "https://api.github.com/repos/" repo' "/" %)]
@@ -158,8 +158,12 @@
       (emit :lsp-installed {:status :error :payload e})
       (emit :lsp-installed {:status :error :payload e})
       (throw e))))
       (throw e))))
 
 
-;; repo is a github repo, not a logseq repo
 (defn install-or-update!
 (defn install-or-update!
+  "Default behavior is to install the latest version of a given repo. Item map
+  includes the following keys:
+* :only-check - When set to true, this only fetches the latest version without installing
+* :plugin-action - When set to 'install', installs the specific :version given
+* :repo - A github repo, not a logseq repo, e.g. user/repo"
   [{:keys [version repo only-check plugin-action] :as item}]
   [{:keys [version repo only-check plugin-action] :as item}]
   (if repo
   (if repo
     (let [coerced-version (and version (. semver coerce version))
     (let [coerced-version (and version (. semver coerce version))

+ 7 - 8
src/main/frontend/components/plugins.cljs

@@ -548,8 +548,8 @@
                [{:title   [:span.flex.items-center (ui/icon "world") (t :settings-page/network-proxy)]
                [{:title   [:span.flex.items-center (ui/icon "world") (t :settings-page/network-proxy)]
                  :options {:on-click #(state/pub-event! [:go/proxy-settings agent-opts])}}]
                  :options {:on-click #(state/pub-event! [:go/proxy-settings agent-opts])}}]
 
 
-               [{:title   [:span.flex.items-center (ui/icon "arrow-down-circle") (t :plugin/install-from-file)]
-                 :options {:on-click plugin-config-handler/open-sync-modal}}]
+               [{:title   [:span.flex.items-center (ui/icon "arrow-down-circle") (t :plugin.install-from-file/menu-title)]
+                 :options {:on-click plugin-config-handler/open-replace-plugins-modal}}]
 
 
                (when (state/developer-mode?)
                (when (state/developer-mode?)
                  [{:hr true}
                  [{:hr true}
@@ -804,11 +804,10 @@
   < rum/reactive
   < rum/reactive
   [plugins]
   [plugins]
   [:div.cp__plugins-fom-file
   [:div.cp__plugins-fom-file
-   [:h1.mb-4.text-2xl.p-1 "Install plugins from plugins.edn"]
+   [:h1.mb-4.text-2xl.p-1 (t :plugin.install-from-file/title)]
    (if (seq plugins)
    (if (seq plugins)
      [:div
      [:div
-      [:div.mb-2.text-xl (util/format "The following %s plugin(s) will replace your plugins:"
-                                      (count (:install plugins)))]
+      [:div.mb-2.text-xl (t :plugin.install-from-file/notice)]
       ;; lists
       ;; lists
       [:ul
       [:ul
        (for [it (:install plugins)
        (for [it (:install plugins)
@@ -817,16 +816,16 @@
           {:key k}
           {:key k}
           [:label.flex-1
           [:label.flex-1
            {:for k}
            {:for k}
-           [:strong.px-3 (str (:name it) " " (:version it))]]])]
+           [:strong.px-3 (str (name (:id it)) " " (:version it))]]])]
 
 
       ;; actions
       ;; actions
       [:div.pt-5
       [:div.pt-5
-       (ui/button [:span "Install"]
+       (ui/button [:span (t :plugin/install)]
                   :on-click #(do
                   :on-click #(do
                                (plugin-config-handler/replace-plugins plugins)
                                (plugin-config-handler/replace-plugins plugins)
                                (state/close-sub-modal! "ls-plugins-from-file-modal")))]]
                                (state/close-sub-modal! "ls-plugins-from-file-modal")))]]
      ;; all done
      ;; all done
-     [:div.py-4 [:strong.text-xl "\uD83C\uDF89 All synced!"]])])
+     [:div.py-4 [:strong.text-xl (str "\uD83C\uDF89 " (t :plugin.install-from-file/success))]])])
 
 
 
 
 (defn open-select-theme!
 (defn open-select-theme!

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

@@ -366,7 +366,7 @@
         :plugin/title "Title"
         :plugin/title "Title"
         :plugin/all "All"
         :plugin/all "All"
         :plugin/unpacked "Unpacked"
         :plugin/unpacked "Unpacked"
-        :plugin/delete-alert "Are you sure uninstall plugin [{1}]?"
+        :plugin/delete-alert "Are you sure you want to uninstall the plugin [{1}]?"
         :plugin/open-settings "Open settings"
         :plugin/open-settings "Open settings"
         :plugin/open-package "Open package"
         :plugin/open-package "Open package"
         :plugin/load-unpacked "Load unpacked plugin"
         :plugin/load-unpacked "Load unpacked plugin"
@@ -377,7 +377,10 @@
         :plugin/marketplace-tips "If the plugin doesn't work correctly when first installed, try to restart Logseq."
         :plugin/marketplace-tips "If the plugin doesn't work correctly when first installed, try to restart Logseq."
         :plugin/up-to-date "It's up to date"
         :plugin/up-to-date "It's up to date"
         :plugin/custom-js-alert "Found the custom.js file, is it allowed to execute? (If you don't understand the content of this file, it is recommended not to allow execution, which has certain security risks.)"
         :plugin/custom-js-alert "Found the custom.js file, is it allowed to execute? (If you don't understand the content of this file, it is recommended not to allow execution, which has certain security risks.)"
-        :plugin/install-from-file "Install from plugins.edn"
+        :plugin.install-from-file/menu-title "Install from plugins.edn"
+        :plugin.install-from-file/title "Install plugins from plugins.edn"
+        :plugin.install-from-file/notice "The following plugins will replace your plugins:"
+        :plugin.install-from-file/success "All plugins installed!"
 
 
         :pdf/copy-ref "Copy ref"
         :pdf/copy-ref "Copy ref"
         :pdf/copy-text "Copy text"
         :pdf/copy-text "Copy text"

+ 12 - 15
src/main/frontend/handler/plugin_config.cljs

@@ -1,7 +1,8 @@
 (ns frontend.handler.plugin-config
 (ns frontend.handler.plugin-config
   "This system component encapsulates the global plugin.edn and depends on the
   "This system component encapsulates the global plugin.edn and depends on the
   global-config component. This component is only enabled? if both the
   global-config component. This component is only enabled? if both the
-  global-config and plugin components are enabled"
+  global-config and plugin components are enabled. plugin.edn is automatically updated
+when a plugin is installed, updated or removed"
   (:require [frontend.handler.global-config :as global-config-handler]
   (:require [frontend.handler.global-config :as global-config-handler]
             ["path" :as path]
             ["path" :as path]
             [promesa.core :as p]
             [promesa.core :as p]
@@ -20,6 +21,7 @@
             [lambdaisland.glogi :as log]))
             [lambdaisland.glogi :as log]))
 
 
 (defn plugin-config-path
 (defn plugin-config-path
+  "Full path to plugins.edn"
   []
   []
   (path/join (global-config-handler/global-config-dir) "plugins.edn"))
   (path/join (global-config-handler/global-config-dir) "plugins.edn"))
 
 
@@ -58,18 +60,13 @@
   "Given installed plugins state and plugins from plugins.edn,
   "Given installed plugins state and plugins from plugins.edn,
 returns map of plugins to install and uninstall"
 returns map of plugins to install and uninstall"
   [installed-plugins edn-plugins]
   [installed-plugins edn-plugins]
-  ;; :name is removed from comparison because it isn't used for reproducible builds
-  ;; and is just for display purposes
   (let [installed-plugins-set (->> installed-plugins
   (let [installed-plugins-set (->> installed-plugins
                                    vals
                                    vals
                                    (map #(-> (select-keys % common-plugin-keys)
                                    (map #(-> (select-keys % common-plugin-keys)
-                                             (assoc :id (keyword (:id %)))
-                                             (dissoc :name)))
+                                             (assoc :id (keyword (:id %)))))
                                    set)
                                    set)
         edn-plugins-set (->> edn-plugins
         edn-plugins-set (->> edn-plugins
-                             (map (fn [[k v]] (-> v
-                                                  (assoc :id k)
-                                                  (dissoc :name))))
+                             (map (fn [[k v]] (assoc v :id k)))
                              set)]
                              set)]
     (if (= installed-plugins-set edn-plugins-set)
     (if (= installed-plugins-set edn-plugins-set)
       {}
       {}
@@ -77,7 +74,7 @@ returns map of plugins to install and uninstall"
                       (set/difference edn-plugins-set installed-plugins-set))
                       (set/difference edn-plugins-set installed-plugins-set))
        :uninstall (vec (set/difference installed-plugins-set edn-plugins-set))})))
        :uninstall (vec (set/difference installed-plugins-set edn-plugins-set))})))
 
 
-(defn open-sync-modal
+(defn open-replace-plugins-modal
   []
   []
   (state/pub-event! [:go/plugins])
   (state/pub-event! [:go/plugins])
   (p/catch
   (p/catch
@@ -106,7 +103,9 @@ returns map of plugins to install and uninstall"
     (plugin-common-handler/unregister-plugin (name (:id plugin))))
     (plugin-common-handler/unregister-plugin (name (:id plugin))))
   (log/info :install-plugins (:install plugins))
   (log/info :install-plugins (:install plugins))
   (doseq [plugin (:install plugins)]
   (doseq [plugin (:install plugins)]
-    (plugin-common-handler/install-marketplace-plugin plugin)))
+    (plugin-common-handler/install-marketplace-plugin
+     ;; Add :name so that install notifications are readable
+     (assoc plugin :name (name (:id plugin))))))
 
 
 (defn setup-install-listener!
 (defn setup-install-listener!
   "Sets up a listener for the lsp-installed event to update plugins.edn"
   "Sets up a listener for the lsp-installed event to update plugins.edn"
@@ -114,16 +113,14 @@ returns map of plugins to install and uninstall"
   (let [listener (fn listener [_ e]
   (let [listener (fn listener [_ e]
                    (when-let [{:keys [status payload only-check]} (bean/->clj e)]
                    (when-let [{:keys [status payload only-check]} (bean/->clj e)]
                      (when (and (= status "completed") (not only-check))
                      (when (and (= status "completed") (not only-check))
-                       (let [{:keys [name title theme]} payload
-                             ;; Same defaults as plugin/setup-install-listener!
-                             name (or title name "Untitled")]
+                       (let [{:keys [theme effect]} payload]
                          (add-or-update-plugin
                          (add-or-update-plugin
                           (assoc payload
                           (assoc payload
                                  :version (:installed-version payload)
                                  :version (:installed-version payload)
+                                 :effect (boolean effect)
                                  ;; Manual install doesn't have theme field but
                                  ;; Manual install doesn't have theme field but
                                  ;; plugin.edn requires this field
                                  ;; plugin.edn requires this field
-                                 :theme (if (some? theme) theme false)
-                                 :name name))))))]
+                                 :theme (boolean theme)))))))]
     (js/window.apis.addListener "lsp-installed" listener)))
     (js/window.apis.addListener "lsp-installed" listener)))
 
 
 (defn start
 (defn start

+ 1 - 2
src/main/frontend/modules/shortcut/config.cljs

@@ -412,8 +412,7 @@
 
 
    :ui/install-plugins-from-file    {:binding false
    :ui/install-plugins-from-file    {:binding false
                                      :inactive (not (config/plugin-config-enabled?))
                                      :inactive (not (config/plugin-config-enabled?))
-                                     ;; TODO: Remove dev convenience
-                                     :fn      (fn [] (plugin-config-handler/open-sync-modal))}
+                                     :fn       plugin-config-handler/open-replace-plugins-modal}
 
 
    :editor/toggle-open-blocks       {:binding "t o"
    :editor/toggle-open-blocks       {:binding "t o"
                                      :fn      editor-handler/toggle-open!}
                                      :fn      editor-handler/toggle-open!}

+ 3 - 3
src/main/frontend/schema/handler/plugin_config.cljc

@@ -4,10 +4,9 @@
 ; The plugin keys should not be changed between releases without a migration plan
 ; The plugin keys should not be changed between releases without a migration plan
 ; for existing config files
 ; for existing config files
 (def Plugin
 (def Plugin
+  ":repo and :version determine the correct plugin to install. :theme and
+  :effect are needed for the install process to work correctly"
   [:map
   [:map
-   [:name
-    [:and {:gen/fmap '(partial str "Name ")}
-     string?]]
    [:version
    [:version
     [:and
     [:and
      {:gen/fmap '(fn [_] (apply str (interpose "." (repeatedly 3 (fn [] (rand-int 10))))))}
      {:gen/fmap '(fn [_] (apply str (interpose "." (repeatedly 3 (fn [] (rand-int 10))))))}
@@ -15,6 +14,7 @@
    [:repo
    [:repo
     [:and {:gen/fmap '(partial str "github-user/")}
     [:and {:gen/fmap '(partial str "github-user/")}
      string?]]
      string?]]
+   [:effect boolean?]
    [:theme boolean?]])
    [:theme boolean?]])
 
 
 (def Plugins-edn
 (def Plugins-edn

+ 5 - 5
src/test/frontend/handler/plugin_config_test.cljs

@@ -32,7 +32,7 @@
 
 
 (deftest-async add-or-update-plugin
 (deftest-async add-or-update-plugin
   (let [dir (create-global-config-dir)
   (let [dir (create-global-config-dir)
-        plugin-to-add {:id :foo :name "Foo" :repo "some-user/foo" :version "v0.9.0"}
+        plugin-to-add {:id :foo :repo "some-user/foo" :version "v0.9.0"}
         body (pr-str (mg/generate plugin-config-schema/Plugins-edn {:size 10}))]
         body (pr-str (mg/generate plugin-config-schema/Plugins-edn {:size 10}))]
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) body)
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) body)
 
 
@@ -61,7 +61,7 @@
 
 
      (p/finally #(delete-global-config-dir dir)))))
      (p/finally #(delete-global-config-dir dir)))))
 
 
-(deftest-async open-sync-modal-malformed-edn
+(deftest-async open-replace-plugins-modal-malformed-edn
   (let [dir (create-global-config-dir)
   (let [dir (create-global-config-dir)
         error-message (atom nil)]
         error-message (atom nil)]
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) "{:id {}")
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) "{:id {}")
@@ -70,12 +70,12 @@
       [notification/show! (fn [msg _] (reset! error-message msg))]
       [notification/show! (fn [msg _] (reset! error-message msg))]
       (->
       (->
        (p/do!
        (p/do!
-        (plugin-config-handler/open-sync-modal)
+        (plugin-config-handler/open-replace-plugins-modal)
         (is (string/starts-with? @error-message "Malformed plugins.edn")
         (is (string/starts-with? @error-message "Malformed plugins.edn")
             "User sees correct notification"))
             "User sees correct notification"))
        (p/finally #(delete-global-config-dir dir))))))
        (p/finally #(delete-global-config-dir dir))))))
 
 
-(deftest-async open-sync-modal-invalid-edn
+(deftest-async open-replace-plugins-modal-invalid-edn
   (let [dir (create-global-config-dir)
   (let [dir (create-global-config-dir)
         error-message (atom nil)]
         error-message (atom nil)]
     ;; Missing a couple plugin keys
     ;; Missing a couple plugin keys
@@ -86,7 +86,7 @@
       [notification/show! (fn [msg _] (reset! error-message msg))]
       [notification/show! (fn [msg _] (reset! error-message msg))]
       (->
       (->
        (p/do!
        (p/do!
-        (plugin-config-handler/open-sync-modal)
+        (plugin-config-handler/open-replace-plugins-modal)
         (is (string/starts-with? @error-message "Invalid plugins.edn")
         (is (string/starts-with? @error-message "Invalid plugins.edn")
             "User sees correct notification"))
             "User sees correct notification"))
        (p/finally #(delete-global-config-dir dir))))))
        (p/finally #(delete-global-config-dir dir))))))