فهرست منبع

improve(plugin): fetch marketplace plugins list via system proxy if no proxy configured. (#5716)

Charlie 3 سال پیش
والد
کامیت
7c4d7cd61a
3فایلهای تغییر یافته به همراه26 افزوده شده و 16 حذف شده
  1. 7 8
      src/main/frontend/components/plugins.cljs
  2. 14 8
      src/main/frontend/handler/plugin.cljs
  3. 5 0
      src/main/frontend/state.cljs

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

@@ -440,14 +440,13 @@
 
      [:div.flex.items-center.r
       ;; extra info
-      (let [{:keys [protocol host port]} agent-opts]
-        (when (every? not-empty [protocol host port])
-          (ui/button
-           [:span.flex.items-center.text-indigo-500
-            (ui/icon "world-download") (str protocol "://" host ":" port)]
-           :small? true
-           :intent "link"
-           :on-click #(state/pub-event! [:go/proxy-settings agent-opts]))))
+      (when-let [proxy-val (state/http-proxy-enabled-or-val?)]
+        (ui/button
+         [:span.flex.items-center.text-indigo-500
+          (ui/icon "world-download") proxy-val]
+         :small? true
+         :intent "link"
+         :on-click #(state/pub-event! [:go/proxy-settings agent-opts])))
 
       ;; search
       (panel-tab-search search-key *search-key *search-ref)

+ 14 - 8
src/main/frontend/handler/plugin.cljs

@@ -73,14 +73,17 @@
   (if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
     (p/create
       (fn [resolve reject]
-        (-> (ipc/ipc :httpFetchJSON plugins-url)
-            (p/then (fn [res]
+        (let [on-ok (fn [res]
                       (if-let [res (and res (bean/->clj res))]
                         (let [pkgs (:packages res)]
                           (state/set-state! :plugin/marketplace-pkgs pkgs)
                           (resolve pkgs))
-                        (reject nil))))
-            (p/catch reject))))
+                        (reject nil)))]
+          (if (state/http-proxy-enabled-or-val?)
+            (-> (ipc/ipc :httpFetchJSON plugins-url)
+                (p/then on-ok)
+                (p/catch reject))
+            (util/fetch plugins-url on-ok reject)))))
     (p/resolved (:plugin/marketplace-pkgs @state/state))))
 
 (defn load-marketplace-stats
@@ -88,8 +91,7 @@
   (if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
     (p/create
       (fn [resolve reject]
-        (-> (ipc/ipc :httpFetchJSON stats-url)
-            (p/then (fn [^js res]
+        (let [on-ok (fn [^js res]
                       (if-let [res (and res (bean/->clj res))]
                         (do
                           (state/set-state!
@@ -100,8 +102,12 @@
                                                      (reduce (fn [a b] (+ a (get b 2))) 0 (:releases stat)))])
                                          res)))
                           (resolve nil))
-                        (reject nil))))
-            (p/catch reject))))
+                        (reject nil)))]
+          (if (state/http-proxy-enabled-or-val?)
+            (-> (ipc/ipc :httpFetchJSON stats-url)
+                (p/then on-ok)
+                (p/catch reject))
+            (util/fetch stats-url on-ok reject)))))
     (p/resolved nil)))
 
 (defn installed?

+ 5 - 0
src/main/frontend/state.cljs

@@ -1690,6 +1690,11 @@
                  (if (fn? m) m
                    (fn [old-value] (merge old-value m)))))
 
+(defn http-proxy-enabled-or-val? []
+  (when-let [agent-opts (sub [:electron/user-cfgs :settings/agent])]
+    (when (every? not-empty (vals agent-opts))
+      (str (:protocol agent-opts) "://" (:host agent-opts) ":" (:port agent-opts)))))
+
 (defn enable-encryption?
   [repo]
   (:feature/enable-encryption?