Browse Source

enhance(plugin): load plugin from web url for debug

charlie 1 year ago
parent
commit
c1f93683a1

+ 44 - 13
src/main/frontend/components/plugins.cljs

@@ -404,14 +404,14 @@
    :intent "link"
    :target "_blank"))
 
-(rum/defc user-proxy-settings-panel
+(rum/defc user-proxy-settings-container
   [{:keys [protocol type] :as agent-opts}]
   (let [type        (or (not-empty type) (not-empty protocol) "system")
         [opts set-opts!] (rum/use-state agent-opts)
         [testing? set-testing?!] (rum/use-state false)
         *test-input (rum/create-ref)
         disabled?   (or (= (:type opts) "system") (= (:type opts) "direct"))]
-    [:div.cp__settings-network-proxy-panel
+    [:div.cp__settings-network-proxy-cnt
      [:h1.mb-2.text-2xl.font-bold (t :settings-page/network-proxy)]
      [:div.p-2
       [:p [:label [:strong (t :type)]
@@ -478,6 +478,33 @@
                               (p/let [_ (ipc/ipc :setProxy opts)]
                                 (state/set-state! [:electron/user-cfgs :settings/agent] opts))))]]]))
 
+(rum/defc load-from-web-url-container
+  []
+  (let [[url set-url!] (rum/use-state "")
+        [pending? set-pending?] (rum/use-state false)
+        handle-submit! (fn []
+                         (set-pending? true)
+                         (-> (p/delay 3000)
+                           (p/finally
+                             #(set-pending? false))))]
+
+    [:div.px-4.pt-4.pb-2.rounded-md.flex.flex-col.gap-2
+     [:div.flex.flex-col.gap-3
+      (shui/input {:placeholder "http://"
+                   :value url
+                   :on-change #(set-url! (-> (util/evalue %) (util/trim-safe)))
+                   :auto-focus true})
+      [:span.text-gray-10
+       (shui/tabler-icon "info-circle" {:size 13})
+       [:span "URLs support both GitHub repositories and local development servers.
+      (For examples: https://github.com/xyhp915/logseq-journals-calendar,
+      http://localhost:8080/<plugin-dir-root>)"]]
+      ]
+     [:div.flex.justify-end
+      (shui/button {:disabled (or pending? (string/blank? url))
+                    :on-click handle-submit!}
+        (if pending? (ui/loading) "Save"))]]))
+
 (rum/defc auto-check-for-updates-control
   []
   (let [[enabled, set-enabled!] (rum/use-state (plugin-handler/get-enabled-auto-check-for-updates?))
@@ -614,17 +641,21 @@
 
                           [{:hr true}]
 
-                          (when (and (state/developer-mode?)
-                                     (util/electron?))
-                            [{:title [:span.flex.items-center.gap-1 (ui/icon "file-code") (t :plugin/open-preferences)]
-                              :options {:on-click
-                                        #(p/let [root (plugin-handler/get-ls-dotdir-root)]
-                                           (js/apis.openPath (str root "/preferences.json")))}}
-                             {:title [:span.flex.items-center.whitespace-nowrap.gap-1
-                                      (ui/icon "bug") (t :plugin/open-logseq-dir) [:code "~/.logseq"]]
-                              :options {:on-click
-                                        #(p/let [root (plugin-handler/get-ls-dotdir-root)]
-                                           (js/apis.openPath root))}}])
+                          (when (state/developer-mode?)
+                            (if (util/electron?)
+                              [{:title [:span.flex.items-center.gap-1 (ui/icon "file-code") (t :plugin/open-preferences)]
+                                :options {:on-click
+                                          #(p/let [root (plugin-handler/get-ls-dotdir-root)]
+                                             (js/apis.openPath (str root "/preferences.json")))}}
+                               {:title [:span.flex.items-center.whitespace-nowrap.gap-1
+                                        (ui/icon "bug") (t :plugin/open-logseq-dir) [:code "~/.logseq"]]
+                                :options {:on-click
+                                          #(p/let [root (plugin-handler/get-ls-dotdir-root)]
+                                             (js/apis.openPath root))}}]
+                              [{:title [:span.flex.items-center.whitespace-nowrap.gap-1
+                                        (ui/icon "plug") (t :plugin/load-from-web-url)]
+                                :options {:on-click
+                                          #(shui/dialog-open! load-from-web-url-container)}}]))
 
                           [{:title [:span.flex.items-center.gap-1 (ui/icon "alert-triangle") (t :plugin/report-security)]
                             :options {:on-click #(plugin-handler/open-report-modal!)}}]

+ 1 - 1
src/main/frontend/components/settings.css

@@ -203,7 +203,7 @@
     }
   }
 
-  &-network-proxy-panel {
+  &-network-proxy-cnt {
     margin: -15px 0;
 
     label {

+ 1 - 1
src/main/frontend/handler/events.cljs

@@ -420,7 +420,7 @@
 
 (defmethod handle :go/proxy-settings [[_ agent-opts]]
   (shui/dialog-open!
-   (plugin/user-proxy-settings-panel agent-opts)
+   (plugin/user-proxy-settings-container agent-opts)
    {:id :https-proxy-panel :center? true :class "lg:max-w-2xl"}))
 
 (defmethod handle :redirect-to-home [_]

+ 1 - 0
src/resources/dicts/en.edn

@@ -552,6 +552,7 @@
  :plugin/checking-for-updates "Checking for plugin updates ..."
  :plugin/list-of-updates "Plugin Updates: "
  :plugin/auto-check-for-updates "Auto check for updates"
+ :plugin/load-from-web-url "Load plugin from web url"
  :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:"

+ 1 - 0
src/resources/dicts/zh-cn.edn

@@ -289,6 +289,7 @@
  :plugin/checking-for-updates "正在检查插件更新 ..."
  :plugin/list-of-updates "可用的插件更新: "
  :plugin/auto-check-for-updates "是否自动检查更新"
+ :plugin/load-from-web-url "通过URL载入插件"
  :plugin.install-from-file/menu-title "从 plugins.edn 安装"
  :plugin.install-from-file/title "从 plugins.edn 配置中安装插件"
  :plugin.install-from-file/notice "以下插件会替换已安装的插件:"