Просмотр исходного кода

enhance(plugin): change marketplace metadata requests to node fetch client

charlie 3 лет назад
Родитель
Сommit
de9ab5ed44

+ 5 - 0
src/electron/electron/handler.cljs

@@ -295,6 +295,11 @@
   (p/let [_ (utils/fetch url)]
     (utils/send-to-renderer win :notification {:type "success" :payload (str "Successfully: " url)})))
 
+(defmethod handle :httpFetchJSON [_win [_ url options]]
+  (p/let [res (utils/fetch url options)
+          json (.json res)]
+         json))
+
 (defmethod handle :getUserDefaultPlugins []
   (utils/get-ls-default-plugins))
 

+ 0 - 1
src/main/frontend/components/plugins.cljs

@@ -372,7 +372,6 @@
       [:p [:label [:strong (t :type)]
            (ui/select [{:label "Disabled" :value "" :selected disabled?}
                        {:label "http" :value "http" :selected (= protocol "http")}
-                       {:label "https" :value "https" :selected (= protocol "https")}
                        {:label "socks5" :value "socks5" :selected (= protocol "socks5")}]
                       #(set-opts!
                          (assoc opts :protocol (if (= "disabled" (util/safe-lower-case %)) nil %))) nil)]]

+ 22 - 19
src/main/frontend/handler/plugin.cljs

@@ -55,12 +55,13 @@
   (if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
     (p/create
       (fn [resolve reject]
-        (-> (util/fetch plugins-url
-                        (fn [res]
-                          (let [pkgs (:packages res)]
-                            (state/set-state! :plugin/marketplace-pkgs pkgs)
-                            (resolve pkgs)))
-                        reject)
+        (-> (ipc/ipc :httpFetchJSON plugins-url)
+            (p/then (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))))
     (p/resolved (:plugin/marketplace-pkgs @state/state))))
 
@@ -69,18 +70,20 @@
   (if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
     (p/create
       (fn [resolve reject]
-        (util/fetch stats-url
-                    (fn [res]
-                      (when res
-                        (state/set-state!
-                          :plugin/marketplace-stats
-                          (into {} (map (fn [[k stat]]
-                                          [k (assoc stat
-                                               :total_downloads
-                                               (reduce (fn [a b] (+ a (get b 2))) 0 (:releases stat)))])
-                                        res)))
-                        (resolve nil)))
-                    reject)))
+        (-> (ipc/ipc :httpFetchJSON stats-url)
+            (p/then (fn [^js res]
+                      (if-let [res (and res (bean/->clj res))]
+                        (do
+                          (state/set-state!
+                           :plugin/marketplace-stats
+                           (into {} (map (fn [[k stat]]
+                                           [k (assoc stat
+                                                     :total_downloads
+                                                     (reduce (fn [a b] (+ a (get b 2))) 0 (:releases stat)))])
+                                         res)))
+                          (resolve nil))
+                        (reject nil))))
+            (p/catch reject))))
     (p/resolved nil)))
 
 (defn installed?
@@ -605,7 +608,7 @@
                                             (state/set-custom-theme! mode theme)
                                             (state/set-theme-mode! mode))
                                           (state/set-state! :plugin/selected-theme url))))
-                                        
+
                 (.on "reset-custom-theme" (fn [^js themes]
                                             (let [themes (bean/->clj themes)
                                                   custom-theme (dissoc themes :mode)