更新新版本获取地址
This commit is contained in:
@@ -32,8 +32,9 @@ material-modal(:show="versionInfo.showModal" max-width="60%" @close="handleClose
|
||||
p 若一样则不必理会该弹窗,直接关闭即可,否则请手动下载新版本更新。
|
||||
div(:class="$style.footer")
|
||||
div(:class="$style.btns")
|
||||
base-btn(v-if="versionInfo.status == 'error'" :class="$style.btn" @click="handleCheckUpdate") 重新检查更新
|
||||
base-btn(v-else :class="$style.btn" disabled) 检查更新中...
|
||||
base-btn(v-if="versionInfo.status == 'error'" :class="$style.btn2" @click="handleCheckUpdate") 重新检查更新
|
||||
base-btn(v-else :class="$style.btn2" disabled) 检查更新中...
|
||||
base-btn(:disabled="disabledIgnoreFailBtn" :class="$style.btn2" @click="handleIgnoreFailTipClick") 一个星期内不再提醒
|
||||
main(v-else-if="versionInfo.status == 'downloaded'" :class="$style.main")
|
||||
h2 🚀程序更新🚀
|
||||
|
||||
@@ -109,6 +110,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
ignoreVersion: null,
|
||||
disabledIgnoreFailBtn: true,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -137,6 +139,7 @@ export default {
|
||||
void getIgnoreVersion().then(version => {
|
||||
this.ignoreVersion = version
|
||||
})
|
||||
this.disabledIgnoreFailBtn = Date.now() - parseInt(localStorage.getItem('update__check_failed_tip') ?? '0') < 7 * 86400000
|
||||
},
|
||||
methods: {
|
||||
handleClose() {
|
||||
@@ -189,6 +192,10 @@ export default {
|
||||
versionInfo.reCheck = true
|
||||
checkUpdate()
|
||||
},
|
||||
handleIgnoreFailTipClick() {
|
||||
localStorage.setItem('update__check_failed_tip', Date.now().toString())
|
||||
this.disabledIgnoreFailBtn = true
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -69,7 +69,7 @@ export default () => {
|
||||
const handleGetVersionInfo = async(): Promise<NonNullable<typeof versionInfo['newVersion']>> => {
|
||||
return (versionInfo.newVersion?.history && !versionInfo.reCheck
|
||||
? Promise.resolve(versionInfo.newVersion)
|
||||
: getVersionInfo().then(body => {
|
||||
: getVersionInfo().then((body: any) => {
|
||||
versionInfo.newVersion = body
|
||||
return body
|
||||
})
|
||||
@@ -102,7 +102,10 @@ export default () => {
|
||||
if (result.version == '0.0.0') {
|
||||
versionInfo.isUnknown = true
|
||||
versionInfo.status = 'error'
|
||||
versionInfo.showModal = true
|
||||
let ignoreFailTipTime = parseInt(localStorage.getItem('update__check_failed_tip') ?? '0')
|
||||
if (Date.now() - ignoreFailTipTime > 7 * 86400000) {
|
||||
versionInfo.showModal = true
|
||||
}
|
||||
return
|
||||
}
|
||||
versionInfo.isUnknown = false
|
||||
|
||||
@@ -1,50 +1,71 @@
|
||||
import { httpGet } from './request'
|
||||
import { name, author } from '../../../package.json'
|
||||
import pkg from '../../../package.json'
|
||||
|
||||
// TODO add Notice
|
||||
|
||||
export const getVersionInfo = async(retryNum = 0) => {
|
||||
const author = pkg.author.name
|
||||
const name = pkg.name
|
||||
|
||||
const address = [
|
||||
[`https://raw.githubusercontent.com/${author}/${name}/master/publish/version.json`, 'direct'],
|
||||
['https://registry.npmjs.org/lx-music-desktop-version-info/latest', 'npm'],
|
||||
['https://registry.npmmirror.com/lx-music-desktop-version-info/latest', 'npm'],
|
||||
[`https://cdn.jsdelivr.net/gh/${author}/${name}/publish/version.json`, 'direct'],
|
||||
[`https://fastly.jsdelivr.net/gh/${author}/${name}/publish/version.json`, 'direct'],
|
||||
[`https://gcore.jsdelivr.net/gh/${author}/${name}/publish/version.json`, 'direct'],
|
||||
['https://gitee.com/lyswhut/lx-music-desktop-versions/raw/master/version.json', 'direct'],
|
||||
['http://cdn.stsky.cn/lx-music/desktop/version.json', 'direct'],
|
||||
]
|
||||
|
||||
const request = async(url, retryNum = 0) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
httpGet(`https://raw.githubusercontent.com/${author.name}/${name}/master/publish/version.json`, {
|
||||
timeout: 20000,
|
||||
httpGet(url, {
|
||||
timeout: 10000,
|
||||
}, (err, resp, body) => {
|
||||
if (err) {
|
||||
return ++retryNum > 3
|
||||
? getVersionInfo2().then(resolve).catch(reject)
|
||||
: getVersionInfo(retryNum).then(resolve).catch(reject)
|
||||
}
|
||||
resolve(body)
|
||||
if (err || resp.statusCode != 200) {
|
||||
++retryNum >= 3
|
||||
? reject(err || new Error(resp.statusMessage || resp.statusCode))
|
||||
: request(url, retryNum).then(resolve).catch(reject)
|
||||
} else resolve(body)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const getVersionInfo2 = async(retryNum = 0) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
httpGet('https://gitee.com/lyswhut/lx-music-desktop-versions/raw/master/version.json', {
|
||||
timeout: 20000,
|
||||
}, (err, resp, body) => {
|
||||
if (!err && !body.version) err = new Error(JSON.stringify(body))
|
||||
if (err) {
|
||||
return ++retryNum > 3
|
||||
? getVersionInfo3().then(resolve).catch(reject)
|
||||
: getVersionInfo2(retryNum).then(resolve).catch(reject)
|
||||
}
|
||||
resolve(body)
|
||||
})
|
||||
const getDirectInfo = async(url) => {
|
||||
return request(url).then(info => {
|
||||
if (info.version == null) throw new Error('failed')
|
||||
return info
|
||||
})
|
||||
}
|
||||
|
||||
const getVersionInfo3 = async(retryNum = 0) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
httpGet('https://cdn.stsky.cn/lx-music/desktop/version.json', {
|
||||
timeout: 20000,
|
||||
}, (err, resp, body) => {
|
||||
if (err) {
|
||||
return ++retryNum > 3
|
||||
? reject(err)
|
||||
: getVersionInfo3(retryNum).then(resolve).catch(reject)
|
||||
}
|
||||
resolve(body)
|
||||
})
|
||||
const getNpmPkgInfo = async(url) => {
|
||||
return request(url).then(json => {
|
||||
if (!json.versionInfo) throw new Error('failed')
|
||||
const info = JSON.parse(json.versionInfo)
|
||||
if (info.version == null) throw new Error('failed')
|
||||
return info
|
||||
})
|
||||
}
|
||||
|
||||
export const getVersionInfo = async(index = 0) => {
|
||||
const [url, source] = address[index]
|
||||
let promise
|
||||
switch (source) {
|
||||
case 'direct':
|
||||
promise = getDirectInfo(url)
|
||||
break
|
||||
case 'npm':
|
||||
promise = getNpmPkgInfo(url)
|
||||
break
|
||||
}
|
||||
|
||||
return promise.catch(async(err) => {
|
||||
index++
|
||||
if (index >= address.length) throw err
|
||||
return getVersionInfo(index)
|
||||
})
|
||||
}
|
||||
|
||||
// getVersionInfo().then(info => {
|
||||
// console.log(info)
|
||||
// })
|
||||
|
||||
@@ -7,7 +7,7 @@ dd
|
||||
base-checkbox(id="setting__update_showChangeLog" :model-value="appSetting['common.showChangeLog']" :label="$t('setting__update_show_change_log')" @update:model-value="updateSetting({'common.showChangeLog': $event})")
|
||||
.gap-top
|
||||
.p.small
|
||||
| {{ $t('setting__update_latest_label') }}{{ versionInfo.newVersion ? versionInfo.newVersion.version : $t('setting__update_unknown') }}
|
||||
| {{ $t('setting__update_latest_label') }}{{ versionInfo.newVersion && versionInfo.newVersion.version != '0.0.0' ? versionInfo.newVersion.version : $t('setting__update_unknown') }}
|
||||
.p.small(@click="handleOpenDevTools") {{ $t('setting__update_current_label') }}{{ versionInfo.version }}
|
||||
.p.small(v-if="downloadProgress" style="line-height: 1.5;")
|
||||
| {{ $t('setting__update_downloading') }}
|
||||
@@ -16,6 +16,8 @@ dd
|
||||
template(v-if="versionInfo.newVersion")
|
||||
.p(v-if="versionInfo.isLatest")
|
||||
span {{ $t('setting__update_latest') }}
|
||||
.p(v-else-if="versionInfo.isUnknown")
|
||||
span {{ $t('setting__update_unknown_tip') }}
|
||||
.p(v-else-if="versionInfo.status != 'downloading'")
|
||||
span {{ $t('setting__update_new_version') }}
|
||||
.p
|
||||
|
||||
Reference in New Issue
Block a user