feat(用户端): 低于 4.0.52 的桌面装机进强制升级遮罩——存量装机只有线上 Web 这一条覆盖通道
后端那个版本地板闸门只会把请求挡成 code 4012,客户端业务代码里没有任何 4012 分支:只拦、不推; 而桌面窗口直载 app-web(APP_URL = config.WEB_HOME_URL),做在页面上才吃得到已经装出去的机器。 判定落在 shared/client-force-update.ts(纯函数,17 例含"换地板结论就翻面"的反例):判不出来一律不拦 (浏览器形态、读不到本机版本、版本串解析不出数字、没有可下的包、线上包并不比本机新)。 遮罩挂 App.vue 根=登录页与首页一起覆盖,自动开始下载,失败只给"重试(断点续传)",不再等第二次确认。
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
<el-config-provider :locale="zhCn">
|
||||
<router-view />
|
||||
<ExpiryNotice />
|
||||
<ForceUpdateGate />
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
@@ -14,6 +15,7 @@
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
import { onBeforeUnmount } from 'vue'
|
||||
import ExpiryNotice from '@/shared/components/ExpiryNotice.vue'
|
||||
import ForceUpdateGate from '@/shared/components/ForceUpdateGate.vue'
|
||||
import { disposeGlobalErrorGuard } from '@/shared/utils/app-error'
|
||||
import { uninstallUserTokenSync } from '@/shared/auth/user-token-sync'
|
||||
import { disposeDownloadProgressListener } from '@/shared/utils/download-progress'
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 强制升级判定(纯函数,无 DOM、可 node --test 直跑)。
|
||||
*
|
||||
* 动机:桌面窗口的页面是线上 Web(app_client/main.py 的 APP_URL = config.WEB_HOME_URL),
|
||||
* 所以"要不要升、不升能不能继续用"这件事只有发一次 app-web 才能覆盖存量装机;
|
||||
* 服务端那个版本地板闸门(ClientVersionGuardFilter)只会把请求挡成 code 4012,
|
||||
* 而客户端业务代码里没有任何 4012 分支——它只拦、不推。这里补的就是"推"那一半。
|
||||
*
|
||||
* 判定刻意保守:**任何"判不出来"的情况一律不拦**(浏览器形态、读不到本机版本、
|
||||
* 版本串解析不出数字、没有可下载的更新包、最新包并不比本机新)。
|
||||
* 挡在门外是拿用户当天的任务换他们的下一次启动,误判一次的代价比漏判大。
|
||||
*/
|
||||
import { compareVersions, normVersion } from './utils/version-compare.ts'
|
||||
|
||||
/** 强升地板:低于这个版本的桌面装机必须更新后才能继续用。 */
|
||||
export const FORCE_UPDATE_TARGET = '4.0.52'
|
||||
|
||||
/** 不拦的理由。每个值都必须能在界面上被解释,不许拿空串当"没必要说"。 */
|
||||
export type ForceSkipReason =
|
||||
| 'not-desktop'
|
||||
| 'no-local-version'
|
||||
| 'unparsable-local-version'
|
||||
| 'invalid-target'
|
||||
| 'at-or-above-target'
|
||||
| 'no-newer-package'
|
||||
|
||||
export type ForceDecision =
|
||||
| { force: true; localVersion: string; targetVersion: string }
|
||||
| { force: false; reason: ForceSkipReason; localVersion: string; targetVersion: string }
|
||||
|
||||
/**
|
||||
* 点分数字版本:至少三段、每段都是非负整数。
|
||||
*
|
||||
* 需要它是因为 compareVersions 把解析不出的段当 0('4.0.52-beta' 会等于 '4.0.0'),
|
||||
* 于是"带后缀的版本"会被判成更旧而误锁人。地板只认能算干净的形状。
|
||||
*/
|
||||
export function isDottedNumericVersion(value: string): boolean {
|
||||
const parts = normVersion(value).split('.')
|
||||
if (parts.length < 3) return false
|
||||
return parts.every((part) => /^\d+$/.test(part))
|
||||
}
|
||||
|
||||
export function decideForceUpdate(input: {
|
||||
/** 有没有真实的桌面桥(能下载并自启更新程序);Web 降级桥不算。 */
|
||||
desktopBridge: boolean
|
||||
/** 本机 exe 版本(桥读不到就传空串)。 */
|
||||
localVersion: string
|
||||
/** 线上最新包版本(/api/version/latest 的 version)。 */
|
||||
latestVersion: string
|
||||
/** 最新包有没有可用下载地址。 */
|
||||
hasPackage: boolean
|
||||
targetVersion?: string
|
||||
}): ForceDecision {
|
||||
const target = normVersion(input.targetVersion ?? FORCE_UPDATE_TARGET)
|
||||
const local = normVersion(input.localVersion)
|
||||
const notForced = (reason: ForceSkipReason): ForceDecision => ({
|
||||
force: false,
|
||||
reason,
|
||||
localVersion: local,
|
||||
targetVersion: target,
|
||||
})
|
||||
|
||||
if (!input.desktopBridge) return notForced('not-desktop')
|
||||
if (!isDottedNumericVersion(target)) return notForced('invalid-target')
|
||||
if (!local) return notForced('no-local-version')
|
||||
if (!isDottedNumericVersion(local)) return notForced('unparsable-local-version')
|
||||
if (compareVersions(local, target) >= 0) return notForced('at-or-above-target')
|
||||
// 到了这一步才看包:没有地址、或线上包并不比本机新,那就拿不出"升上去更好"的东西,
|
||||
// 不能把人锁在门外(灰度回滚期 latest 低于地板是真实存在的状态)。
|
||||
if (!input.hasPackage) return notForced('no-newer-package')
|
||||
const latest = normVersion(input.latestVersion)
|
||||
if (!latest || compareVersions(latest, local) <= 0) return notForced('no-newer-package')
|
||||
return { force: true, localVersion: local, targetVersion: target }
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 强制升级遮罩:低于地板版本的桌面装机,不更新就不能继续用。
|
||||
*
|
||||
* 为什么做在页面而不是 exe 或后端闸门:桌面窗口直载线上 Web,存量装机下次打开就吃到这一版;
|
||||
* exe 里的代码改不动已经装出去的那些,后端地板闸门只会把请求挡成 code 4012(客户端不认这个码,
|
||||
* 只拦不推)。判定本身在 shared/client-force-update.ts(纯函数、可实跑),这里只管挂载时机与界面。
|
||||
*
|
||||
* 不打扰的情形(由判定决定,不在这里二次猜):浏览器形态、老 exe 读不到本机版本、
|
||||
* 没有可用更新包、本机已达标或线上包更旧。
|
||||
*/
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
import UpdateProgressBar from '@/shared/components/UpdateProgressBar.vue'
|
||||
import { decideForceUpdate, type ForceDecision } from '@/shared/client-force-update'
|
||||
import { getPywebviewApi, hasPywebview } from '@/shared/bridges/pywebview'
|
||||
import { useVersionUpdate } from '@/shared/composables/useVersionUpdate'
|
||||
|
||||
const { currentVersion, latestVersion, fileUrl, progress, runCheck, startUpdate } = useVersionUpdate()
|
||||
|
||||
const decision = ref<ForceDecision | null>(null)
|
||||
let evaluated = false
|
||||
|
||||
const blocked = computed(() => decision.value?.force === true)
|
||||
const failed = computed(() => progress.value?.status === 'failed')
|
||||
/** 下载/校验进行中不许再点(Python 侧有同一把锁,但界面不该让人白点一次)。 */
|
||||
const inFlight = computed(() => {
|
||||
const status = progress.value?.status
|
||||
return status === 'downloading' || status === 'verifying'
|
||||
})
|
||||
const readyToExit = computed(() => progress.value?.status === 'ready')
|
||||
const primaryText = computed(() => {
|
||||
if (inFlight.value) return '正在下载更新包…'
|
||||
if (readyToExit.value) return '更新包已就绪'
|
||||
return '立即更新'
|
||||
})
|
||||
|
||||
function start(): void {
|
||||
if (!fileUrl.value || inFlight.value || readyToExit.value) return
|
||||
void startUpdate(fileUrl.value)
|
||||
}
|
||||
|
||||
async function evaluate(): Promise<void> {
|
||||
if (evaluated) return
|
||||
evaluated = true
|
||||
await runCheck()
|
||||
decision.value = decideForceUpdate({
|
||||
// 只有"真桌面桥 + 会做更新"两个条件同时成立才拦人:降级桥点了也办不成事
|
||||
desktopBridge: hasPywebview() && Boolean(getPywebviewApi()?.do_update_app),
|
||||
localVersion: currentVersion.value,
|
||||
latestVersion: latestVersion.value,
|
||||
hasPackage: Boolean(fileUrl.value),
|
||||
})
|
||||
if (decision.value.force) start()
|
||||
}
|
||||
|
||||
// 桥注入可能晚于本组件挂载:没就绪就等 pywebviewready,就绪了才判一次(浏览器永远不判成强升)
|
||||
const readyHandler = () => {
|
||||
void evaluate()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (hasPywebview()) {
|
||||
void evaluate()
|
||||
return
|
||||
}
|
||||
window.addEventListener('pywebviewready', readyHandler, { once: true })
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('pywebviewready', readyHandler)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="blocked && decision" class="force-update-mask" role="dialog" aria-modal="true" aria-label="需要更新">
|
||||
<section class="force-update-card">
|
||||
<h2 class="force-update-title">需要更新后才能继续使用</h2>
|
||||
<p class="force-update-versions">
|
||||
当前版本 <b>v{{ decision.localVersion }}</b> 最低要求 <b>v{{ decision.targetVersion }}</b>
|
||||
</p>
|
||||
<p class="force-update-desc">
|
||||
这个版本已不能正常使用。更新已开始自动下载,下载完成后程序会在本机任务跑完时自动退出并安装。
|
||||
</p>
|
||||
|
||||
<UpdateProgressBar :progress="progress" />
|
||||
|
||||
<div class="force-update-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="force-update-primary"
|
||||
:disabled="inFlight || readyToExit"
|
||||
@click="start"
|
||||
>
|
||||
{{ primaryText }}
|
||||
</button>
|
||||
<button v-if="failed" type="button" class="force-update-ghost" @click="start">
|
||||
重试(从断点继续)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="failed" class="force-update-tip">
|
||||
下载没成功可以再点重试,网络中断后会从断点继续。反复失败请联系技术支持协助更新。
|
||||
</p>
|
||||
<p v-else-if="readyToExit" class="force-update-tip">
|
||||
更新包已就绪,等本机任务跑完就会自动退出并更新;也可以先保存手上的工作再重启。
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.force-update-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3200;
|
||||
background: rgba(20, 20, 20, 0.78);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.force-update-card {
|
||||
width: 460px;
|
||||
max-width: 100%;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
padding: 22px 24px 18px;
|
||||
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.32);
|
||||
}
|
||||
|
||||
.force-update-title {
|
||||
margin: 0 0 10px;
|
||||
font-size: 18px;
|
||||
color: #c0392b;
|
||||
}
|
||||
|
||||
.force-update-versions {
|
||||
margin: 0 0 8px;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.force-update-desc {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.force-update-actions {
|
||||
margin-top: 14px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.force-update-primary {
|
||||
padding: 8px 20px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
background: #28a745;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.force-update-primary:disabled {
|
||||
background: #9fc9ab;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.force-update-ghost {
|
||||
padding: 8px 14px;
|
||||
border: 1px solid #d0d0d0;
|
||||
border-radius: 5px;
|
||||
background: #fff;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.force-update-tip {
|
||||
margin: 12px 0 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
color: #8a6d3b;
|
||||
}
|
||||
</style>
|
||||
@@ -342,6 +342,7 @@ export function useVersionUpdate() {
|
||||
loadCurrentVersion,
|
||||
loadVersions,
|
||||
runCheck,
|
||||
startUpdate,
|
||||
doUpdate,
|
||||
doUpdateVersion,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user