admin/home: if we are running a beta, we'll be offered to switch to stable
Massimo Melina committed
Jul 19, 2023 at 14:58 UTC
d9cd0014409934428cbc2a29d445267219cdc62d
3 files changed
+30
-15
admin/src/HomePage.ts
+13
-7
@@ -13,7 +13,8 @@ import {
13
prefix,
14
REPO_URL,
15
wait,
16
- wikiLink
16
+ wikiLink,
17
+ with_
18
} from './misc'
19
import { BrowserUpdated as UpdateIcon, CheckCircle, Error, Info, Launch, Warning } from '@mui/icons-material'
20
import md from './md'
@@ -108,12 +109,17 @@ export default function HomePage() {
109
icon: UpdateIcon,
110
onClick: () => apiCall('check_update').then(x => setUpdates(x.options), alertDialog)
111
}, "Check for updates")
111
- : !updates.length ? entry('', "No update available")
112
- : !status.updatePossible ? entry('', `Version ${updates[0].name} available`)
113
- : h(Flex, { vert: true },
114
- updates.map((x: any) =>
115
- h(Btn, { icon: UpdateIcon, onClick: () => update(x.tag_name) }, prefix("Install ", x.name)) )
116
- ),
112
+ : with_(_.find(updates, 'isNewer'), newer =>
113
+ !updates.length || !status.updatePossible && !newer ? entry('', "No update available")
114
+ : newer && !status.updatePossible ? entry('', `Version ${newer.name} available`)
115
+ : h(Flex, { vert: true },
116
+ updates.map((x: any) =>
117
+ h(Btn, {
118
+ icon: UpdateIcon,
119
+ ...!x.isNewer && { color: 'warning', variant: 'outlined' },
120
+ onClick: () => update(x.tag_name)
121
+ }, prefix("Install ", x.name, x.isNewer ? '' : " (older)")))
122
+ ))
123
)
124
}
125
src/const.ts
+1
@@ -14,6 +14,7 @@ const PKG_PATH = join(__dirname, '..', 'package.json')
14
export const BUILD_TIMESTAMP = fs.statSync(PKG_PATH).mtime.toISOString()
15
const pkg = JSON.parse(fs.readFileSync(PKG_PATH,'utf8'))
16
export const VERSION = pkg.version
17
+export const RUNNING_BETA = VERSION.includes('-')
18
export const DAY = 86_400_000
19
20
export const API_VERSION = 8.3
src/update.ts
+16
-8
@@ -1,7 +1,7 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import { getRepoInfo } from './github'
4
-import { argv, HFS_REPO, IS_BINARY, IS_WINDOWS } from './const'
4
+import { argv, HFS_REPO, IS_BINARY, IS_WINDOWS, RUNNING_BETA } from './const'
5
import { basename, dirname, join } from 'path'
6
import { spawn, spawnSync } from 'child_process'
7
import { httpsStream, onProcessExit, unzip } from './misc'
@@ -14,14 +14,20 @@ import { currentVersion, defineConfig, versionToScalar } from './config'
14
15
const updateToBeta = defineConfig('update_to_beta', false)
16
17
-interface Release { prerelease: boolean, tag_name: string, name: string, assets: any[] }
17
+interface Release {
18
+ prerelease: boolean,
19
+ tag_name: string,
20
+ name: string,
21
+ assets: any[],
22
+ isNewer: boolean // introduced by us
23
+}
24
25
export async function getUpdates() {
26
const stable: Release = await getRepoInfo(HFS_REPO + '/releases/latest')
27
const verStable = ver(stable)
28
const ret = await getBetas()
23
- if (stable && currentVersion.olderThan(stable.tag_name))
24
- ret.unshift(stable)
29
+ if (stable && (currentVersion.olderThan(stable.tag_name) || RUNNING_BETA)) // if we are running a beta, also offer the latest stable
30
+ ret.push(stable)
31
return ret
32
33
function ver(x: any) {
@@ -29,7 +35,7 @@ export async function getUpdates() {
35
}
36
37
async function getBetas() {
32
- if (!updateToBeta.get() && !currentVersion.includes('-')) return [] // '-' means using beta
38
+ if (!updateToBeta.get() && !RUNNING_BETA) return []
39
let page = 1
40
const ret = []
41
while (1) {
@@ -38,10 +44,12 @@ export async function getUpdates() {
44
if (!res.length) break
45
for (const x of res) {
46
if (!x.prerelease) continue // prerelease are all the end
41
- if (ver(x) <= verStable) // prerelease-s are locally ordered, so as soon as we reach verStable we are done
47
+ const v = ver(x)
48
+ if (v <= verStable) // prerelease-s are locally ordered, so as soon as we reach verStable we are done
49
return ret
43
- if (ver(x) !== currentVersion.getScalar())
44
- ret.push(x)
50
+ if (v === currentVersion.getScalar()) continue // skip current
51
+ x.isNewer = v > currentVersion.getScalar() // make easy to know what's newer
52
+ ret.push(x)
53
}
54
}
55
return ret