Skip to content

Commit

Permalink
fix: ignore autoUpdate interval in manual update check
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Mar 4, 2024
1 parent cf1374f commit f5a9ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/background/utils/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>} 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;
Expand All @@ -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);
},
});
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5a9ea2

Please sign in to comment.