更新新版本获取地址

pull/1583/head
lyswhut 2023-08-30 13:01:27 +08:00
parent 903ca18b75
commit 358142c1cc
8 changed files with 92 additions and 40 deletions

View File

@ -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

View File

@ -546,6 +546,7 @@
"setting__update_show_change_log": "Show changelog on first boot after version update", "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_try_auto_update": "Attempt to download updates automatically when a new version is found",
"setting__update_unknown": "Unknown", "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", "setting_sync_status_enabled": "connected",
"song_list": "Playlists", "song_list": "Playlists",
"songlist__import_input_btn_confirm": "Open", "songlist__import_input_btn_confirm": "Open",

View File

@ -545,6 +545,7 @@
"setting__update_show_change_log": "更新版本后的首次启动时显示更新日志", "setting__update_show_change_log": "更新版本后的首次启动时显示更新日志",
"setting__update_try_auto_update": "发现新版本时尝试自动下载更新", "setting__update_try_auto_update": "发现新版本时尝试自动下载更新",
"setting__update_unknown": "未知", "setting__update_unknown": "未知",
"setting__update_unknown_tip": "❓ 获取最新版本信息失败,建议去关于界面打开项目发布地址查看当前版本是否最新",
"setting_sync_status_enabled": "已连接", "setting_sync_status_enabled": "已连接",
"song_list": "歌单", "song_list": "歌单",
"songlist__import_input_btn_confirm": "打开", "songlist__import_input_btn_confirm": "打开",

View File

@ -546,6 +546,7 @@
"setting__update_show_change_log": "更新版本後的首次啟動時顯示更新日誌", "setting__update_show_change_log": "更新版本後的首次啟動時顯示更新日誌",
"setting__update_try_auto_update": "發現新版本時嘗試自動下載更新", "setting__update_try_auto_update": "發現新版本時嘗試自動下載更新",
"setting__update_unknown": "未知", "setting__update_unknown": "未知",
"setting__update_unknown_tip": "❓ 獲取最新版本信息失敗,建議去關於界面打開項目發布地址查看當前版本是否最新",
"setting_sync_status_enabled": "已連接", "setting_sync_status_enabled": "已連接",
"song_list": "歌單", "song_list": "歌單",
"songlist__import_input_show_btn": "打開歌單", "songlist__import_input_show_btn": "打開歌單",

View File

