Browse Source

enhance(ux): test url for proxy settings

charlie 3 years ago
parent
commit
da4d507bcc

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

@@ -314,6 +314,10 @@
 (defmethod handle :getLogseqDotDirRoot []
 (defmethod handle :getLogseqDotDirRoot []
   (utils/get-ls-dotdir-root))
   (utils/get-ls-dotdir-root))
 
 
+(defmethod handle :testProxyUrl [win [_ url]]
+  (p/let [_ (utils/fetch url)]
+    (utils/send-to-renderer win :notification {:type "success" :payload (str "Successfully: " url)})))
+
 (defmethod handle :getUserDefaultPlugins []
 (defmethod handle :getUserDefaultPlugins []
   (utils/get-ls-default-plugins))
   (utils/get-ls-default-plugins))
 
 

+ 1 - 1
src/electron/electron/utils.cljs

@@ -118,7 +118,7 @@
   ([window kind payload]
   ([window kind payload]
    (when window
    (when window
      (.. ^js window -webContents
      (.. ^js window -webContents
-         (send kind (bean/->js payload))))))
+         (send (name kind) (bean/->js payload))))))
 
 
 (defn get-graph-dir
 (defn get-graph-dir
   [graph-name]
   [graph-name]

+ 28 - 4
src/main/frontend/components/plugins.cljs

@@ -338,6 +338,8 @@
 (rum/defc user-proxy-settings-panel
 (rum/defc user-proxy-settings-panel
   [{:keys [protocol] :as agent-opts}]
   [{:keys [protocol] :as agent-opts}]
   (let [[opts set-opts!] (rum/use-state agent-opts)
   (let [[opts set-opts!] (rum/use-state agent-opts)
+        [testing? set-testing?!] (rum/use-state false)
+        *test-input (rum/create-ref)
         disabled? (string/blank? (:protocol opts))]
         disabled? (string/blank? (:protocol opts))]
     [:div.cp__settings-network-proxy-panel
     [:div.cp__settings-network-proxy-panel
      [:h1.mb-2.text-2xl.font-bold (t :settings-page/network-proxy)]
      [:h1.mb-2.text-2xl.font-bold (t :settings-page/network-proxy)]
@@ -362,12 +364,34 @@
           :on-change #(set-opts!
           :on-change #(set-opts!
                         (assoc opts :port (util/trim-safe (util/evalue %))))}]]]
                         (assoc opts :port (util/trim-safe (util/evalue %))))}]]]
 
 
+      [:hr]
+      [:p.flex.items-center.space-x-2
+       [:span.w-60
+        [:input.form-input.is-small
+         {:ref *test-input
+          :placeholder "http://"
+          :on-change #(set-opts!
+                        (assoc opts :test (util/trim-safe (util/evalue %))))
+          :value (:test opts)}]]
+
+       (ui/button (if testing? (ui/loading "Testing") "Test URL")
+         :intent "logseq" :large? false
+         :style {:margin-top 0 :padding "5px 15px"}
+         :on-click #(let [val (util/trim-safe (.-value (rum/deref *test-input)))]
+                      (when (and (not testing?) (not (string/blank? val)))
+                        (set-testing?! true)
+                        (-> (p/let [_ (ipc/ipc :setHttpsAgent opts)
+                                    _ (ipc/ipc :testProxyUrl val)])
+                          (p/catch (fn [e] (notification/show! (str e) :error)))
+                          (p/finally (fn [] (set-testing?! false)))))
+                      ))]
+
       [:p.pt-2
       [:p.pt-2
        (ui/button (t :save)
        (ui/button (t :save)
-                  :on-click (fn []
-                              (p/let [_ (ipc/ipc :setHttpsAgent opts)]
-                                     (state/set-state! [:electron/user-cfgs :settings/agent] opts)
-                                     (state/close-sub-modal! :https-proxy-panel))))]]]))
+         :on-click (fn []
+                     (p/let [_ (ipc/ipc :setHttpsAgent opts)]
+                       (state/set-state! [:electron/user-cfgs :settings/agent] opts)
+                       (state/close-sub-modal! :https-proxy-panel))))]]]))
 
 
 (rum/defc ^:large-vars/cleanup-todo panel-control-tabs < rum/static
 (rum/defc ^:large-vars/cleanup-todo panel-control-tabs < rum/static
   [search-key *search-key category *category
   [search-key *search-key category *category

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

@@ -270,7 +270,6 @@
     (state/close-sub-modal! "ls-focused-settings-modal")))
     (state/close-sub-modal! "ls-focused-settings-modal")))
 
 
 (defmethod handle :go/proxy-settings [[_ agent-opts]]
 (defmethod handle :go/proxy-settings [[_ agent-opts]]
-  (js/console.log agent-opts)
   (state/set-sub-modal!
   (state/set-sub-modal!
     (fn [_] (plugin/user-proxy-settings-panel agent-opts))
     (fn [_] (plugin/user-proxy-settings-panel agent-opts))
     {:id :https-proxy-panel :center? true}))
     {:id :https-proxy-panel :center? true}))