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

pull/6489/head
Peng Xiao 2022-08-26 19:36:48 +08:00
commit aba435b9a0
10 changed files with 100 additions and 9 deletions

View File

@ -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) => {

View File

@ -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()
}
}

View File

@ -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)
}
}
/**

File diff suppressed because one or more lines are too long

View File

@ -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))

View File

@ -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!

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)]