From f5a9ea2c2d09c6d994ab04121e89ee0708c3fcdc Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 4 Mar 2024 05:36:17 +0300 Subject: [PATCH] fix: ignore autoUpdate interval in manual update check --- src/background/utils/update.js | 15 ++++++++------- src/common/index.js | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/background/utils/update.js b/src/background/utils/update.js index dd91cd43ca..62912492eb 100644 --- a/src/background/utils/update.js +++ b/src/background/utils/update.js @@ -20,16 +20,17 @@ hookOptions(changes => 'autoUpdate' in changes && autoUpdate()); addOwnCommands({ /** - * @param {number | number[]} [id] - when omitted, all scripts are checked + * @param {number | number[] | 'auto'} [id] - when omitted, all scripts are checked * @return {Promise} number of updated scripts */ async CheckUpdate(id) { - const isAuto = !id; - const scripts = isAuto ? getScripts() : ensureArray(id).map(getScriptById).filter(Boolean); + const isAuto = id === AUTO; + const isAll = isAuto || !id; + const scripts = isAll ? getScripts() : ensureArray(id).map(getScriptById).filter(Boolean); const urlOpts = { all: true, - auto: isAuto, - enabledOnly: isAuto && getOption('updateEnabledScriptsOnly'), + allowedOnly: isAll, + enabledOnly: isAll && getOption('updateEnabledScriptsOnly'), }; const jobs = scripts.map(script => { const curId = script.props.id; @@ -51,7 +52,7 @@ addOwnCommands({ notes.map(n => n.script.props.id), ); } - if (isAuto) setOption('lastUpdate', Date.now()); + if (isAll) setOption('lastUpdate', Date.now()); return results.reduce((num, r) => num + (r === true), 0); }, }); @@ -147,7 +148,7 @@ function autoUpdate() { let elapsed = Date.now() - getOption('lastUpdate'); if (elapsed >= interval) { // Wait on startup for things to settle and after unsuspend for network reconnection - setTimeout(commands.CheckUpdate, 20e3); + setTimeout(commands.CheckUpdate, 20e3, AUTO); elapsed = 0; } clearTimeout(autoUpdate.timer); diff --git a/src/common/index.js b/src/common/index.js index 4b76abefa6..779294fbaa 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -212,12 +212,12 @@ export function getScriptPrettyUrl(script, displayName) { * @param {VMScript} script * @param {Object} [opts] * @param {boolean} [opts.all] - to return all two urls [checkUrl, downloadUrl] - * @param {boolean} [opts.auto] - auto-update mode: check shouldUpdate + * @param {boolean} [opts.allowedOnly] - check shouldUpdate * @param {boolean} [opts.enabledOnly] * @return {string[] | string} */ -export function getScriptUpdateUrl(script, { all, auto, enabledOnly } = {}) { - if ((!auto || script.config.shouldUpdate) +export function getScriptUpdateUrl(script, { all, allowedOnly, enabledOnly } = {}) { + if ((!allowedOnly || script.config.shouldUpdate) && (!enabledOnly || script.config.enabled)) { const { custom, meta } = script; /* URL in meta may be set to an invalid value to enforce disabling of the automatic updates