in case of new warnings, refresh updates info immediately
Massimo Melina committed
Apr 5, 2026 at 16:35 UTC
62eb82b955381ce8d7f9550718009783a81cada9
3 files changed
+22
-11
src/commands.ts
+2
-2
@@ -3,7 +3,7 @@
3
import { createAdmin, getAccount, updateAccount } from './perm'
4
import { configKeyExists, setConfig, getWholeConfig, showHelp } from './config'
5
import _ from 'lodash'
6
-import { getUpdates, update } from './update'
6
+import { getBestUpdate, update } from './update'
7
import { openAdmin } from './listen'
8
import yaml from 'yaml'
9
import { BUILD_TIMESTAMP, VERSION } from './const'
@@ -154,7 +154,7 @@ const commands = {
154
'check-update': {
155
params: '',
156
async cb() {
157
- const update = (await getUpdates(true))[0]
157
+ const update = await getBestUpdate()
158
if (!update)
159
throw "you already have the latest version: " + VERSION
160
console.log("new version available", update.name)
src/github.ts
+6
-2
@@ -23,6 +23,7 @@ import { storedMap } from './persistence'
23
import { argv } from './argv'
24
import { expiringCache } from './expiringCache'
25
import { configReady } from './config'
26
+import { checkForUpdates } from './update'
27
28
const DIST_ROOT = 'dist'
29
@@ -288,10 +289,13 @@ export const getProjectInfo = debounceAsync(async () => {
289
Object.assign(obj, more)
290
}
291
_.remove(newAlerts, x => !x)
291
- if (!_.isEqual(alerts, newAlerts))
292
+ if (!_.isEqual(alerts, newAlerts)) {
293
+ alerts = newAlerts
294
+ if (newAlerts.length)
295
+ void checkForUpdates() // with new alerts, is best to have fresh updates info
296
for (const a of newAlerts)
297
console.log("ALERT:", a)
294
- alerts = newAlerts
298
+ }
299
const black = onlyTruthy(Object.keys(obj.repo_blacklist || {}).map(findPluginByRepo))
300
blacklistedInstalledPlugins = onlyTruthy(black.map(x => _.isString(x.repo) && x.repo))
301
if (black.length) {
src/update.ts
+14
-7
@@ -4,7 +4,7 @@ import { apiGithubPaginated, getProjectInfo, getRepoInfo } from './github'
4
import { ARGS_FILE, HFS_REPO, IS_BINARY, IS_WINDOWS, PREVIOUS_TAG, RUNNING_BETA } from './const'
5
import { dirname, join } from 'path'
6
import { spawn, spawnSync } from 'child_process'
7
-import { DAY, exists, unzip, prefix, xlate, HOUR, httpWithBody, statWithTimeout, repeat } from './misc'
7
+import { DAY, exists, unzip, prefix, xlate, HOUR, httpWithBody, statWithTimeout, repeat, debounceAsync } from './misc'
8
import { createReadStream, existsSync, renameSync, unlinkSync, writeFileSync } from 'fs'
9
import { pluginsWatcher } from './plugins'
10
import { chmod, rename, writeFile, rm } from 'fs/promises'
@@ -29,18 +29,25 @@ autoCheckUpdateResult.ready().then(() => {
29
return v
30
})
31
})
32
-configReady.then(lastCheckUpdate.ready).then(() => repeat(HOUR, async () => {
33
- if (!autoCheckUpdate.get()) return
34
- if (Date.now() < lastCheckUpdate.get() + AUTO_CHECK_EVERY) return
32
+configReady.then(lastCheckUpdate.ready).then(() => repeat(HOUR, () => {
33
+ if (autoCheckUpdate.get() && Date.now() > lastCheckUpdate.get() + AUTO_CHECK_EVERY)
34
+ return checkForUpdates()
35
+}))
36
+
37
+export const checkForUpdates = debounceAsync(async () => {
38
console.log("checking for updates")
39
try {
37
- const u = (await getUpdates(true))[0]
40
+ const u = await getBestUpdate()
41
if (u) console.log("new version available", u.name)
42
autoCheckUpdateResult.set(u)
43
lastCheckUpdate.set(Date.now())
44
}
45
catch {}
43
-}))
46
+}, { reuseRunning: true })
47
+
48
+export async function getBestUpdate() {
49
+ return (await getUpdates(true))[0]
50
+}
51
52
export type Release = { // not using interface, as it will not work with kvstorage.Jsonable
53
prerelease: boolean,
@@ -116,7 +123,7 @@ export async function update(tagOrUrl: string='') {
123
else if (tagOrUrl ? !url : !await localUpdateAvailable()) {
124
if (/^\d/.test(tagOrUrl)) // work even if the tag is passed without the initial 'v' (useful for console commands)
125
tagOrUrl = 'v' + tagOrUrl
119
- const update = !tagOrUrl ? (await getUpdates(true))[0]
126
+ const update = !tagOrUrl ? await getBestUpdate()
127
: await getRepoInfo(HFS_REPO + '/releases/tags/' + tagOrUrl).catch(e => {
128
if (e.message === '404') console.error("version not found")
129
else throw e