enhance(plugin): check updates for the web plugins

This commit is contained in:
charlie
2024-12-30 18:15:24 +08:00
parent 208ca930eb
commit 109e91bd35
7 changed files with 46 additions and 24 deletions

View File

@@ -520,7 +520,7 @@ class PluginLocal extends EventEmitter<
const url = path.join(localRoot, filePath)
filePath = reg.test(url) ? url : PROTOCOL_FILE + url
}
return !this.options.effect && this.isInstalledInDotRoot
return !this.options.effect && this.isInstalledInLocalDotRoot
? convertToLSPResource(filePath, this.dotPluginsRoot)
: filePath
}
@@ -559,7 +559,7 @@ class PluginLocal extends EventEmitter<
'effect',
'sponsors',
]
.concat(!this.isInstalledInDotRoot ? ['devEntry'] : [])
.concat(!this.isInstalledInLocalDotRoot ? ['devEntry'] : [])
.forEach((k) => {
this._options[k] = pkg[k]
})
@@ -591,7 +591,7 @@ class PluginLocal extends EventEmitter<
this._options.icon = icon && this._resolveResourceFullUrl(icon)
this._options.theme = Boolean(logseq.theme || !!logseq.themes)
if (this.isInstalledInDotRoot) {
if (this.isInstalledInLocalDotRoot) {
this._id = path.basename(localRoot)
} else if (!this.isWebPlugin) {
// development mode
@@ -645,7 +645,7 @@ class PluginLocal extends EventEmitter<
let dirPathInstalled = null
let tmp_file_method = 'write_user_tmp_file'
if (this.isInstalledInDotRoot) {
if (this.isInstalledInLocalDotRoot) {
tmp_file_method = 'write_dotdir_file'
dirPathInstalled = this._localRoot.replace(this.dotPluginsRoot, '')
dirPathInstalled = path.join(DIR_PLUGINS, dirPathInstalled)
@@ -928,7 +928,7 @@ class PluginLocal extends EventEmitter<
if (unregister) {
await this.unload()
if (this.isWebPlugin || this.isInstalledInDotRoot) {
if (this.isWebPlugin || this.isInstalledInLocalDotRoot) {
this._ctx.emit('unlink-plugin', this.id)
}
@@ -999,7 +999,7 @@ class PluginLocal extends EventEmitter<
return window.frontend.modules.layout.core
}
get isInstalledInDotRoot() {
get isInstalledInLocalDotRoot() {
if (this.isWebPlugin) return false
const dotRoot = this.dotConfigRoot
const plgRoot = this.localRoot
@@ -1103,7 +1103,7 @@ class PluginLocal extends EventEmitter<
json.id = this.id
json.err = this.loadErr
json.usf = this.dotSettingsFile
json.iir = this.isInstalledInDotRoot
json.iir = this.isInstalledInLocalDotRoot
json.lsr = this._resolveResourceFullUrl('/')
if (settings === false) {
@@ -1349,7 +1349,7 @@ class LSPluginCore
this.emit('registered', pluginLocal)
// external plugins
if (!pluginLocal.isWebPlugin && !pluginLocal.isInstalledInDotRoot) {
if (!pluginLocal.isWebPlugin && !pluginLocal.isInstalledInLocalDotRoot) {
externals.add(url)
}
}
@@ -1394,7 +1394,7 @@ class LSPluginCore
for (const identity of plugins) {
const p = this.ensurePlugin(identity)
if (!p.isWebPlugin && !p.isInstalledInDotRoot) {
if (!p.isWebPlugin && !p.isInstalledInLocalDotRoot) {
unregisteredExternals.push(p.options.url)
}

View File

@@ -20,6 +20,7 @@
"gulp-replace": "^1.1.4",
"gulp-postcss": "^10.0.0",
"ip": "1.1.9",
"semver": "7.5.2",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-cljs-test": "^0.1.0",

View File

@@ -516,7 +516,8 @@
:class "load-unpacked"
:on-click plugin-handler/load-unpacked-plugin}))
(unpacked-plugin-loader selected-unpacked-pkg)])]
(when (util/electron?)
(unpacked-plugin-loader selected-unpacked-pkg))])]
[:div.flex.items-center.r
;; extra info

View File

@@ -28,8 +28,7 @@
(defn installed?
"For the given plugin id, returns boolean indicating if it is installed"
[id]
(and (contains? (:plugin/installed-plugins @state/state) (keyword id))
(get-in @state/state [:plugin/installed-plugins (keyword id) :iir])))
(contains? (:plugin/installed-plugins @state/state) (keyword id)))
(defn emit-lsp-updates!
[payload]
@@ -37,17 +36,26 @@
(js/window.apis.emit (name :lsp-updates) (bean/->js payload)))
(defn async-install-or-update-for-web!
[{:keys [version repo only-check _plugin-action] :as manifest}]
(js/console.log "debug:install-or-update" manifest)
(-> (fetch-web-plugin-entry-info repo version)
(p/then (fn [{:keys [_version] :as web-pkg}]
(let [web-pkg (merge web-pkg (dissoc manifest :stat))]
[{:keys [version repo only-check] :as manifest}]
(js/console.log "[plugin]" (if only-check "Checking" "Installing") " #" repo)
(-> (fetch-web-plugin-entry-info repo (if only-check "" version))
(p/then (fn [web-pkg]
(let [web-pkg (merge web-pkg (dissoc manifest :stat))
latest-version (:version web-pkg)
valid-latest-version (when only-check
(let [coerced-current-version (util/sem-ver.coerce version)
coerced-latest-version (util/sem-ver.coerce latest-version)]
(if (and coerced-current-version
coerced-latest-version
(util/sem-ver.lt coerced-current-version coerced-latest-version))
latest-version
(throw (js/Error. :no-new-version)))))]
(emit-lsp-updates!
{:status :completed
:only-check only-check
:payload (if only-check
(assoc manifest :latest-version version :latest-notes "TODO: update notes")
(assoc manifest :dst repo :installed-version version :web-pkg web-pkg))}))))
{:status :completed
:only-check only-check
:payload (if only-check
(assoc manifest :latest-version valid-latest-version :latest-notes "TODO: update notes")
(assoc manifest :dst repo :installed-version version :web-pkg web-pkg))}))))
(p/catch (fn [^js e]
(emit-lsp-updates!
{:status :error

View File

@@ -144,9 +144,12 @@
(-> (load-marketplace-plugins false)
(p/then (fn [manifests]
(let [mft (some #(when (= (:id %) id) %) manifests)]
(let [mft (some #(when (= (:id %) id) %) manifests)
opts (merge (dissoc pkg :logger) mft)]
;;TODO: (throw (js/Error. [:not-found-in-marketplace id]))
(ipc/ipc :updateMarketPlugin (merge (dissoc pkg :logger) mft)))
(if (util/electron?)
(ipc/ipc :updateMarketPlugin opts)
(plugin-common-handler/async-install-or-update-for-web! opts)))
true))
(p/catch (fn [^js e]
(state/reset-all-updates-state)

View File

@@ -11,6 +11,7 @@
["sanitize-filename" :as sanitizeFilename]
["check-password-strength" :refer [passwordStrength]]
["path-complete-extname" :as pathCompleteExtname]
["semver" :as semver]
[frontend.loader :refer [load]]
[cljs-bean.core :as bean]
[cljs-time.coerce :as tc]
@@ -50,6 +51,7 @@
(-namespace [_] nil)))
#?(:cljs (defonce ^js node-path utils/nodePath))
#?(:cljs (defonce ^js sem-ver semver))
#?(:cljs (defonce ^js full-path-extname pathCompleteExtname))
#?(:cljs (defn app-scroll-container-node
([]

View File

@@ -7499,6 +7499,13 @@ semver-greatest-satisfied-range@^1.1.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==
semver@7.5.2:
version "7.5.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.2.tgz#5b851e66d1be07c1cdaf37dfc856f543325a2beb"
integrity sha512-SoftuTROv/cRjCze/scjGyiDtcUyxw1rgYQSZY7XTmtR5hX+dm76iDbTH8TkLPHCQmlbQVSSbNZCPM2hb0knnQ==
dependencies:
lru-cache "^6.0.0"
semver@^6.0.0, semver@^6.2.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"