@ -32,8 +32,9 @@ material-modal(:show="versionInfo.showModal" max-width="60%" @close="handleClose
p 若一样则不必理会该弹窗直接关闭即可否则请手动下载新版本更新 p 若一样则不必理会该弹窗直接关闭即可否则请手动下载新版本更新
div(:class="$style.footer") div(:class="$style.footer")
div(:class="$style.btns") div(:class="$style.btns")
base-btn(v-if="versionInfo.status == 'error'" :class="$style.btn" @click="handleCheckUpdate") 重新检查更新 base-btn(v-if="versionInfo.status == 'error'" :class="$style.btn2" @click="handleCheckUpdate") 重新检查更新
base-btn(v-else :class="$style.btn" disabled) 检查更新中... 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") main(v-else-if="versionInfo.status == 'downloaded'" :class="$style.main")
h2 🚀程序更新🚀 h2 🚀程序更新🚀
@ -109,6 +110,7 @@ export default {
data() { data() {
return { return {
ignoreVersion: null, ignoreVersion: null,
disabledIgnoreFailBtn: true,
} }
}, },
computed: { computed: {
@ -137,6 +139,7 @@ export default {
void getIgnoreVersion().then(version => { void getIgnoreVersion().then(version => {
this.ignoreVersion = version this.ignoreVersion = version
}) })
this.disabledIgnoreFailBtn = Date.now() - parseInt(localStorage.getItem('update__check_failed_tip') ?? '0') < 7 * 86400000
}, },
methods: { methods: {
handleClose() { handleClose() {
@ -189,6 +192,10 @@ export default {
versionInfo.reCheck = true versionInfo.reCheck = true
checkUpdate() checkUpdate()
}, },
handleIgnoreFailTipClick() {
localStorage.setItem('update__check_failed_tip', Date.now().toString())
this.disabledIgnoreFailBtn = true
},
}, },
} }
</script> </script>

View File

@ -69,7 +69,7 @@ export default () => {
const handleGetVersionInfo = async(): Promise<NonNullable<typeof versionInfo['newVersion']>> => { const handleGetVersionInfo = async(): Promise<NonNullable<typeof versionInfo['newVersion']>> => {
return (versionInfo.newVersion?.history && !versionInfo.reCheck return (versionInfo.newVersion?.history && !versionInfo.reCheck
? Promise.resolve(versionInfo.newVersion) ? Promise.resolve(versionInfo.newVersion)
: getVersionInfo().then(body => { : getVersionInfo().then((body: any) => {
versionInfo.newVersion = body versionInfo.newVersion = body
return body return body
}) })
@ -102,7 +102,10 @@ export default () => {
if (result.version == '0.0.0') { if (result.version == '0.0.0') {
versionInfo.isUnknown = true versionInfo.isUnknown = true
versionInfo.status = 'error' 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 return
} }
versionInfo.isUnknown = false versionInfo.isUnknown = false

View File

@ -1,50 +1,71 @@
import { httpGet } from './request' import { httpGet } from './request'
import { name, author } from '../../../package.json' import pkg from '../../../package.json'
// TODO add Notice // 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) => { return await new Promise((resolve, reject) => {
httpGet(`https://raw.githubusercontent.com/${author.name}/${name}/master/publish/version.json`, { httpGet(url, {
timeout: 20000, timeout: 10000,
}, (err, resp, body) => { }, (err, resp, body) => {
if (err) { if (err || resp.statusCode != 200) {
return ++retryNum > 3 ++retryNum >= 3
? getVersionInfo2().then(resolve).catch(reject) ? reject(err || new Error(resp.statusMessage || resp.statusCode))
: getVersionInfo(retryNum).then(resolve).catch(reject) : request(url, retryNum).then(resolve).catch(reject)
} } else resolve(body)
resolve(body)
}) })
}) })
} }
const getVersionInfo2 = async(retryNum = 0) => { const getDirectInfo = async(url) => {
return await new Promise((resolve, reject) => { return request(url).then(info => {
httpGet('https://gitee.com/lyswhut/lx-music-desktop-versions/raw/master/version.json', { if (info.version == null) throw new Error('failed')
timeout: 20000, return info
}, (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 getVersionInfo3 = async(retryNum = 0) => { const getNpmPkgInfo = async(url) => {
return await new Promise((resolve, reject) => { return request(url).then(json => {
httpGet('https://cdn.stsky.cn/lx-music/desktop/version.json', { if (!json.versionInfo) throw new Error('failed')
timeout: 20000, const info = JSON.parse(json.versionInfo)
}, (err, resp, body) => { if (info.version == null) throw new Error('failed')
if (err) { return info
return ++retryNum > 3
? reject(err)
: getVersionInfo3(retryNum).then(resolve).catch(reject)
}
resolve(body)
})
}) })
} }
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)
// })

View File

@ -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})") 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 .gap-top
.p.small .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(@click="handleOpenDevTools") {{ $t('setting__update_current_label') }}{{ versionInfo.version }}
.p.small(v-if="downloadProgress" style="line-height: 1.5;") .p.small(v-if="downloadProgress" style="line-height: 1.5;")
| {{ $t('setting__update_downloading') }} | {{ $t('setting__update_downloading') }}
@ -16,6 +16,8 @@ dd
template(v-if="versionInfo.newVersion") template(v-if="versionInfo.newVersion")
.p(v-if="versionInfo.isLatest") .p(v-if="versionInfo.isLatest")
span {{ $t('setting__update_latest') }} span {{ $t('setting__update_latest') }}
.p(v-else-if="versionInfo.isUnknown")
span {{ $t('setting__update_unknown_tip') }}
.p(v-else-if="versionInfo.status != 'downloading'") .p(v-else-if="versionInfo.status != 'downloading'")
span {{ $t('setting__update_new_version') }} span {{ $t('setting__update_new_version') }}
.p .p