enhance(plugin): auto updates for web plugins

This commit is contained in:
charlie
2025-01-08 13:15:26 +08:00
parent 1110e81741
commit d0cd4c2e1e
5 changed files with 23 additions and 19 deletions

View File

@@ -1112,6 +1112,7 @@ class PluginLocal extends EventEmitter<
json.err = this.loadErr
json.usf = this.dotSettingsFile
json.iir = this.isInstalledInLocalDotRoot
json.webMode = this.isWebPlugin ? (this.installedFromUserWebUrl ? 'user' : 'github') : false
json.lsr = this._resolveResourceFullUrl('/')
if (settings === false) {

View File

@@ -1367,10 +1367,12 @@
(not (number? last-updates))
;; interval 12 hours
(> (- (js/Date.now) last-updates) (* 60 60 12 1000))))
(js/setTimeout
(fn []
(plugin-handler/auto-check-enabled-for-updates!)
(storage/set :lsp-last-auto-updates (js/Date.now))))))))
(let [update-timer (js/setTimeout
(fn []
(plugin-handler/auto-check-enabled-for-updates!)
(storage/set :lsp-last-auto-updates (js/Date.now)))
(if (util/electron?) 3000 (* 60 1000) ))]
#(js/clearTimeout update-timer))))))
[online?])
[:<>]))

View File

@@ -37,30 +37,31 @@
(defn async-install-or-update-for-web!
[{: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))
(js/console.log "debug:plugin:" (if only-check "Checking" "Installing") " #" repo)
(let [version (if (not only-check) (:latest-version manifest) version)]
(-> (fetch-web-plugin-entry-info repo (if only-check "" version))
(p/then (fn [web-pkg]
(let [web-pkg (merge web-pkg (dissoc manifest :stat))
(let [web-pkg (merge web-pkg (dissoc manifest :stat :version :only-check))
latest-version (:version web-pkg)
valid-latest-version (when only-check
(let [coerced-current-version (.coerce util/sem-ver version)
coerced-latest-version (.coerce util/sem-ver latest-version)]
(if (and coerced-current-version
coerced-latest-version
(util/sem-ver.lt coerced-current-version coerced-latest-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 valid-latest-version :latest-notes "TODO: update notes")
(assoc manifest :dst repo :version latest-version :web-pkg web-pkg))}))))
{:status :completed
:only-check only-check
:payload (if only-check
(assoc manifest :latest-version valid-latest-version :latest-notes (some-> web-pkg :_objectExtra :releaseNotes))
(assoc manifest :dst repo :version latest-version :web-pkg web-pkg))}))))
(p/catch (fn [^js e]
(emit-lsp-updates!
{:status :error
:only-check only-check
:payload (assoc manifest :error-code (.-message e))})))))
{:status :error
:only-check only-check
:payload (assoc manifest :error-code (.-message e))}))))))
(defn install-marketplace-plugin!
"Installs plugin given plugin map with id"

View File

@@ -785,7 +785,7 @@
(some-> github-repo
(plugin-common-handler/get-web-plugin-checker-url!))
(str url "/package.json"))
^js res (js/window.fetch package-url)
^js res (js/window.fetch (str package-url "?v=" (js/Date.now)))
package (if (and (.-ok res)
(= (.-status res) 200))
(-> (.json res)

View File

@@ -2035,7 +2035,7 @@ Similar to re-frame subscriptions"
([theme?] (get-enabled?-installed-plugins theme? true false false))
([theme? enabled? include-unpacked? include-all?]
(filterv
#(and (if include-unpacked? true (:iir %))
#(and (if include-unpacked? true (or (:webMode %) (:iir %)))
(if-not (boolean? enabled?) true (= (not enabled?) (boolean (get-in % [:settings :disabled]))))
(or include-all? (if (boolean? theme?) (= (boolean theme?) (:theme %)) true)))
(vals (:plugin/installed-plugins @state)))))