feat: 版本更新优化非强制更新
This commit is contained in:
+19
-5
@@ -28,6 +28,18 @@ const waitForPromptDecision = (payload) => {
|
||||
})
|
||||
}
|
||||
|
||||
const toBoolean = (v) => {
|
||||
if (v === true) return true
|
||||
if (v === false || v === null || typeof v === 'undefined') return false
|
||||
if (typeof v === 'number') return v === 1
|
||||
if (typeof v === 'string') {
|
||||
const s = v.trim().toLowerCase()
|
||||
if (s === '1' || s === 'true') return true
|
||||
if (s === '0' || s === 'false' || s === '') return false
|
||||
}
|
||||
return !!v
|
||||
}
|
||||
|
||||
export const compareVersion = (a, b) => {
|
||||
const pa = String(a || '')
|
||||
.split('.')
|
||||
@@ -311,6 +323,7 @@ export const createHotUpdate = ({
|
||||
uni.showToast({ title: '已经是最新版本', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const isForceUpdate = toBoolean(info?.isForceUpdate)
|
||||
const promptKey = String(info.type || '') + ':' + String(latest || '')
|
||||
const desc = getUpdateDesc(info)
|
||||
const content = desc
|
||||
@@ -320,7 +333,7 @@ export const createHotUpdate = ({
|
||||
: '发现新的版本,请立即更新到最新版本'
|
||||
const title = latest ? `发现新版本 v${latest}` : '提示'
|
||||
const confirmText = '立即升级'
|
||||
const cancelText = info.isForceUpdate ? '关闭' : '取消'
|
||||
const cancelText = isForceUpdate ? '关闭' : '取消'
|
||||
|
||||
const doUpdate = () => {
|
||||
const wgtUrl = String(info.filePath || '')
|
||||
@@ -337,7 +350,7 @@ export const createHotUpdate = ({
|
||||
emitUniEvent(HOT_UPDATE_PROMPT_CLOSE_EVENT, {})
|
||||
}
|
||||
|
||||
if (info.isForceUpdate) {
|
||||
if (isForceUpdate) {
|
||||
if (source !== 'manual' && state.lastAutoUpdateAttemptKey === promptKey) return
|
||||
state.lastAutoUpdateAttemptKey = promptKey
|
||||
try {
|
||||
@@ -353,7 +366,7 @@ export const createHotUpdate = ({
|
||||
title,
|
||||
content,
|
||||
version: latest,
|
||||
isForceUpdate: !!info.isForceUpdate,
|
||||
isForceUpdate,
|
||||
confirmText,
|
||||
cancelText,
|
||||
})
|
||||
@@ -393,6 +406,7 @@ export const createHotUpdate = ({
|
||||
const { updateInfo, localCompareVersion, latestVersion } = payload
|
||||
if (!hasNewVersion(updateInfo, localCompareVersion)) return
|
||||
|
||||
const isForceUpdate = toBoolean(updateInfo?.isForceUpdate)
|
||||
const promptKey = String(updateInfo.type || '') + ':' + String(latestVersion || '')
|
||||
try {
|
||||
if (latestKeyStorageKey) uni.setStorageSync(latestKeyStorageKey, promptKey)
|
||||
@@ -400,13 +414,13 @@ export const createHotUpdate = ({
|
||||
const storedPrompt = String(uni.getStorageSync(storageKey) || '')
|
||||
const shouldSkipPrompt =
|
||||
allowSkipPrompt &&
|
||||
!updateInfo.isForceUpdate &&
|
||||
!isForceUpdate &&
|
||||
(state.lastPromptKey === promptKey || storedPrompt === promptKey)
|
||||
if (shouldSkipPrompt) return
|
||||
state.lastPromptKey = promptKey
|
||||
uni.setStorageSync(storageKey, promptKey)
|
||||
|
||||
if (updateInfo.type == 'min' && updateInfo.isForceUpdate) {
|
||||
if (updateInfo.type == 'min' && isForceUpdate) {
|
||||
if (state.lastAutoUpdateAttemptKey === promptKey) return
|
||||
state.lastAutoUpdateAttemptKey = promptKey
|
||||
const wgtUrl = String(updateInfo.filePath || '')
|
||||
|
||||
Reference in New Issue
Block a user