更新新版本获取地址
parent
903ca18b75
commit
358142c1cc
|
@ -0,0 +1,16 @@
|
|||
name: Publish NPM Version Info
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
dispatch:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v2
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
repository: lyswhut/lx-music-desktop-version-info
|
||||
event-type: npm-release
|
|
@ -546,6 +546,7 @@
|
|||
"setting__update_show_change_log": "Show changelog on first boot after version update",
|
||||
"setting__update_try_auto_update": "Attempt to download updates automatically when a new version is found",
|
||||
"setting__update_unknown": "Unknown",
|
||||
"setting__update_unknown_tip": "❓ Failed to obtain the latest version information, it is recommended to go to the About interface to open the project release address to check whether the current version is the latest",
|
||||
"setting_sync_status_enabled": "connected",
|
||||
"song_list": "Playlists",
|
||||
"songlist__import_input_btn_confirm": "Open",
|
||||
|
|
|
@ -545,6 +545,7 @@
|
|||
"setting__update_show_change_log": "更新版本后的首次启动时显示更新日志",
|
||||
"setting__update_try_auto_update": "发现新版本时尝试自动下载更新",
|
||||
"setting__update_unknown": "未知",
|
||||
"setting__update_unknown_tip": "❓ 获取最新版本信息失败,建议去关于界面打开项目发布地址查看当前版本是否最新",
|
||||
"setting_sync_status_enabled": "已连接",
|
||||
"song_list": "歌单",
|
||||
"songlist__import_input_btn_confirm": "打开",
|
||||
|
|
|
@ -546,6 +546,7 @@
|
|||
"setting__update_show_change_log": "更新版本後的首次啟動時顯示更新日誌",
|
||||
"setting__update_try_auto_update": "發現新版本時嘗試自動下載更新",
|
||||
"setting__update_unknown": "未知",
|
||||
"setting__update_unknown_tip": "❓ 獲取最新版本信息失敗,建議去關於界面打開項目發布地址查看當前版本是否最新",
|
||||
"setting_sync_status_enabled": "已連接",
|
||||
"song_list": "歌單",
|
||||
"songlist__import_input_show_btn": "打開歌單",
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue