Explorar o código

Merge remote-tracking branch 'upstream/master' into whiteboards

Peng Xiao %!s(int64=3) %!d(string=hai) anos
pai
achega
aba435b9a0

+ 3 - 2
libs/src/LSPlugin.caller.ts

@@ -72,7 +72,7 @@ class LSPluginCaller extends EventEmitter {
     let syncGCTimer: any = 0
     let syncTag = 0
     const syncActors = new Map<number, DeferredActor>()
-    const readyDeferred = deferred(1000 * 5)
+    const readyDeferred = deferred(1000 * 60)
 
     const model: any = this._extendUserModel({
       [LSPMSG_READY]: async (baseInfo) => {
@@ -266,7 +266,8 @@ class LSPluginCaller extends EventEmitter {
     return new Promise((resolve, reject) => {
       timer = setTimeout(() => {
         reject(new Error(`handshake Timeout`))
-      }, 8 * 1000) // 8 secs
+        pt.destroy()
+      }, 4 * 1000) // 4 secs
 
       handshake
         .then((refChild: ParentAPI) => {

+ 25 - 3
libs/src/LSPlugin.core.ts

@@ -1128,6 +1128,7 @@ class LSPluginCore
     | 'registered'
     | 'error'
     | 'unregistered'
+    | 'ready'
     | 'themes-changed'
     | 'theme-selected'
     | 'reset-custom-theme'
@@ -1261,7 +1262,26 @@ class LSPluginCore
 
       await this.loadUserPreferences()
 
-      const externals = new Set(this._userPreferences.externals)
+      let externals = new Set(this._userPreferences.externals)
+
+      // valid externals
+      if (externals?.size) {
+        try {
+          const validatedExternals: Record<string, boolean> = await invokeHostExportedApi(
+            'validate_external_plugins', [...externals]
+          )
+
+          externals = new Set([...Object.entries(validatedExternals)].reduce(
+            (a, [k, v]) => {
+              if (v) {
+                a.push(k)
+              }
+              return a
+            }, []))
+        } catch (e) {
+          console.error('[validatedExternals Error]', e)
+        }
+      }
 
       if (initial) {
         plugins = plugins.concat(
@@ -1287,10 +1307,12 @@ class LSPluginCore
         )
 
         const perfInfo = { o: pluginLocal, s: performance.now(), e: 0 }
-        perfTable.set(pluginLocal.id, perfInfo)
+        perfTable.set(url, perfInfo)
 
         await pluginLocal.load({ indicator: readyIndicator })
 
+        perfInfo.e = performance.now()
+
         const { loadErr } = pluginLocal
 
         if (loadErr) {
@@ -1307,7 +1329,6 @@ class LSPluginCore
           }
         }
 
-        perfInfo.e = performance.now()
 
         pluginLocal.settings?.on('change', (a) => {
           this.emit('settings-changed', pluginLocal.id, a)
@@ -1331,6 +1352,7 @@ class LSPluginCore
       console.error(e)
     } finally {
       this._isRegistering = false
+      this.emit('ready', perfTable)
       debugPerfInfo()
     }
   }

+ 8 - 0
libs/src/postmate/index.ts

@@ -374,6 +374,14 @@ export class Postmate {
       this.frame.src = url
     })
   }
+
+
+  destroy() {
+    if (process.env.NODE_ENV !== 'production') {
+      log('Postmate: Destroying Postmate instance')
+    }
+    this.frame.parentNode.removeChild(this.frame)
+  }
 }
 
 /**

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
resources/js/lsplugin.core.js


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

@@ -305,6 +305,13 @@
 (defmethod handle :getUserDefaultPlugins []
   (utils/get-ls-default-plugins))
 
+(defmethod handle :validateUserExternalPlugins [_win [_ urls]]
+  (zipmap urls (for [url urls]
+                 (try
+                   (and (fs-extra/pathExistsSync url)
+                        (fs-extra/pathExistsSync (path/join url "package.json")))
+                   (catch js/Error _e false)))))
+
 (defmethod handle :relaunchApp []
   (.relaunch app) (.quit app))
 

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

@@ -996,6 +996,33 @@
    [current-repo db-restoring? nfs-granted?])
   nil)
 
+(rum/defc perf-tip-content
+  [pid name url]
+  [:div
+   [:span.block.whitespace-normal
+    "This plugin "
+    [:strong.text-red-500 "#" name]
+    " takes too long to load, affecting the application startup time and
+     potentially causing other plugins to fail to load."]
+
+   [:path.opacity-50
+    [:small [:span.pr-1 (ui/icon "folder")] url]]
+
+   [:p
+    (ui/button "Disable now"
+               :small? true
+               :on-click
+               (fn []
+                 (-> (js/LSPluginCore.disable pid)
+                     (p/then #(do
+                                (notification/clear! pid)
+                                (notification/show!
+                                 [:span "The plugin "
+                                  [:strong.text-red-500 "#" name]
+                                  " is disabled."] :success
+                                 true nil 3000)))
+                     (p/catch #(js/console.error %)))))]])
+
 (defn open-plugins-modal!
   []
   (state/set-modal!

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

@@ -439,6 +439,12 @@
     (plugin-handler/hook-plugin-db :changed payload)
     (plugin-handler/hook-plugin-block-changes payload)))
 
+(defmethod handle :plugin/loader-perf-tip [[_ {:keys [^js o _s _e]}]]
+  (when-let [opts (.-options o)]
+    (notification/show!
+     (plugin/perf-tip-content (.-id o) (.-name opts) (.-url opts))
+     :warning false (.-id o))))
+
 (defmethod handle :backup/broken-config [[_ repo content]]
   (when (and repo content)
     (let [path (config/get-config-path)

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

@@ -585,7 +585,7 @@
         [:small.scale-250.opacity-70.mb-10.animate-pulse (svg/logo false)]
         [:small.block.text-sm.relative.opacity-50 {:style {:right "-8px"}} text]]])))
 
-(defn init-plugins!
+(defn ^:large-vars/cleanup-todo init-plugins!
   [callback]
 
   (let [el (js/document.createElement "div")]
@@ -665,7 +665,24 @@
                                                           (let [id (keyword id)]
                                                             (when (and settings
                                                                        (contains? (:plugin/installed-plugins @state/state) id))
-                                                              (update-plugin-settings-state id (bean/->clj settings)))))))
+                                                              (update-plugin-settings-state id (bean/->clj settings))))))
+
+                                (.on "ready" (fn [^js perf-table]
+                                               (when-let [plugins (and perf-table (.entries perf-table))]
+                                                 (->> plugins
+                                                      (keep
+                                                       (fn [[_k ^js v]]
+                                                         (when-let [end (and (some-> v (.-o) (.-disabled) (not))
+                                                                             (.-e v))]
+                                                           (when (and (number? end)
+                                                                      ;; valid end time
+                                                                      (> end 0)
+                                                                      ;; greater than 3s
+                                                                      (> (- end (.-s v)) 3000))
+                                                             v))))
+                                                      ((fn [perfs]
+                                                         (doseq [perf perfs]
+                                                           (state/pub-event! [:plugin/loader-perf-tip (bean/->clj perf)])))))))))
 
               default-plugins (get-user-default-plugins)
 

+ 1 - 1
src/main/frontend/ui.cljs

@@ -231,7 +231,7 @@
                   "exiting" "transition ease-in duration-100 opacity-100"
                   "exited" "transition ease-in duration-100 opacity-0")}
         [:div.rounded-lg.shadow-xs {:style {:max-height "calc(100vh - 200px)"
-                                            :overflow-y "scroll"
+                                            :overflow-y "auto"
                                             :overflow-x "hidden"}}
          [:div.p-4
           [:div.flex.items-start

+ 3 - 0
src/main/logseq/api.cljs

@@ -711,6 +711,9 @@
         (insert_block src content (bean/->js opts))))))
 
 ;; plugins
+(defn ^:export validate_external_plugins [urls]
+  (ipc/ipc :validateUserExternalPlugins urls))
+
 (def ^:export __install_plugin
   (fn [^js manifest]
     (when-let [{:keys [repo id] :as mft} (bean/->clj manifest)]

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio