29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
/**
|
|
* 与 /app/apkVersion/latest 对比:远程 version 与当前安装包是否不一致(用于侧栏红点等)
|
|
* @param {function(string): Promise<any>} httpGet 如 (url) => vm.$http.get(url)
|
|
* @returns {Promise<boolean>}
|
|
*/
|
|
import {
|
|
getCurrentAppVersionInfo,
|
|
normalizeVersionString,
|
|
extractLatestApkRecord
|
|
} from '@/common/utils/appVersion.js'
|
|
import { syncGlobalVersionToLocalStorage } from '@/common/config/appVersionConfig.js'
|
|
|
|
export async function isRemoteApkVersionDifferentFromInstalled(httpGet) {
|
|
if (typeof httpGet !== 'function') return false
|
|
syncGlobalVersionToLocalStorage()
|
|
const localVer = normalizeVersionString(getCurrentAppVersionInfo().versionName)
|
|
try {
|
|
const res = await httpGet('/app/apkVersion/latest')
|
|
if (!res || Number(res.code) !== 200) return false
|
|
const record = extractLatestApkRecord(res)
|
|
if (!record || !record.versionName) return false
|
|
const remoteVer = normalizeVersionString(record.versionName)
|
|
return remoteVer !== localVer
|
|
} catch (e) {
|
|
console.warn('[appUpdateVersionCheck]', e)
|
|
return false
|
|
}
|
|
}
|