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:
@@ -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>
|
||||
Reference in New Issue
Block a user