Przeglądaj źródła

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 lat temu
rodzic
commit
2685cd1325

+ 1 - 1
bb.edn

@@ -4,7 +4,7 @@
   {:git/url "https://github.com/babashka/spec.alpha"
    :sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
   metosin/malli
-  {:mvn/version "0.8.9"}
+  {:mvn/version "0.9.1"}
   logseq/bb-tasks
   #_{:local/root "../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"}
   ;; TODO: bump to mvn/version when released
   borkdude/rewrite-edn                  {:git/url "https://github.com/borkdude/rewrite-edn"
-                                         :sha "80f246139b1a43b6f2cbab329521d060ee7c1b7b"}
+                                         :sha     "80f246139b1a43b6f2cbab329521d060ee7c1b7b"}
   funcool/promesa                       {:mvn/version "4.0.2"}
   medley/medley                         {:mvn/version "1.4.0"}
   metosin/reitit-frontend               {:mvn/version "0.3.10"}
@@ -31,7 +31,7 @@
   instaparse/instaparse                 {:mvn/version "1.4.10"}
   org.clojars.mmb90/cljs-cache          {:mvn/version "0.1.4"}
   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/"]
                   :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
 
-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
 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]))
 
 (defn validate-plugins-edn
+  "Validate a plugins.edn file"
   [file]
   (if-let [errors (->> file
                        slurp

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

@@ -76,8 +76,8 @@
                        {:response-transform
                         (fn [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
                             (let [repo' (some-> repo (string/trim) (string/replace #"^/+(.+?)/+$" "$1"))
                                   api #(str "https://api.github.com/repos/" repo' "/" %)]
@@ -158,8 +158,12 @@
       (emit :lsp-installed {:status :error :payload e})
       (throw e))))
 
-;; repo is a github repo, not a logseq repo
 (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}]
   (if repo
     (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)]
                  :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?)
                  [{:hr true}
@@ -804,11 +804,10 @@
   < rum/reactive
   [plugins]
   [: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)
      [: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
       [:ul
        (for [it (:install plugins)
@@ -817,16 +816,16 @@
           {:key k}
           [:label.flex-1
            {:for k}
-           [:strong.px-3 (str (:name it) " " (:version it))]]])]
+           [:strong.px-3 (str (name (:id it)) " " (:version it))]]])]
 
       ;; actions
       [:div.pt-5
-       (ui/button [:span "Install"]
+       (ui/button [:span (t :plugin/install)]
                   :on-click #(do
                                (plugin-config-handler/replace-plugins plugins)
                                (state/close-sub-modal! "ls-plugins-from-file-modal")))]]
      ;; 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!

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

@@ -366,7 +366,7 @@
         :plugin/title "Title"
         :plugin/all "All"
         :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-package "Open package"
         :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/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/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-text "Copy text"

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

@@ -1,7 +1,8 @@
 (ns frontend.handler.plugin-config
   "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 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]
             ["path" :as path]
             [promesa.core :as p]
@@ -20,6 +21,7 @@
             [lambdaisland.glogi :as log]))
 
 (defn plugin-config-path
+  "Full path to 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,
 returns map of plugins to install and uninstall"
   [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
                                    vals
                                    (map #(-> (select-keys % common-plugin-keys)
-                                             (assoc :id (keyword (:id %)))
-                                             (dissoc :name)))
+                                             (assoc :id (keyword (:id %)))))
                                    set)
         edn-plugins-set (->> edn-plugins
-                             (map (fn [[k v]] (-> v
-                                                  (assoc :id k)
-                                                  (dissoc :name))))
+                             (map (fn [[k v]] (assoc v :id k)))
                              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))
        :uninstall (vec (set/difference installed-plugins-set edn-plugins-set))})))
 
-(defn open-sync-modal
+(defn open-replace-plugins-modal
   []
   (state/pub-event! [:go/plugins])
   (p/catch
@@ -106,7 +103,9 @@ returns map of plugins to install and uninstall"
     (plugin-common-handler/unregister-plugin (name (:id plugin))))
   (log/info :install-plugins (: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!
   "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]
                    (when-let [{:keys [status payload only-check]} (bean/->clj e)]
                      (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
                           (assoc payload
                                  :version (:installed-version payload)
+                                 :effect (boolean effect)
                                  ;; Manual install doesn't have theme field but
                                  ;; plugin.edn requires this field
-                                 :theme (if (some? theme) theme false)
-                                 :name name))))))]
+                                 :theme (boolean theme)))))))]
     (js/window.apis.addListener "lsp-installed" listener)))
 
 (defn start

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

@@ -412,8 +412,7 @@
 
    :ui/install-plugins-from-file    {:binding false
                                      :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"
                                      :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
 ; for existing config files
 (def Plugin
+  ":repo and :version determine the correct plugin to install. :theme and
+  :effect are needed for the install process to work correctly"
   [:map
-   [:name
-    [:and {:gen/fmap '(partial str "Name ")}
-     string?]]
    [:version
     [:and
      {:gen/fmap '(fn [_] (apply str (interpose "." (repeatedly 3 (fn [] (rand-int 10))))))}
@@ -15,6 +14,7 @@
    [:repo
     [:and {:gen/fmap '(partial str "github-user/")}
      string?]]
+   [:effect boolean?]
    [:theme boolean?]])
 
 (def Plugins-edn

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

@@ -32,7 +32,7 @@
 
 (deftest-async add-or-update-plugin
   (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}))]
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) body)
 
@@ -61,7 +61,7 @@
 
      (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)
         error-message (atom nil)]
     (fs-node/writeFileSync (plugin-config-handler/plugin-config-path) "{:id {}")
@@ -70,12 +70,12 @@
       [notification/show! (fn [msg _] (reset! error-message msg))]
       (->
        (p/do!
-        (plugin-config-handler/open-sync-modal)
+        (plugin-config-handler/open-replace-plugins-modal)
         (is (string/starts-with? @error-message "Malformed plugins.edn")
             "User sees correct notification"))
        (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)
         error-message (atom nil)]
     ;; Missing a couple plugin keys
@@ -86,7 +86,7 @@
       [notification/show! (fn [msg _] (reset! error-message msg))]
       (->
        (p/do!
-        (plugin-config-handler/open-sync-modal)
+        (plugin-config-handler/open-replace-plugins-modal)
         (is (string/starts-with? @error-message "Invalid plugins.edn")
             "User sees correct notification"))
        (p/finally #(delete-global-config-dir dir))))))